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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
359 | A | Table | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are... | The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50).
Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* e... | Print a single number — the minimum number of operations Simon needs to carry out his idea. | [
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n"
] | [
"4\n",
"2\n"
] | In the first sample, the sequence of operations can be like this:
- For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to c... | 500 | [
{
"input": "3 3\n0 0 0\n0 1 0\n0 0 0",
"output": "4"
},
{
"input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0",
"output": "2"
},
{
"input": "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0... | 1,568,367,784 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 140 | 1,228,800 | class CodeforcesTask359ASolution:
def __init__(self):
self.result = ''
self.n_m = []
self.board = []
def read_input(self):
self.n_m = [int(x) for x in input().split(" ")]
for x in range(self.n_m[0]):
self.board.append([int(y) for y in input().split(" ")])
... | Title: Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on t... | ```python
class CodeforcesTask359ASolution:
def __init__(self):
self.result = ''
self.n_m = []
self.board = []
def read_input(self):
self.n_m = [int(x) for x in input().split(" ")]
for x in range(self.n_m[0]):
self.board.append([int(y) for y in input().split(... | 3 | |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh... | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"... | 1,503,594,346 | 1,846 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 | from math import factorial
def count(n, k):
return factorial(n) // (factorial(k) * factorial(n - k))
n, m = map(int, input().split())
table = []
for i in range(n):
table.append(list(map(int, input().split())))
ans = 0
for i in range(n):
c0 = table[i].count(0)
c1 = table[i].count(1)
fo... | Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or ... | ```python
from math import factorial
def count(n, k):
return factorial(n) // (factorial(k) * factorial(n - k))
n, m = map(int, input().split())
table = []
for i in range(n):
table.append(list(map(int, input().split())))
ans = 0
for i in range(n):
c0 = table[i].count(0)
c1 = table[i].count(... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,569,668,692 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s=input()
z="hello"
i=0
for a in s:
if(i>=len(z)):
break
if(a==z[i])
i+=1
if(i==5):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
z="hello"
i=0
for a in s:
if(i>=len(z)):
break
if(a==z[i])
i+=1
if(i==5):
print("YES")
else:
print("NO")
``` | -1 |
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\n1 1 ... | 1,526,418,161 | 2,147,483,647 | Python 3 | OK | TESTS | 140 | 155 | 16,179,200 |
n = int(input())
A = [int(x) for x in input().split()]
m = min(A)
A = [i for i, x in enumerate(A) if x == m]
print(min([A[i + 1] - A[i] for i in range(len(A) - 1)]))
| Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
I... | ```python
n = int(input())
A = [int(x) for x in input().split()]
m = min(A)
A = [i for i, x in enumerate(A) if x == m]
print(min([A[i + 1] - A[i] for i in range(len(A) - 1)]))
``` | 3 | |
143 | B | Help Kingdom of Far Far Away 2 | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operatio... | The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is:
- The number's notation only contains characters from the set {"0" – "9... | Print the number given in the input in the financial format by the rules described in the problem statement. | [
"2012\n",
"0.000\n",
"-0.00987654321\n",
"-12345678.9\n"
] | [
"$2,012.00",
"$0.00",
"($0.00)",
"($12,345,678.90)"
] | Pay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the financi... | 1,000 | [
{
"input": "2012",
"output": "$2,012.00"
},
{
"input": "0.000",
"output": "$0.00"
},
{
"input": "-0.00987654321",
"output": "($0.00)"
},
{
"input": "-12345678.9",
"output": "($12,345,678.90)"
},
{
"input": "0.99999999999999999999",
"output": "$0.99"
},
{
... | 1,646,730,929 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 512,000 | n=input()
w=n.split('.')
if(float(n)<0):
x=w[0].replace('-','')
else:
x=w[0]
if(int(float(n))==float(n)):
l=len(x)
r=l%3
v=l//3
s=''
if(v>0):
if(r!=0):
s+=x[:r]+','
y=r+3
for i in range(v-1):
s+=x[r:y]+','
... | Title: Help Kingdom of Far Far Away 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more e... | ```python
n=input()
w=n.split('.')
if(float(n)<0):
x=w[0].replace('-','')
else:
x=w[0]
if(int(float(n))==float(n)):
l=len(x)
r=l%3
v=l//3
s=''
if(v>0):
if(r!=0):
s+=x[:r]+','
y=r+3
for i in range(v-1):
s+=x[r:y]+','... | 0 | |
1,009 | C | Annoying Present | PROGRAMMING | 1,700 | [
"greedy",
"math"
] | null | null | Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some int... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change. | Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$. | [
"2 3\n-1 3\n0 0\n-1 -4\n",
"3 2\n0 2\n5 0\n"
] | [
"-2.500000000000000\n",
"7.000000000000000\n"
] | none | 0 | [
{
"input": "2 3\n-1 3\n0 0\n-1 -4",
"output": "-2.500000000000000"
},
{
"input": "3 2\n0 2\n5 0",
"output": "7.000000000000000"
},
{
"input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64",
"output": "-16.500000000000000"
},
{
"input": "1 1\n0 0",
... | 1,543,376,221 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 452 | 716,800 | #!/usr/bin/env python
import zlib, base64
exec(zlib.decompress(base64.b64decode('eJx1jEsOgzAMBfc5hatunA8NdIngMFSB1lJjLBMqevtG7Lt60hvNXC9x3zQ+iOPMH5Bvea1sOOQxT4LEJRDLXtDeNnlTXWs0yNgGZN/ZGO9mWRUIiEEnfs6YbW/gCOm/D+pHdofH5NghN509O0ALpKHtK0319uJQmpMa0RpCjWzND8GsM7A=')))
# Created by pyminifier (https://github.com/liftoff/py... | Title: Annoying Present
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some c... | ```python
#!/usr/bin/env python
import zlib, base64
exec(zlib.decompress(base64.b64decode('eJx1jEsOgzAMBfc5hatunA8NdIngMFSB1lJjLBMqevtG7Lt60hvNXC9x3zQ+iOPMH5Bvea1sOOQxT4LEJRDLXtDeNnlTXWs0yNgGZN/ZGO9mWRUIiEEnfs6YbW/gCOm/D+pHdofH5NghN509O0ALpKHtK0319uJQmpMa0RpCjWzND8GsM7A=')))
# Created by pyminifier (https://github.com/... | 3 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,696,694,858 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 |
n = int(input())
v = list(map(int, input().split()))
pref1 = [0] * n
pref1[0] = v[0]
for k in range(1, n):
pref1[k] = pref1[k - 1] + v[k]
u = v.sort()
pref2 = [0] * n
pref2[0] = v[0]
for k in range(1, n):
pref2[k] = pref2[k - 1] + u[k]
m = int(input())
for _ in range(m):
type, l, r ... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n = int(input())
v = list(map(int, input().split()))
pref1 = [0] * n
pref1[0] = v[0]
for k in range(1, n):
pref1[k] = pref1[k - 1] + v[k]
u = v.sort()
pref2 = [0] * n
pref2[0] = v[0]
for k in range(1, n):
pref2[k] = pref2[k - 1] + u[k]
m = int(input())
for _ in range(m):
t... | -1 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,694,598,341 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | s = list(map(int, input().split(" ")))
d = []
dep = 0
for i in s:
if i in d:
dep+=1
else:
d.append(i)
print(dep) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
s = list(map(int, input().split(" ")))
d = []
dep = 0
for i in s:
if i in d:
dep+=1
else:
d.append(i)
print(dep)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,659,590,962 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 93 | 0 | s=input()
charlist="hello"
x=1
while x==1:
a=s.find(charlist[0])
if a==-1:
x=0
else:
charlist=charlist[1:]
s=s[a+1:]
if charlist=="":
break
if x==1:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
charlist="hello"
x=1
while x==1:
a=s.find(charlist[0])
if a==-1:
x=0
else:
charlist=charlist[1:]
s=s[a+1:]
if charlist=="":
break
if x==1:
print("YES")
else:
print("NO")
``` | 3.9535 |
779 | C | Dishonest Sellers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week... | In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during d... | Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. | [
"3 1\n5 4 6\n3 1 5\n",
"5 3\n3 4 7 10 3\n4 5 5 12 5\n"
] | [
"10\n",
"25\n"
] | In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ... | 1,000 | [
{
"input": "3 1\n5 4 6\n3 1 5",
"output": "10"
},
{
"input": "5 3\n3 4 7 10 3\n4 5 5 12 5",
"output": "25"
},
{
"input": "1 0\n9\n8",
"output": "8"
},
{
"input": "2 0\n4 10\n1 2",
"output": "3"
},
{
"input": "4 2\n19 5 17 13\n3 18 8 10",
"output": "29"
},
... | 1,561,298,686 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 624 | 33,382,400 | import operator
import operator
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
increaseInPrice = dict()
for i in range(n):
increaseInPrice[i] = b[i]-a[i]
sortedIncrease = sorted(increaseInPrice.items(), key=operator.itemgetter(1))
i = n-1
totalCost = 0
whi... | Title: Dishonest Sellers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be... | ```python
import operator
import operator
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
increaseInPrice = dict()
for i in range(n):
increaseInPrice[i] = b[i]-a[i]
sortedIncrease = sorted(increaseInPrice.items(), key=operator.itemgetter(1))
i = n-1
totalCos... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,693,128,204 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | m,n,a=map(int,input().split())
if m%a==0:
va1=m//a
else:
va1=m//a+1
if n%a==0:
va2=n//a
else:
va2=n//a+1
print(va1*va2)
#24
| 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
m,n,a=map(int,input().split())
if m%a==0:
va1=m//a
else:
va1=m//a+1
if n%a==0:
va2=n//a
else:
va2=n//a+1
print(va1*va2)
#24
``` | 3.977 |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,668,506,298 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | t=int(input())
i=[int(a) for a in input().split()][:t]
print(i.index(max(i))+1,sorted(i)[2]) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
t=int(input())
i=[int(a) for a in input().split()][:t]
print(i.index(max(i))+1,sorted(i)[2])
``` | -1 | |
980 | B | Marlin | PROGRAMMING | 1,600 | [
"constructive algorithms"
] | null | null | The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bottom-right cell $(4, n)$. The second village is located at $(4, 1)$ and its people love the ... | The first line of input contain two integers, $n$ and $k$ ($3 \leq n \leq 99$, $0 \leq k \leq 2\times(n-2)$), $n$ is odd, the width of the city, and the number of hotels to be placed, respectively. | Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra $4$ lines that describe the city, each line should have $n$ characters, each of which is "#" if that cell has a hotel on it, or "." if not. | [
"7 2\n",
"5 3\n"
] | [
"YES\n.......\n.#.....\n.#.....\n.......\n",
"YES\n.....\n.###.\n.....\n.....\n"
] | none | 1,000 | [
{
"input": "7 2",
"output": "YES\n.......\n.#.....\n.#.....\n......."
},
{
"input": "5 3",
"output": "YES\n.....\n.###.\n.....\n....."
},
{
"input": "3 2",
"output": "YES\n...\n.#.\n.#.\n..."
},
{
"input": "3 0",
"output": "YES\n...\n...\n...\n..."
},
{
"input": "... | 1,525,793,242 | 1,342 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 61 | 7,065,600 | n,k = [int(s) for s in input().split()]
def line(h=0):
if h < 0: h = 0
if h > n-2: h = n-2
return '.' + '#'*h + '.'*(n-h-1)
if k > 2*(n-2):
print("NO")
else:
print("YES")
print(line())
print(line(k))
k -= n-2
print(line(k))
print(line()) | Title: Marlin
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bo... | ```python
n,k = [int(s) for s in input().split()]
def line(h=0):
if h < 0: h = 0
if h > n-2: h = n-2
return '.' + '#'*h + '.'*(n-h-1)
if k > 2*(n-2):
print("NO")
else:
print("YES")
print(line())
print(line(k))
k -= n-2
print(line(k))
print(line())
``` | 0 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,694,014,892 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | I=input;a,b,c=I(),I(),I()
print max(a+b+c,(a+b)*c,a*(b+c),a*b*c)
| Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
I=input;a,b,c=I(),I(),I()
print max(a+b+c,(a+b)*c,a*(b+c),a*b*c)
``` | -1 | |
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,626,839,905 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 108 | 22,118,400 | n = int(input())
check = 0
plane = list(map(int, input().split(" ")))
plane = [plane[i]-1 for i in range(0, n)]
for i in range(0, n):
if plane[plane[plane[i]]] == i:
check = 1
else:
print("YES" if check else "NO") | 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
n = int(input())
check = 0
plane = list(map(int, input().split(" ")))
plane = [plane[i]-1 for i in range(0, n)]
for i in range(0, n):
if plane[plane[plane[i]]] == i:
check = 1
else:
print("YES" if check else "NO")
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,565,540,081 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | # Совсем недавно Вася научился печатать на клавиатуре и выходить в интернет.
# Он сразу же зашел в чат и решил поздороваться со всеми. Вася напечатал слово s.
# Считается, что у Васи получилось поздороваться, если из напечатанного слова можно
# удалить некоторые буквы так, чтобы получилось слово "hello". Например, е... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
# Совсем недавно Вася научился печатать на клавиатуре и выходить в интернет.
# Он сразу же зашел в чат и решил поздороваться со всеми. Вася напечатал слово s.
# Считается, что у Васи получилось поздороваться, если из напечатанного слова можно
# удалить некоторые буквы так, чтобы получилось слово "hello". Н... | 0 |
45 | E | Director | PROGRAMMING | 2,000 | [
"constructive algorithms",
"greedy"
] | E. Director | 2 | 256 | Vasya is a born Berland film director, he is currently working on a new blockbuster, "The Unexpected". Vasya knows from his own experience how important it is to choose the main characters' names and surnames wisely. He made up a list of *n* names and *n* surnames that he wants to use. Vasya haven't decided yet how to ... | The first input line contains number *n* (1<=≤<=*n*<=≤<=100) — the number of names and surnames. Then follow *n* lines — the list of names. Then follow *n* lines — the list of surnames. No two from those 2*n* strings match. Every name and surname is a non-empty string consisting of no more than 10 Latin letters. It is ... | The output data consist of a single line — the needed list. Note that one should follow closely the output data format! | [
"4\nAnn\nAnna\nSabrina\nJohn\nPetrov\nIvanova\nStoltz\nAbacaba\n",
"4\nAa\nAb\nAc\nBa\nAd\nAe\nBb\nBc\n"
] | [
"Ann Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz",
"Aa Ad, Ab Ae, Ac Bb, Ba Bc"
] | none | 0 | [
{
"input": "4\nAnn\nAnna\nSabrina\nJohn\nPetrov\nIvanova\nStoltz\nAbacaba",
"output": "Ann Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz"
},
{
"input": "4\nAa\nAb\nAc\nBa\nAd\nAe\nBb\nBc",
"output": "Aa Ad, Ab Ae, Ac Bb, Ba Bc"
},
{
"input": "5\nDa\nEcccdbbdc\nD\nEabbd\nFaafbfdffa\n... | 1,691,144,590 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | import sys
readline = sys.stdin.readline
names = [[] for _ in range(26)]
surnames = [[] for _ in range(26)]
atidx = {c:i for i,c in enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZ')}
def read_input():
N = int(readline().strip())
for i in range(N):
word = readline().strip()
names[atidx[word[0]]].append(... | Title: Director
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is a born Berland film director, he is currently working on a new blockbuster, "The Unexpected". Vasya knows from his own experience how important it is to choose the main characters' names and surnames wisely. He made up a ... | ```python
import sys
readline = sys.stdin.readline
names = [[] for _ in range(26)]
surnames = [[] for _ in range(26)]
atidx = {c:i for i,c in enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZ')}
def read_input():
N = int(readline().strip())
for i in range(N):
word = readline().strip()
names[atidx[word[0]... | 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,619,890,904 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 109 | 0 | a,b,c =map(int,input().split())
temp1 = a+c+b
temp2 = b+b+a+a
temp3 = a+c+c+a
temp4 = b+c+c+b
print(min(temp1,temp2,temp3,temp4)) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
a,b,c =map(int,input().split())
temp1 = a+c+b
temp2 = b+b+a+a
temp3 = a+c+c+a
temp4 = b+c+c+b
print(min(temp1,temp2,temp3,temp4))
``` | 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,080,345 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n, m = [int(x) for x in input().split()]
l = []
for i in range(n):
f = [int(x) for x in input().split()]
for i in f[1:]:
l.append(i)
v = []
for i in range(1,n+1):
v.append(i in l)
if 0 in v:
print("NO")
else:
print("YES") | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n, m = [int(x) for x in input().split()]
l = []
for i in range(n):
f = [int(x) for x in input().split()]
for i in f[1:]:
l.append(i)
v = []
for i in range(1,n+1):
v.append(i in l)
if 0 in v:
print("NO")
else:
print("YES")
``` | 0 | |
552 | A | Vanya and Table | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of rectangles.
Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1<=≤<=*x*2<=≤<=100, 1<=≤<=*y*1<=≤<=*y*2<=≤<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *... | In a single line print the sum of all values in the cells of the table. | [
"2\n1 1 2 3\n2 2 3 3\n",
"2\n1 1 3 3\n1 1 3 3\n"
] | [
"10\n",
"18\n"
] | Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110
So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will ... | 500 | [
{
"input": "2\n1 1 2 3\n2 2 3 3",
"output": "10"
},
{
"input": "2\n1 1 3 3\n1 1 3 3",
"output": "18"
},
{
"input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13",
"output": "510"
},
{
"input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11",
"o... | 1,539,191,106 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 108 | 0 | n = int(input())
counter = 0
for i in range(n):
x1 = int(input())
y1 = int(input())
x2 = int(input())
y2 = int(input())
counter += (x2 - x1 + 1) * (y2 - y1 + 1)
print(counter) | Title: Vanya and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vany... | ```python
n = int(input())
counter = 0
for i in range(n):
x1 = int(input())
y1 = int(input())
x2 = int(input())
y2 = int(input())
counter += (x2 - x1 + 1) * (y2 - y1 + 1)
print(counter)
``` | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an array *a* with *n* distinct integers. Construct an array *b* by permuting *a* such that for every non-empty subset of indices *S*<==<={*x*1,<=*x*2,<=...,<=*x**k*} (1<=≤<=*x**i*<=≤<=*n*, 0<=<<=*k*<=<<=*n*) the sums of elements on that positions in *a* and *b* are different, i. e. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=22) — the size of the array.
The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the elements of the array. | If there is no such array *b*, print -1.
Otherwise in the only line print *n* space-separated integers *b*1,<=*b*2,<=...,<=*b**n*. Note that *b* must be a permutation of *a*.
If there are multiple answers, print any of them. | [
"2\n1 2\n",
"4\n1000 100 10 1\n"
] | [
"2 1 \n",
"100 1 1000 10\n"
] | An array *x* is a permutation of *y*, if we can shuffle elements of *y* such that it will coincide with *x*.
Note that the empty subset and the subset containing all indices are not counted. | 0 | [
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "4\n1000 100 10 1",
"output": "100 1 1000 10"
},
{
"input": "5\n1 3 4 5 2",
"output": "5 2 3 4 1 "
},
{
"input": "1\n10000000",
"output": "10000000 "
},
{
"input": "4\n1 5 8 4",
"output": "8 4 5 1 "
},
{
... | 1,510,945,320 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | n = int(input())
a = list(map(int, input().split()))
sorted_a = sorted(a)
shifted_sorted_a = [sorted_a[-1]] + sorted_a[:-1]
#print(sorted_a)
#print(shifted_sorted_a)
for i in range(len(a)):
pos_in_sorted = sorted_a.index(a[i])
print(shifted_sorted_a[pos_in_sorted], end=" ")
print()
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* distinct integers. Construct an array *b* by permuting *a* such that for every non-empty subset of indices *S*<==<={*x*1,<=*x*2,<=...,<=*x**k*} (1<=≤<=*x**i*<=≤<=*n*, 0<=<<=*k*<=<<=*n*) th... | ```python
n = int(input())
a = list(map(int, input().split()))
sorted_a = sorted(a)
shifted_sorted_a = [sorted_a[-1]] + sorted_a[:-1]
#print(sorted_a)
#print(shifted_sorted_a)
for i in range(len(a)):
pos_in_sorted = sorted_a.index(a[i])
print(shifted_sorted_a[pos_in_sorted], end=" ")
print()
``` | 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,665,045,817 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | count = 1
pre = None
for i in input():
count = count+1 if i == pre else 1
if count == 7:
print("YES")
break
pre = i
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
count = 1
pre = None
for i in input():
count = count+1 if i == pre else 1
if count == 7:
print("YES")
break
pre = i
else:
print("NO")
``` | 3.977 |
302 | B | Eugeny and Play List | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"two pointers"
] | null | null | Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i* *c**i* times. Eugeny's play list is organized as follows: first song number 1 plays *c*1 times, then son... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *n* lines contain pairs of integers. The *i*-th line contains integers *c**i*,<=*t**i* (1<=≤<=*c**i*,<=*t**i*<=≤<=109) — the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 109 .
The next... | Print *m* integers — the *i*-th number must equal the number of the song that was playing during the *v**i*-th minute after Eugeny started listening to the play list. | [
"1 2\n2 8\n1 16\n",
"4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9\n"
] | [
"1\n1\n",
"1\n1\n2\n2\n3\n4\n4\n4\n4\n"
] | none | 1,000 | [
{
"input": "1 2\n2 8\n1 16",
"output": "1\n1"
},
{
"input": "4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9",
"output": "1\n1\n2\n2\n3\n4\n4\n4\n4"
},
{
"input": "3 3\n2 8\n5 1\n10 5\n13 16 62",
"output": "1\n1\n3"
},
{
"input": "4 4\n2 8\n2 2\n6 3\n8 7\n13 23 29 85",
"output... | 1,684,392,752 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 686 | 17,100,800 | n, m = map(int, input().split())
songs = []
c = 0
for i in range(n):
a, b = map(int, input().split())
c += a * b
songs.append(c)
v = list(map(int, input().split()))
si = 0
for it in v:
while songs[si] < it:
si += 1
print(si + 1) | Title: Eugeny and Play List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i... | ```python
n, m = map(int, input().split())
songs = []
c = 0
for i in range(n):
a, b = map(int, input().split())
c += a * b
songs.append(c)
v = list(map(int, input().split()))
si = 0
for it in v:
while songs[si] < it:
si += 1
print(si + 1)
``` | 3 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,683,951,251 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 218 | 15,052,800 | import math,sys,collections,bisect,heapq
from itertools import combinations
def natural(n):
return n*(n+1)//2
def possible(freq,mid,n):
c = 0
for i in freq:
c+=freq[i]//mid
if c>=n:
return True
return False
def binarysearch(l,r,arr,k,ini):
if l<=r:
mid = (l+r)//2
if ini-arr[mid]>=k:
return binaryse... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
import math,sys,collections,bisect,heapq
from itertools import combinations
def natural(n):
return n*(n+1)//2
def possible(freq,mid,n):
c = 0
for i in freq:
c+=freq[i]//mid
if c>=n:
return True
return False
def binarysearch(l,r,arr,k,ini):
if l<=r:
mid = (l+r)//2
if ini-arr[mid]>=k:
retur... | 3 | |
868 | B | Race Against Time | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with ... | Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand. | Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"12 30 45 3 11\n",
"12 0 1 12 1\n",
"3 47 0 4 9\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | 500 | [
{
"input": "12 30 45 3 11",
"output": "NO"
},
{
"input": "12 0 1 12 1",
"output": "YES"
},
{
"input": "3 47 0 4 9",
"output": "YES"
},
{
"input": "10 22 59 6 10",
"output": "YES"
},
{
"input": "3 1 13 12 3",
"output": "NO"
},
{
"input": "11 19 28 9 10"... | 1,689,767,581 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 46 | 0 | # LUOGU_RID: 116460278
a,b,c,d,e = map(int,input().split())
a,b,c,d,e = (5*a+0.5)%60,(b+0.5)%60,(c+0.5)%60,5*d,5*e
f,g = min(d,e),max(d,e)
if (f<a<g or f<b<g or f<c<g) and ((0<a<f or g<a<60) or (0<b<f or g<b<60) or (0<c<f or g<c<60)):
print('NO')
else:
print('YES') | Title: Race Against Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time par... | ```python
# LUOGU_RID: 116460278
a,b,c,d,e = map(int,input().split())
a,b,c,d,e = (5*a+0.5)%60,(b+0.5)%60,(c+0.5)%60,5*d,5*e
f,g = min(d,e),max(d,e)
if (f<a<g or f<b<g or f<c<g) and ((0<a<f or g<a<60) or (0<b<f or g<b<60) or (0<c<f or g<c<60)):
print('NO')
else:
print('YES')
``` | 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,690,398,754 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | def gravity_flip(arr):
arr.sort()
return arr
# Read the number of columns in the box
n = int(input())
# Read the number of cubes in each column
columns = list (map(int, input().split()))
# Find the amounts of cubes in each column after the gravity switch
result = gravity_flip (columns)
# Print the result
pr... | 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
def gravity_flip(arr):
arr.sort()
return arr
# Read the number of columns in the box
n = int(input())
# Read the number of cubes in each column
columns = list (map(int, input().split()))
# Find the amounts of cubes in each column after the gravity switch
result = gravity_flip (columns)
# Print the... | 3 | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,601,400,004 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | import sys
input=sys.stdin.readline()
n= int(input)
input=sys.stdin.readline()
arr = list(map(int, input.split()))
ar=[]
for i in range(n):
ar.append([arr[i], i+1])
ar.sort()
for i in range(n//2):
print(ar[i][1], ar[n-1-i][1] ) | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
import sys
input=sys.stdin.readline()
n= int(input)
input=sys.stdin.readline()
arr = list(map(int, input.split()))
ar=[]
for i in range(n):
ar.append([arr[i], i+1])
ar.sort()
for i in range(n//2):
print(ar[i][1], ar[n-1-i][1] )
``` | 3 | |
190 | D | Non-Secret Cypher | PROGRAMMING | 1,900 | [
"two pointers"
] | null | null | Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the informati... | The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array... | Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 2\n1 2 1 2\n",
"5 3\n1 2 1 1 3\n",
"3 1\n1 1 1\n"
] | [
"3",
"2",
"6"
] | In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), ... | 2,000 | [
{
"input": "4 2\n1 2 1 2",
"output": "3"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2"
},
{
"input": "3 1\n1 1 1",
"output": "6"
},
{
"input": "20 2\n6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10",
"output": "131"
},
{
"input": "63 2\n1 2 1 2 4 5 1 1 1 1 1 2 3 1 2 3 3... | 1,665,564,606 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 216 | 6,246,400 | from collections import defaultdict
from email.policy import default
n, k = list(map(int, input().split(' ')))
nums = list(map(int, input().split(' ')))
l, r = 0, 0
visited = defaultdict(int)
count = 0
repeated = 0
while r < n:
visited[nums[r]] += 1
if visited[nums[r]] >= k:
repeated ... | Title: Non-Secret Cypher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunat... | ```python
from collections import defaultdict
from email.policy import default
n, k = list(map(int, input().split(' ')))
nums = list(map(int, input().split(' ')))
l, r = 0, 0
visited = defaultdict(int)
count = 0
repeated = 0
while r < n:
visited[nums[r]] += 1
if visited[nums[r]] >= k:
... | 0 | |
913 | B | Christmas Spruce | PROGRAMMING | 1,200 | [
"implementation",
"trees"
] | null | null | Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a ... | The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*).
Vertex 1 is the root. It's guaranteed that the root ha... | Print "Yes" if the tree is a spruce and "No" otherwise. | [
"4\n1\n1\n1\n",
"7\n1\n1\n1\n2\n2\n2\n",
"8\n1\n1\n1\n1\n3\n3\n3\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | The first example:
<img class="tex-graphics" src="https://espresso.codeforces.com/8dd976913226df83d535dfa66193f5525f8471bc.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The second example:
<img class="tex-graphics" src="https://espresso.codeforces.com/44dad5804f5290a2e026c9c41a15151562df8682.png" style="max-w... | 750 | [
{
"input": "4\n1\n1\n1",
"output": "Yes"
},
{
"input": "7\n1\n1\n1\n2\n2\n2",
"output": "No"
},
{
"input": "8\n1\n1\n1\n1\n3\n3\n3",
"output": "Yes"
},
{
"input": "3\n1\n1",
"output": "No"
},
{
"input": "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10",
"output": "N... | 1,655,292,729 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 108 | 1,740,800 | from collections import defaultdict
n = int(input())
tree = defaultdict(list)
for i in range(n-1):
p = int(input())
tree[p].append(i+2)
for i in range(1, n+1):
if i not in tree : tree[i] = []
ans = "YES"
for vertex in tree :
c = 0
for child in tree[vertex]:
if len(tree[ch... | Title: Christmas Spruce
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there ex... | ```python
from collections import defaultdict
n = int(input())
tree = defaultdict(list)
for i in range(n-1):
p = int(input())
tree[p].append(i+2)
for i in range(1, n+1):
if i not in tree : tree[i] = []
ans = "YES"
for vertex in tree :
c = 0
for child in tree[vertex]:
if l... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109... | Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. | [
"3\n7 1 3\n1 2 1\n",
"4\n5 10 3 2\n2 3 2 4\n"
] | [
"2.000000000000\n",
"1.400000000000\n"
] | In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. | 0 | [
{
"input": "3\n7 1 3\n1 2 1",
"output": "2.000000000000"
},
{
"input": "4\n5 10 3 2\n2 3 2 4",
"output": "1.400000000000"
},
{
"input": "3\n1 1000000000 2\n1 2 1000000000",
"output": "333333332.999999999971"
},
{
"input": "2\n4 5\n10 8",
"output": "0.055555555556"
},
... | 1,488,737,457 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 5,000 | 8,294,400 | def mult_mat(M1, M2):
a11 = M1[0][0]*M2[0][0] + M1[0][1]*M2[1][0]
a12 = M1[0][0]*M2[0][1] + M1[0][1]*M2[1][1]
a21 = M1[1][0]*M2[0][0] + M1[1][1]*M2[1][0]
a22 = M1[1][0]*M2[0][1] + M1[1][1]*M2[1][1]
r = [[a11, a12], [a21, a22]]
return r
def binpow(a, n):
rez = [[a[0][0], a[0][1]], [... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*... | ```python
def mult_mat(M1, M2):
a11 = M1[0][0]*M2[0][0] + M1[0][1]*M2[1][0]
a12 = M1[0][0]*M2[0][1] + M1[0][1]*M2[1][1]
a21 = M1[1][0]*M2[0][0] + M1[1][1]*M2[1][0]
a22 = M1[1][0]*M2[0][1] + M1[1][1]*M2[1][1]
r = [[a11, a12], [a21, a22]]
return r
def binpow(a, n):
rez = [[a[0][0], a... | 0 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,530,809,069 | 569 | Python 3 | OK | TESTS | 45 | 124 | 0 | n, d = map(int, input().split())
a = [int(x) for x in input().split()]
test = set()
for x in a:
fi = x + d
se = x - d
if min(abs(coord - fi) for coord in a) == d:
test.add(fi)
if min(abs(coord - se) for coord in a) == d:
test.add(se)
print(len(test)) | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
n, d = map(int, input().split())
a = [int(x) for x in input().split()]
test = set()
for x in a:
fi = x + d
se = x - d
if min(abs(coord - fi) for coord in a) == d:
test.add(fi)
if min(abs(coord - se) for coord in a) == d:
test.add(se)
print(len(test))
``` | 3 | |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,629,235,438 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,656,000 | n,a,b=map(int,input().split())
ans=0
for i in range(n):
if i>=a-1 and i<=b-1:
ans+=1
ans
| Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
n,a,b=map(int,input().split())
ans=0
for i in range(n):
if i>=a-1 and i<=b-1:
ans+=1
ans
``` | 0 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,588,603,601 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 | def gcd(a, b): return max(a, b) if min(a, b) == 0 else gcd(b, a%b)
[a, b, n] = [int(x) for x in input().split()]
i = 0
while n >= 0:
if i%2 == 0: n -= gcd(n, a)
else: n -= gcd(n, b)
i += 1
print(0 if i%2 == 0 else 1)
| Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
def gcd(a, b): return max(a, b) if min(a, b) == 0 else gcd(b, a%b)
[a, b, n] = [int(x) for x in input().split()]
i = 0
while n >= 0:
if i%2 == 0: n -= gcd(n, a)
else: n -= gcd(n, b)
i += 1
print(0 if i%2 == 0 else 1)
``` | 3 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,498,195,948 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 5,529,600 | def gcd(a,b):
if a==0:
return int(b)
return int(gcd(b%a,a))
t,w,b=map(int,(input().split()))
lcm = int((w*b)/gcd(w,b))
mul = int(t//lcm)
ans = min(t, lcm*mul+int(min(w,b)-1)) - lcm*mul + 1
ans += mul*min(w, b) - 1
g2 = gcd(ans,t)
print(int(ans/(g2)),"/",int(t//(g2)),sep="")
| Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
def gcd(a,b):
if a==0:
return int(b)
return int(gcd(b%a,a))
t,w,b=map(int,(input().split()))
lcm = int((w*b)/gcd(w,b))
mul = int(t//lcm)
ans = min(t, lcm*mul+int(min(w,b)-1)) - lcm*mul + 1
ans += mul*min(w, b) - 1
g2 = gcd(ans,t)
print(int(ans/(g2)),"/",int(t//(g2)),sep="")
`... | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,691,762,673 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | a=input()
a=list(map(str,a))
if len(set(a))==2:
print(0)
elif len(set(a))==3:
print(1)
else:
print(len(set(a))-4)
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
a=input()
a=list(map(str,a))
if len(set(a))==2:
print(0)
elif len(set(a))==3:
print(1)
else:
print(len(set(a))-4)
``` | 3 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,690,961,237 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import math
n = int(input())
a = int(math.sqrt(n))
if int(math.pow(a,2)) == n:
print(1)
else:
print(n-int(math.pow(a,2))) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
import math
n = int(input())
a = int(math.sqrt(n))
if int(math.pow(a,2)) == n:
print(1)
else:
print(n-int(math.pow(a,2)))
``` | 0 | |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,586,869,957 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 109 | 409,600 |
n = int(input())
mult = n // 4
oth = n % 4
ans = 'aabb' * mult
if oth == 1:
ans += 'a'
elif oth == 2:
ans += 'aa'
else:
ans += 'aab'
print(ans) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n = int(input())
mult = n // 4
oth = n % 4
ans = 'aabb' * mult
if oth == 1:
ans += 'a'
elif oth == 2:
ans += 'aa'
else:
ans += 'aab'
print(ans)
``` | 0 | |
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac... | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n... | 1,690,196,198 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 156 | 3,379,200 | def main():
n = int(input())
a = [0] * 1000
b = [0] * 1000
for i in range(n):
a[i], b[i] = map(int, input().split())
s = 0
for i in range(n):
x1, x2, x3, x4 = True, True, True, True
for j in range(n):
if a[i] > a[j] and b[i] == b[j]:
... | Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give... | ```python
def main():
n = int(input())
a = [0] * 1000
b = [0] * 1000
for i in range(n):
a[i], b[i] = map(int, input().split())
s = 0
for i in range(n):
x1, x2, x3, x4 = True, True, True, True
for j in range(n):
if a[i] > a[j] and b[i] == b[j]:
... | 3 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,613,019,321 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 404 | 8,192,000 | y,k,n = map(int,input().split())
cnt=0
if y==n:
print(-1)
else:
c =k-(y%k)
for i in range(10**5):
if c+y<=n:
print(c,end=" ")
c+=k
else:
break | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y,k,n = map(int,input().split())
cnt=0
if y==n:
print(-1)
else:
c =k-(y%k)
for i in range(10**5):
if c+y<=n:
print(c,end=" ")
c+=k
else:
break
``` | 0 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,697,604,650 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | x,y,z=map(int,input().split())
result=[x]
def fun():
for i in result:
if i == 1 or i == 0:
continue
else:
result.insert(result.index(i), i // 2)
result.insert(result.index(i), i % 2)
result.insert(result.index(i), i // 2)
result.pop(result.... | Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
x,y,z=map(int,input().split())
result=[x]
def fun():
for i in result:
if i == 1 or i == 0:
continue
else:
result.insert(result.index(i), i // 2)
result.insert(result.index(i), i % 2)
result.insert(result.index(i), i // 2)
result.p... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,671,538,249 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | c,d=map(int,input().split())
s=c*d/2
print(int(s))
| 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
c,d=map(int,input().split())
s=c*d/2
print(int(s))
``` | 3.977 |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,690,790,683 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
a = list(map(int, input().split()))
up = max(a)
down = min(a)
u_p = a.index(up)+1
d_p = a.index(down)+1
ans = up-1+n-d_p
print(ans) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n = int(input())
a = list(map(int, input().split()))
up = max(a)
down = min(a)
u_p = a.index(up)+1
d_p = a.index(down)+1
ans = up-1+n-d_p
print(ans)
``` | 0 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,686,333,548 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 124 | 15,872,000 | n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
lst = []
lst.append(sum(arr[:k]))
for i in range(k,n):
lst.append(lst[-1]+arr[i]-arr[i-k])
mn = min(lst)
print(lst.index(mn)+1)
| Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
lst = []
lst.append(sum(arr[:k]))
for i in range(k,n):
lst.append(lst[-1]+arr[i]-arr[i-k])
mn = min(lst)
print(lst.index(mn)+1)
``` | 3 | |
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,424,173 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 0 | # get input
N = int(input())
square_str = input()
previous = 'W'
B_cnt = 0
results = []
for i in range(N):
if square_str[i] == 'B':
if previous == 'B':
B_cnt += 1
else:
# '...WB...', recount
B_cnt = 1
previous = 'B'
else: # get 'W'
if previ... | 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
# get input
N = int(input())
square_str = input()
previous = 'W'
B_cnt = 0
results = []
for i in range(N):
if square_str[i] == 'B':
if previous == 'B':
B_cnt += 1
else:
# '...WB...', recount
B_cnt = 1
previous = 'B'
else: # get 'W'
... | 3 | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,523,558,375 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 77 | 7,065,600 | a , b ,c=(map(int ,input().split()))
while(a<b):
a=a+c
if(a==b):
print('YES')
else:
print('NO')
| Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a , b ,c=(map(int ,input().split()))
while(a<b):
a=a+c
if(a==b):
print('YES')
else:
print('NO')
``` | 0 | |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,570,648,743 | 2,147,483,647 | PyPy 3 | OK | TESTS | 53 | 171 | 11,673,600 | from itertools import accumulate
n = int(input())
s = input().strip()
a = [0] + list(accumulate(2 * int(d) - 1 for d in list(s)))
m = {}
for i in range(len(a)):
if a[i] not in m:
m[a[i]] = i
a[i] = i - m[a[i]]
print(max(a))
| Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
from itertools import accumulate
n = int(input())
s = input().strip()
a = [0] + list(accumulate(2 * int(d) - 1 for d in list(s)))
m = {}
for i in range(len(a)):
if a[i] not in m:
m[a[i]] = i
a[i] = i - m[a[i]]
print(max(a))
``` | 3 | |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,609,243,508 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 140 | 819,200 | s1=input()
import string
s2=input()
a=list(string.ascii_lowercase)
li=list(x for x in s1 )
i=len(li)-1
while True:
if li[i]=='z':
pass
else:
li[i]=a[a.index(li[i])+1]
break
i-=1
if i<0:
break
for j in range(i+1,len(s1)):
li[i]='a'
li=''.join(li)
... | Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
s1=input()
import string
s2=input()
a=list(string.ascii_lowercase)
li=list(x for x in s1 )
i=len(li)-1
while True:
if li[i]=='z':
pass
else:
li[i]=a[a.index(li[i])+1]
break
i-=1
if i<0:
break
for j in range(i+1,len(s1)):
li[i]='a'
li=''... | 0 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,688,409,523 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | var s:string; i,n:longint;
begin
readln (n);
readln (s);
for i:=1 to length(s) do
if s[i]='0' then break;
if i>length(s) then i:=length(s);
writeln (i);
end. | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
var s:string; i,n:longint;
begin
readln (n);
readln (s);
for i:=1 to length(s) do
if s[i]='0' then break;
if i>length(s) then i:=length(s);
writeln (i);
end.
``` | -1 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,696,928,684 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 92 | 0 | #黄靖涵 2300098604 工学院 2023秋
t = int(input())
def angle(a):
if 360 % (180 - a):
return "NO"
else:
return "YES"
for i in range(t):
a = int(input())
ans = angle(a)
print(ans) | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
#黄靖涵 2300098604 工学院 2023秋
t = int(input())
def angle(a):
if 360 % (180 - a):
return "NO"
else:
return "YES"
for i in range(t):
a = int(input())
ans = angle(a)
print(ans)
``` | 3 | |
18 | D | Seller Bob | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"greedy"
] | D. Seller Bob | 2 | 128 | Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB me... | The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than... | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | [
"7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n",
"3\nwin 5\nsell 6\nsell 4\n"
] | [
"1056\n",
"0\n"
] | none | 0 | [
{
"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10",
"output": "1056"
},
{
"input": "3\nwin 5\nsell 6\nsell 4",
"output": "0"
},
{
"input": "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23... | 1,626,889,927 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 404 | 24,166,400 | read = lambda: [int(i) for i in input().split()]
n = int(input())
a = [0] * n
for i in range(n):
s, x = input().split()
x = int(x)
if s == "sell":
a[i] = x + 1
else:
a[i] = -x - 1
pos = dict()
left = [-1] * n
for i in range(n):
if -a[i] in pos:
left[i] = pos[-a[i]]
pos[a[i]] = i
dp =... | Title: Seller Bob
Time Limit: 2 seconds
Memory Limit: 128 megabytes
Problem Description:
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he... | ```python
read = lambda: [int(i) for i in input().split()]
n = int(input())
a = [0] * n
for i in range(n):
s, x = input().split()
x = int(x)
if s == "sell":
a[i] = x + 1
else:
a[i] = -x - 1
pos = dict()
left = [-1] * n
for i in range(n):
if -a[i] in pos:
left[i] = pos[-a[i]]
pos[a[i]] =... | 3.808973 |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,564,571,961 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | dhve = list(map(int, input().split()))
d, h, v, e = dhve[0], dhve[1], dhve[2], dhve[3]
pi = 3.14159265358979
V = (v*7*4)/(d*d*22)
relative_speed = V-e
if relative_speed <= 0:
print("NO")
else:
print("YES")
print(h/relative_speed)
| Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, cont... | ```python
dhve = list(map(int, input().split()))
d, h, v, e = dhve[0], dhve[1], dhve[2], dhve[3]
pi = 3.14159265358979
V = (v*7*4)/(d*d*22)
relative_speed = V-e
if relative_speed <= 0:
print("NO")
else:
print("YES")
print(h/relative_speed)
``` | 0 | |
967 | A | Mind the Gap | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minut... | The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, i... | Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | [
"6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n",
"16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n",
"3 17\n0 30\n1 0\n12 0\n"
] | [
"6 1\n",
"24 50\n",
"0 0\n"
] | In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert th... | 500 | [
{
"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40",
"output": "6 1"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "24 50"
},
{
"input": "3 17\n0 30\n1 0\n12 0",
"output": "0 0"
},
{
... | 1,611,534,131 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 2,150,400 | n, s = map(int, input().split())
times = []
result = 0
for i in range (n):
h, m = map(int, input().split())
times.append(60*h + m)
for i in range(n-1):
if times[i+1] - times[i] == 2 + 2*s:
result = times[i] + 1 + s
if result == 0:
result = times[n-1] + 1 + s
hour = times // 60
... | Title: Mind the Gap
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing ... | ```python
n, s = map(int, input().split())
times = []
result = 0
for i in range (n):
h, m = map(int, input().split())
times.append(60*h + m)
for i in range(n-1):
if times[i+1] - times[i] == 2 + 2*s:
result = times[i] + 1 + s
if result == 0:
result = times[n-1] + 1 + s
hour = ti... | -1 | |
38 | C | Blinds | PROGRAMMING | 1,400 | [
"brute force"
] | C. Blinds | 2 | 256 | The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are *n* blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they ... | The first output line contains two space-separated integers *n* and *l* (1<=≤<=*n*,<=*l*<=≤<=100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated *n* integers *a**i*. They are the lengths of initial stripes in... | Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0. | [
"4 2\n1 2 3 4\n",
"5 3\n5 5 7 3 1\n",
"2 3\n1 2\n"
] | [
"8\n",
"15\n",
"0\n"
] | In the first sample test the required window is 2 × 4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length ... | 0 | [
{
"input": "4 2\n1 2 3 4",
"output": "8"
},
{
"input": "5 3\n5 5 7 3 1",
"output": "15"
},
{
"input": "2 3\n1 2",
"output": "0"
},
{
"input": "2 2\n3 3",
"output": "6"
},
{
"input": "5 2\n2 4 1 1 3",
"output": "8"
},
{
"input": "7 4\n3 2 1 1 1 3 2",
... | 1,696,053,768 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n, minLen = [int(item) for item in input().split()]
arr = [int(item) for item in input().split()]
limit = max(arr)
maxArea = 0
for _len in range(minLen, limit + 1):
height = 0
for item in arr:
height += item // _len
if maxArea < height * minLen:
maxArea = height * minLen
print(ma... | Title: Blinds
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are *n* blind stripes with the width of 1 in the factory warehouse for blind production.... | ```python
n, minLen = [int(item) for item in input().split()]
arr = [int(item) for item in input().split()]
limit = max(arr)
maxArea = 0
for _len in range(minLen, limit + 1):
height = 0
for item in arr:
height += item // _len
if maxArea < height * minLen:
maxArea = height * minLen... | 0 |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,653,317,741 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 |
line1 = list(map(int,input().split()))
n = line1[0]
d = line1[1]
lis = list(map(int,input().split()))
flag = 0
jokes = 0
time = 0
for i in range(n):
time+=lis[i]
if time > d:
flag = 1
break
jokes += 2
time+=10
if flag == 1:
print(-1)
else:
... | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
line1 = list(map(int,input().split()))
n = line1[0]
d = line1[1]
lis = list(map(int,input().split()))
flag = 0
jokes = 0
time = 0
for i in range(n):
time+=lis[i]
if time > d:
flag = 1
break
jokes += 2
time+=10
if flag == 1:
print(-1)... | 3 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,698,105,673 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # Input
s = input() # Starting position
t = input() # Target position
# Extract row and column numbers for both positions
s_row, s_col = int(s[1]), ord(s[0]) - ord('a') + 1
t_row, t_col = int(t[1]), ord(t[0]) - ord('a') + 1
# Calculate the number of moves in the row and column directions
row_moves = abs(t_... | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
# Input
s = input() # Starting position
t = input() # Target position
# Extract row and column numbers for both positions
s_row, s_col = int(s[1]), ord(s[0]) - ord('a') + 1
t_row, t_col = int(t[1]), ord(t[0]) - ord('a') + 1
# Calculate the number of moves in the row and column directions
row_move... | 0 |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,592,800,638 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 280 | 0 | n=int(input())
li=list(input().split())
li1=[0,0,0]
li2=['chest','biceps','back']
for i,j in enumerate(li):
li1[int(i)%3]+=int(j)
print(li2[li1.index(max(li1))])
| Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n=int(input())
li=list(input().split())
li1=[0,0,0]
li2=['chest','biceps','back']
for i,j in enumerate(li):
li1[int(i)%3]+=int(j)
print(li2[li1.index(max(li1))])
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,692,916,707 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | for _ in range(int(input())):
x = input()
n = len(x)
if n > 10:
print(x[0] + str(n - 2) + x[n-1])
else:
print(x) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
for _ in range(int(input())):
x = input()
n = len(x)
if n > 10:
print(x[0] + str(n - 2) + x[n-1])
else:
print(x)
``` | 3.977 |
33 | C | Wonderful Randomized Sum | PROGRAMMING | 1,800 | [
"greedy"
] | C. Wonderful Randomized Sum | 2 | 256 | Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of elements in the sequence. The second line contains *n* integers *a**i* (<=-<=104<=≤<=*a**i*<=≤<=104) — the sequence itself. | The first and the only line of the output should contain the answer to the problem. | [
"3\n-1 -2 -3\n",
"5\n-4 2 0 5 0\n",
"5\n-1 10 -5 10 -2\n"
] | [
"6\n",
"11\n",
"18\n"
] | none | 1,500 | [
{
"input": "3\n-1 -2 -3",
"output": "6"
},
{
"input": "5\n-4 2 0 5 0",
"output": "11"
},
{
"input": "5\n-1 10 -5 10 -2",
"output": "18"
},
{
"input": "1\n-3",
"output": "3"
},
{
"input": "4\n1 4 -5 -2",
"output": "12"
},
{
"input": "7\n-17 6 5 0 1 4 -1... | 1,450,746,011 | 2,147,483,647 | Python 3 | OK | TESTS | 89 | 560 | 7,372,800 | class Container:
pass
n = int(input())
values = list(map(int, input().split()))
best_prefixes = (n + 1) * [ 0 ]
plus = 0
best_double_minus = double_minus = 0
for i, x in enumerate(values):
plus += x
double_minus -= 2 * x
best_double_minus = max(best_double_minus, double_minus)
best_prefixes[i + 1]... | Title: Wonderful Randomized Sum
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivat... | ```python
class Container:
pass
n = int(input())
values = list(map(int, input().split()))
best_prefixes = (n + 1) * [ 0 ]
plus = 0
best_double_minus = double_minus = 0
for i, x in enumerate(values):
plus += x
double_minus -= 2 * x
best_double_minus = max(best_double_minus, double_minus)
best_prefi... | 3.846267 |
652 | B | z-sort | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold:
1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=><=1.
For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array *a*.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | If it's possible to make the array *a* *z*-sorted print *n* space separated integers *a**i* — the elements after *z*-sort. Otherwise print the only word "Impossible". | [
"4\n1 2 2 1\n",
"5\n1 3 2 2 5\n"
] | [
"1 2 1 2\n",
"1 5 2 3 2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 1",
"output": "1 2 1 2"
},
{
"input": "5\n1 3 2 2 5",
"output": "1 5 2 3 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1"
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 ... | 1,623,310,983 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 62 | 0 | import math
import sys
def scan():
return list(map(int, sys.stdin.readline().strip().split()))
def solution():
n = int(input())
a = scan()
b = []
c = []
a.sort()
for i in range(n//2):
b.append(a[i])
for j in range(n//2, n):
c.append(a[j])
j = 0
... | Title: z-sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold:
1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=... | ```python
import math
import sys
def scan():
return list(map(int, sys.stdin.readline().strip().split()))
def solution():
n = int(input())
a = scan()
b = []
c = []
a.sort()
for i in range(n//2):
b.append(a[i])
for j in range(n//2, n):
c.append(a[j])
... | 3 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,690,316,610 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 |
n , h = map(int,input().split())
heights = map(int,input().split())
result = 0
for x in heights:
if x >= h:
result+=2
else:
result+=1
print(result)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n , h = map(int,input().split())
heights = map(int,input().split())
result = 0
for x in heights:
if x >= h:
result+=2
else:
result+=1
print(result)
``` | 0 | |
42 | E | Baldman and the military | PROGRAMMING | 2,700 | [
"dfs and similar",
"graphs",
"trees"
] | E. Baldman and the military | 4 | 256 | Baldman is a warp master. He possesses a unique ability — creating wormholes! Given two positions in space, Baldman can make a wormhole which makes it possible to move between them in both directions. Unfortunately, such operation isn't free for Baldman: each created wormhole makes him lose plenty of hair from his head... | First line of the input contains a single natural number *n* (2<=≤<=*n*<=≤<=100000) — the number of objects on the military base. The second line — one number *m* (1<=≤<=*m*<=≤<=200000) — the number of the wormholes Baldman can make. The following *m* lines describe the wormholes: each line contains three integer numbe... | Your program should output *q* lines, one for each query. The *i*-th line should contain a single integer number — the answer for *i*-th query: the minimum cost (in hair) of a system of wormholes allowing the optimal patrol for any system of tunnels (satisfying the given conditions) if *a**i* and *b**i* are the two obj... | [
"2\n1\n1 2 3\n1\n1 2\n",
"3\n1\n1 2 3\n2\n1 2\n1 3\n"
] | [
"0\n",
"-1\n3\n"
] | none | 2,500 | [
{
"input": "2\n1\n1 2 3\n1\n1 2",
"output": "0"
},
{
"input": "3\n1\n1 2 3\n2\n1 2\n1 3",
"output": "-1\n3"
},
{
"input": "4\n4\n1 2 1\n1 3 2\n3 4 3\n1 3 4\n6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "5\n4\n3\n4\n3\n3"
},
{
"input": "4\n5\n1 2 10\n2 3 3\n3 4 4\n1 4 5\n2 4 6\... | 1,689,639,035 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1689639035.8076324")# 1689639035.8076518 | Title: Baldman and the military
Time Limit: 4 seconds
Memory Limit: 256 megabytes
Problem Description:
Baldman is a warp master. He possesses a unique ability — creating wormholes! Given two positions in space, Baldman can make a wormhole which makes it possible to move between them in both directions. Unfortunately... | ```python
print("_RANDOM_GUESS_1689639035.8076324")# 1689639035.8076518
``` | 0 |
429 | E | Points and Segments | PROGRAMMING | 3,000 | [
"graphs"
] | null | null | Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following.
Iahub wants to draw *n* distinct segments [*l**i*... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. The *i*-th of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It's guaranteed that all the segments are distinct. | If there is no good drawing for a given test, output a single integer -1. Otherwise output *n* integers; each integer must be 0 or 1. The *i*-th number denotes the color of the *i*-th segment (0 is red and 1 is blue).
If there are multiple good drawings you can output any of them. | [
"2\n0 2\n2 3\n",
"6\n1 5\n1 3\n3 5\n2 10\n11 11\n12 12\n"
] | [
"0 1\n",
"0 1 0 1 0 0\n"
] | none | 2,000 | [] | 1,604,102,033 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 108 | 921,600 | def dfs(v,color):
if visit[v]:
return
visit[v] = True
answer[v] = color
for vertex in adj[v]:
dfs(vertex,color^1)
n=int(input())
A=[(0,0)]*2*n
adj=[[] for i in range (2*n)]
visit=[False]*2*n
answer=[0]*2*n
for i in range(n):
left,right=map(int,input().split())
... | Title: Points and Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of ne... | ```python
def dfs(v,color):
if visit[v]:
return
visit[v] = True
answer[v] = color
for vertex in adj[v]:
dfs(vertex,color^1)
n=int(input())
A=[(0,0)]*2*n
adj=[[] for i in range (2*n)]
visit=[False]*2*n
answer=[0]*2*n
for i in range(n):
left,right=map(int,input().sp... | -1 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,687,755,627 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | n=int(input())
l=list(map(int,input().split()))
l.sort()
p=[0]*n
s=[0]*n
p[0]=l[0]
s[n-1]=l[n-1]
for i in range(1,n):
p[i]=(p[i-1]+l[i])
for i in range(n-2,-1,-1):
s[i]=s[i+1]+l[i]
i=n-2
c=0
while i>=0:
if s[i+1]>p[i]:
break
i-=1
c+=1
print(c+1) | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n=int(input())
l=list(map(int,input().split()))
l.sort()
p=[0]*n
s=[0]*n
p[0]=l[0]
s[n-1]=l[n-1]
for i in range(1,n):
p[i]=(p[i-1]+l[i])
for i in range(n-2,-1,-1):
s[i]=s[i+1]+l[i]
i=n-2
c=0
while i>=0:
if s[i+1]>p[i]:
break
i-=1
c+=1
print(c+1)
``` | 3 | |
416 | A | Guess a number! | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"two pointers"
] | null | null | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that *y* is st... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10000) — the number of questions (and answers). Next *n* lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries), - "<" (for the se... | Print any of such integers *y*, that the answers to all the queries are correct. The printed number *y* must meet the inequation <=-<=2·109<=≤<=*y*<=≤<=2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | [
"4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N\n",
"2\n> 100 Y\n< -100 Y\n"
] | [
"17\n",
"Impossible\n"
] | none | 500 | [
{
"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N",
"output": "17"
},
{
"input": "2\n> 100 Y\n< -100 Y",
"output": "Impossible"
},
{
"input": "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N",
"output": "1"
},
{
"input": "4\n<= 1 Y\n>= 1 Y\n>= 1 Y\n<= 1 Y",
"output": "1"
},
{
"input": ... | 1,545,446,232 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 140 | 0 | """
██╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗
██║██╔═══██╗██║ ╚════██╗██╔═████╗███║██╔══██╗
██║██║ ██║██║ █████╔╝██║██╔██║╚██║╚██████║
██║██║ ██║██║ ██╔═══╝ ████╔╝██║ ██║ ╚═══██║
██║╚██████╔╝██║ ███████╗╚██████╔╝ ██║ █████╔╝
╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚════╝
██████╗ ██╗██╗ █████... | Title: Guess a number!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by aski... | ```python
"""
██╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗
██║██╔═══██╗██║ ╚════██╗██╔═████╗███║██╔══██╗
██║██║ ██║██║ █████╔╝██║██╔██║╚██║╚██████║
██║██║ ██║██║ ██╔═══╝ ████╔╝██║ ██║ ╚═══██║
██║╚██████╔╝██║ ███████╗╚██████╔╝ ██║ █████╔╝
╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚════╝
██████╗ ██╗██╗... | 3 | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,652,447,425 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | n = int(input())
l = []
k = 1
for i in range(n):
a, m = map(int, input().split())
if a != m:
print("rated")
k = 0
l.append(a)
l_1 = []
l_1.extend(l)
l_1.sort()
l_1.reverse()
if k == 1:
if l == l_1:
print("maybe")
else:
print("unrated") | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
n = int(input())
l = []
k = 1
for i in range(n):
a, m = map(int, input().split())
if a != m:
print("rated")
k = 0
l.append(a)
l_1 = []
l_1.extend(l)
l_1.sort()
l_1.reverse()
if k == 1:
if l == l_1:
print("maybe")
else:
print("unrated")
`... | 0 | |
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO"... | 1,592,513,623 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | m={'A','H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}
a=set(map(str,input()))
print(a)
if a.issubset(m):
print("YES")
else:
print("NO") | Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of ... | ```python
m={'A','H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}
a=set(map(str,input()))
print(a)
if a.issubset(m):
print("YES")
else:
print("NO")
``` | 0 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,552,577,638 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | n = int(input())
a = input()
s = 0
f = 0
for i in range(0,n,2):
if a[i] == 'S':
s += 1
else:
f += 1
if s > f:
print('YES')
else:
print('NO')
| Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
n = int(input())
a = input()
s = 0
f = 0
for i in range(0,n,2):
if a[i] == 'S':
s += 1
else:
f += 1
if s > f:
print('YES')
else:
print('NO')
``` | 0 | |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,513,658,593 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 140 | 8,806,400 | n = int(input())
a = map(int, input().split())
x, y = 0, 0
for t in a:
if (t == 1): x = x+1
else: y = y+1
z = min(x, y)
ans = z + (x - z) // 3
print (ans) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
n = int(input())
a = map(int, input().split())
x, y = 0, 0
for t in a:
if (t == 1): x = x+1
else: y = y+1
z = min(x, y)
ans = z + (x - z) // 3
print (ans)
``` | 3 | |
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 ... | 1,656,068,064 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | a=int(input())
b=input();
c=len(b)
if(c>a):
print(b[0],c-2,b[c-1]);
else:
print(b) | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob... | ```python
a=int(input())
b=input();
c=len(b)
if(c>a):
print(b[0],c-2,b[c-1]);
else:
print(b)
``` | -1 |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,669,206,440 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n,k=map(int,input().split())
l = list(map(int,input().split()))
c = 0
p = 0
times= 5//k
l.sort()
for i in l:
if i<=times:
p+=1
c = p//3
print(c)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n,k=map(int,input().split())
l = list(map(int,input().split()))
c = 0
p = 0
times= 5//k
l.sort()
for i in l:
if i<=times:
p+=1
c = p//3
print(c)
``` | 0 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,690,707,612 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 124 | 0 | def main() -> None :
BANK_STATE:int = int(input())
maximumBankState:int = -1
LAST_DIGIT_REMOVED_STATE:int = int(str(BANK_STATE)[:-1])
LAST_BEFORE_DIGIT_REMOVED_STATE:int = int(str(BANK_STATE)[:-2] + str(BANK_STATE)[-1])
maximumBankState = max(BANK_STATE, LAST_DIGIT_REMOVED_STATE, LAST_BEFORE_... | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
def main() -> None :
BANK_STATE:int = int(input())
maximumBankState:int = -1
LAST_DIGIT_REMOVED_STATE:int = int(str(BANK_STATE)[:-1])
LAST_BEFORE_DIGIT_REMOVED_STATE:int = int(str(BANK_STATE)[:-2] + str(BANK_STATE)[-1])
maximumBankState = max(BANK_STATE, LAST_DIGIT_REMOVED_STATE, LA... | 3 | |
960 | C | Subsequence Counting | PROGRAMMING | 1,700 | [
"bitmasks",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_su... | The only line of input consists of two space separated integers *X* and *d* (1<=≤<=*X*,<=*d*<=≤<=109). | Output should consist of two lines.
First line should contain a single integer *n* (1<=≤<=*n*<=≤<=10<=000)— the number of integers in the final array.
Second line should consist of *n* space separated integers — *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=<<=1018).
If there is no answer, print a single integer -1.... | [
"10 5\n",
"4 2\n"
] | [
"6\n5 50 7 15 6 100",
"4\n10 100 1000 10000"
] | In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Simil... | 1,500 | [
{
"input": "10 5",
"output": "6\n1 1 1 7 13 19 "
},
{
"input": "4 2",
"output": "3\n1 1 4 "
},
{
"input": "4 1",
"output": "3\n1 1 3 "
},
{
"input": "1 1",
"output": "1\n1 "
},
{
"input": "63 1",
"output": "21\n1 1 1 1 1 3 3 3 3 5 5 5 7 7 9 11 13 15 17 19 21 "... | 1,528,042,292 | 6,092 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 1,000 | 7,168,000 | n , d = map(int, input().split())
print(n)
res = 1
for i in range(n):
if(i != n - 1):
print(res, end = ' ')
else :
print(res)
res += d | Title: Subsequence Counting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he alway... | ```python
n , d = map(int, input().split())
print(n)
res = 1
for i in range(n):
if(i != n - 1):
print(res, end = ' ')
else :
print(res)
res += d
``` | 0 | |
88 | B | Keyboard | PROGRAMMING | 1,500 | [
"implementation"
] | B. Keyboard | 1 | 256 | Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they m... | The first line contains three integers *n*, *m*, *x* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*x*<=≤<=50).
Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys ... | If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes). | [
"2 2 1\nab\ncd\n1\nA\n",
"2 2 1\nab\ncd\n1\ne\n",
"2 2 1\nab\ncS\n5\nabcBA\n",
"3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n"
] | [
"-1\n",
"-1\n",
"1\n",
"2\n"
] | In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.
In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.
In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the key... | 1,000 | [
{
"input": "2 2 1\nab\ncd\n1\nA",
"output": "-1"
},
{
"input": "2 2 1\nab\ncd\n1\ne",
"output": "-1"
},
{
"input": "2 2 1\nab\ncS\n5\nabcBA",
"output": "1"
},
{
"input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG",
"output": "2"
},
... | 1,567,496,202 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 124 | 1,638,400 | import math
def dist(a, b, c, d):
return math.sqrt((a - c) ** 2 + (b - d) ** 2)
class CodeforcesTask88BSolution:
def __init__(self):
self.result = ''
self.n_m_x = []
self.keyboard = []
self.text = ""
def read_input(self):
self.n_m_x = [int(x) for x in input().spl... | Title: Keyboard
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on ... | ```python
import math
def dist(a, b, c, d):
return math.sqrt((a - c) ** 2 + (b - d) ** 2)
class CodeforcesTask88BSolution:
def __init__(self):
self.result = ''
self.n_m_x = []
self.keyboard = []
self.text = ""
def read_input(self):
self.n_m_x = [int(x) for x in i... | 0 |
46 | B | T-shirts from Sponsor | PROGRAMMING | 1,100 | [
"implementation"
] | B. T-shirts from Sponsor | 2 | 256 | One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not ... | The first line contains five non-negative integers *N**S*,<=*N**M*,<=*N**L*,<=*N**XL*,<=*N**XXL* not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer *K* (1<=≤<=*K*<=≤<=1000) which represents the number of participants. The next *K* lines contain the ... | For each contestant, print a line containing the size of the T-shirt he/she got. | [
"1 0 2 0 1\n3\nXL\nXXL\nM\n"
] | [
"XXL\nL\nL\n"
] | none | 0 | [
{
"input": "1 0 2 0 1\n3\nXL\nXXL\nM",
"output": "XXL\nL\nL"
},
{
"input": "0 0 0 0 1\n1\nS",
"output": "XXL"
},
{
"input": "1 0 1 0 1\n1\nS",
"output": "S"
},
{
"input": "1 0 0 0 1\n2\nS\nL",
"output": "S\nXXL"
},
{
"input": "1 1 1 1 1\n2\nXL\nM",
"output": "... | 1,683,545,109 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 216 | 3,379,200 | l=list(map(int,input().split()))[:5]
n=int(input())
lt=[]
ul=[[0,1,2,3,4],[1,2,0,3,4],[2,3,1,4,0],[3,4,2,1,0],[4,3,2,1,0]]
def prn(x):
if x==0:
print('S')
elif x==1:
print('M')
elif x==2:
print('L')
elif x==3:
print('XL')
elif x==4:
print('XXL')
... | Title: T-shirts from Sponsor
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what size... | ```python
l=list(map(int,input().split()))[:5]
n=int(input())
lt=[]
ul=[[0,1,2,3,4],[1,2,0,3,4],[2,3,1,4,0],[3,4,2,1,0],[4,3,2,1,0]]
def prn(x):
if x==0:
print('S')
elif x==1:
print('M')
elif x==2:
print('L')
elif x==3:
print('XL')
elif x==4:
pri... | 3.939706 |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,696,167,963 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 1,331,200 | total = 0
num = int(input())
while num >= 100:
num -= 100
total += 1
while num >= 20:
num -= 20
total += 1
while num >= 10:
num -= 10
total += 1
while num >= 5:
num -= 5
total += 1
while num >= 1:
num -= 1
total += 1
print(total)
| Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
total = 0
num = int(input())
while num >= 100:
num -= 100
total += 1
while num >= 20:
num -= 20
total += 1
while num >= 10:
num -= 10
total += 1
while num >= 5:
num -= 5
total += 1
while num >= 1:
num -= 1
total += 1
print(total)
``` | 3 | |
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag... | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denotin... | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the s... | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"inpu... | 1,695,057,128 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 102,400 | def yzd_solution(f, shop):
sorted_values = sorted(shop.items(), key=lambda item: item[1][1], reverse=True)
for (k, l) in sorted_values:
if l[0] != 0:
l[0] *= 2
f -= 1
if f == 0:
break
products = 0
for (k, l) in sorted_values:
... | Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an ass... | ```python
def yzd_solution(f, shop):
sorted_values = sorted(shop.items(), key=lambda item: item[1][1], reverse=True)
for (k, l) in sorted_values:
if l[0] != 0:
l[0] *= 2
f -= 1
if f == 0:
break
products = 0
for (k, l) in sorted_values:... | 0 | |
808 | A | Lucky Year | PROGRAMMING | 900 | [
"implementation"
] | null | null | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. | Output amount of years from the current year to the next lucky one. | [
"4\n",
"201\n",
"4000\n"
] | [
"1\n",
"99\n",
"1000\n"
] | In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | 0 | [
{
"input": "4",
"output": "1"
},
{
"input": "201",
"output": "99"
},
{
"input": "4000",
"output": "1000"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "1",
"output": "1"
},
{
"input": "100000000",
"ou... | 1,594,267,958 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 6,656,000 | import numpy as np
import math as mt
x = int(input())
k = True
if x <= 9:
print(1)
k = False
if k:
print(10**mt.floor(np.log10(x)) - x%10)
| Title: Lucky Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 1... | ```python
import numpy as np
import math as mt
x = int(input())
k = True
if x <= 9:
print(1)
k = False
if k:
print(10**mt.floor(np.log10(x)) - x%10)
``` | -1 | |
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,657,561,426 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 93 | 0 | ham = input()
supplies = list(map(int,input().split()))
price = list(map(int,input().split()))
money = int(input())
required = [ham.count("B"),ham.count("S"),ham.count("C")]
l,h = 0,(money + 200)
while(l<=h):
mid = (l + h)//2
cost = 0
req = []
for i in range(3):
req.append(max(required[i] * mid - s... | 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
ham = input()
supplies = list(map(int,input().split()))
price = list(map(int,input().split()))
money = int(input())
required = [ham.count("B"),ham.count("S"),ham.count("C")]
l,h = 0,(money + 200)
while(l<=h):
mid = (l + h)//2
cost = 0
req = []
for i in range(3):
req.append(max(required[i]... | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,621,609,423 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | l=['Sheldon', 'Leonard', 'Penny' ,'Rajesh','Howard']
n=int(input())
while n>5:
n-=5
n//=2
# print(n)
print(l[n]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
l=['Sheldon', 'Leonard', 'Penny' ,'Rajesh','Howard']
n=int(input())
while n>5:
n-=5
n//=2
# print(n)
print(l[n])
``` | 0 |
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd... | 1,647,704,559 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | x=input()
y=input()
n,m=0,0
for i in range(len(x)-1):
if ord(x[i+1])-ord(x[i])==1:
n+=1
for c in range(len(y)-1):
if ord(y[c+1])-ord(y[c])==1:
m+=1
print(-1 if n==m else max(m,n)+1) | Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two ... | ```python
x=input()
y=input()
n,m=0,0
for i in range(len(x)-1):
if ord(x[i+1])-ord(x[i])==1:
n+=1
for c in range(len(y)-1):
if ord(y[c+1])-ord(y[c])==1:
m+=1
print(-1 if n==m else max(m,n)+1)
``` | 0 | |
58 | B | Coins | PROGRAMMING | 1,300 | [
"greedy"
] | B. Coins | 2 | 256 | In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d... | The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin. | Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coin... | [
"10\n",
"4\n",
"3\n"
] | [
"10 5 1\n",
"4 2 1\n",
"3 1\n"
] | none | 1,000 | [
{
"input": "10",
"output": "10 5 1"
},
{
"input": "4",
"output": "4 2 1"
},
{
"input": "3",
"output": "3 1"
},
{
"input": "2",
"output": "2 1"
},
{
"input": "5",
"output": "5 1"
},
{
"input": "6",
"output": "6 3 1"
},
{
"input": "7",
"o... | 1,503,617,812 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 530 | 0 | n = int(input())
cont = 0
for i in range(n, 0, -1):
if n%i == 0:
n = i
if cont == 0:
cont = 1
else:
print(' ', end = '')
print(n, end = '')
print()
| Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following... | ```python
n = int(input())
cont = 0
for i in range(n, 0, -1):
if n%i == 0:
n = i
if cont == 0:
cont = 1
else:
print(' ', end = '')
print(n, end = '')
print()
``` | 3.8675 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,604,418,373 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 218 | 0 | n = int(input())
li = list(map(int,input().split()))[:n]
diff = 0
old = 0
for i in range(1,n):
diff = li[i] - li[i-1]
if diff>=old:
old = diff
else:
print(i)
break
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
li = list(map(int,input().split()))[:n]
diff = 0
old = 0
for i in range(1,n):
diff = li[i] - li[i-1]
if diff>=old:
old = diff
else:
print(i)
break
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,688,738,549 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | s = input()
def is_hello(s):
hello = "hello"
i = 0
for char in s:
if i < 5 and char == hello[i]:
i += 1
return i == 5
result = "YES" if is_hello(s) else "NO"
print(result)
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
def is_hello(s):
hello = "hello"
i = 0
for char in s:
if i < 5 and char == hello[i]:
i += 1
return i == 5
result = "YES" if is_hello(s) else "NO"
print(result)
``` | 3.977 |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,560,794,620 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 109 | 0 | n, k = map(int, input().split())
res = 1
while k % 2 == 0:
res += 1
k //= 2
print(res) | Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
n, k = map(int, input().split())
res = 1
while k % 2 == 0:
res += 1
k //= 2
print(res)
``` | 3 | |
877 | C | Slava and tanks | PROGRAMMING | 1,600 | [
"constructive algorithms"
] | null | null | Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the size of the map. | In the first line print *m* — the minimum number of bombs Slava needs to destroy all tanks.
In the second line print *m* integers *k*1,<=*k*2,<=...,<=*k**m*. The number *k**i* means that the *i*-th bomb should be dropped at the cell *k**i*.
If there are multiple answers, you can print any of them. | [
"2\n",
"3\n"
] | [
"3\n2 1 2 ",
"4\n2 1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "3\n2 1 2 "
},
{
"input": "3",
"output": "4\n2 1 3 2 "
},
{
"input": "4",
"output": "6\n2 4 1 3 2 4 "
},
{
"input": "6",
"output": "9\n2 4 6 1 3 5 2 4 6 "
},
{
"input": "10",
"output": "15\n2 4 6 8 10 1 3 5 7 9 2 4 6 8 10 "
},
{
... | 1,681,994,096 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
print(n + 1)
print(2, end=" ")
print(1, end=" ")
i = n
while True:
if i == 1:
break
print(i, end=" ")
i -= 1
| Title: Slava and tanks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there... | ```python
n = int(input())
print(n + 1)
print(2, end=" ")
print(1, end=" ")
i = n
while True:
if i == 1:
break
print(i, end=" ")
i -= 1
``` | 0 | |
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a w... | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "... | 1,604,736,405 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 307,200 | p, v = map(int, input().split())
WORDS_P = []
WORDS_V = []
WORDS = []
for i in range(p):
WORDS_P.append(input())
if WORDS_P[i] not in WORDS:
WORDS.append(WORDS_P[i])
for i in range(v):
WORDS_V.append(input())
if WORDS_V[i] not in WORDS:
WORDS.append(WORDS_V[i])
if WORDS % 2 =... | Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You... | ```python
p, v = map(int, input().split())
WORDS_P = []
WORDS_V = []
WORDS = []
for i in range(p):
WORDS_P.append(input())
if WORDS_P[i] not in WORDS:
WORDS.append(WORDS_P[i])
for i in range(v):
WORDS_V.append(input())
if WORDS_V[i] not in WORDS:
WORDS.append(WORDS_V[i])
if W... | -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,598,733,624 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 73 | 217 | 8,601,600 | n = int(input())
a = list(map(int, input().split()))
max, sum, find = 0, 0, 0
for i in range(n):
sum += a[i]
if sum % 2 == 0:
if sum > max:
max = sum
for i in range(n):
find = sum - a[i]
if find % 2 == 0:
if find > max:
max = find
print(max if... | 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())
a = list(map(int, input().split()))
max, sum, find = 0, 0, 0
for i in range(n):
sum += a[i]
if sum % 2 == 0:
if sum > max:
max = sum
for i in range(n):
find = sum - a[i]
if find % 2 == 0:
if find > max:
max = find
pr... | 0 | |
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno... | The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). | Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso... | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
... | 1,670,357,648 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 93 | 0 | # Author : Mohamed Yousef
# Date : 2022-12-06
import sys,math,bisect,collections,itertools,heapq
from collections import defaultdict,deque
n,m=map(int,sys.stdin.readline().split())
x=max(n,m)
y=min(n,m)
z=x-y
ans=1
if z>=10:
print(0)
else:
for i in range(y+1,x+1):
ans*=i
print... | Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like... | ```python
# Author : Mohamed Yousef
# Date : 2022-12-06
import sys,math,bisect,collections,itertools,heapq
from collections import defaultdict,deque
n,m=map(int,sys.stdin.readline().split())
x=max(n,m)
y=min(n,m)
z=x-y
ans=1
if z>=10:
print(0)
else:
for i in range(y+1,x+1):
ans*=i
... | 3 | |
552 | E | Vanya and Brackets | PROGRAMMING | 2,100 | [
"brute force",
"dp",
"expression parsing",
"greedy",
"implementation",
"strings"
] | null | null | Vanya is doing his maths homework. He has an expression of form , where *x*1,<=*x*2,<=...,<=*x**n* are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. | The first line contains expression *s* (1<=≤<=|*s*|<=≤<=5001, |*s*| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs <=+<= and <=*<=.
The number of signs <=*<= doesn't exceed 15. | In the first line print the maximum possible value of an expression. | [
"3+5*7+8*4\n",
"2+3*5\n",
"3*4*5\n"
] | [
"303\n",
"25\n",
"60\n"
] | Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.
Note to the second sample test. (2 + 3) * 5 = 25.
Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60). | 2,500 | [
{
"input": "3+5*7+8*4",
"output": "303"
},
{
"input": "2+3*5",
"output": "25"
},
{
"input": "3*4*5",
"output": "60"
},
{
"input": "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5",
"output": "152587890625"
},
{
"input": "2*2+2*2",
"output": "16"
},
{
"input": "1+1+1+1... | 1,615,116,016 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 77 | 0 | s = input().split('*')
ans = -1
for i in range(len(s)):
for j in range(1, len(s)):
copy = s[:i] + [str(eval('*'.join(s[i:i + j])))] + s[i + j:]
ans = max(ans, eval('*'.join(copy)))
print(ans) | Title: Vanya and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is doing his maths homework. He has an expression of form , where *x*1,<=*x*2,<=...,<=*x**n* are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one... | ```python
s = input().split('*')
ans = -1
for i in range(len(s)):
for j in range(1, len(s)):
copy = s[:i] + [str(eval('*'.join(s[i:i + j])))] + s[i + j:]
ans = max(ans, eval('*'.join(copy)))
print(ans)
``` | 0 | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,595,351,674 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 20,172,800 | n,m,d=list(map(int,input().split()))
a=[]
c=[]
for i in range(n):
b=list(map(int,input().split()))
for i in range(m):
t1=b[i]%d
if len(a)==0:
a.append(t1)
c.append(b[i]//d)
else:
if t1 not in a:
a.append(t1)
else:
c.append... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
n,m,d=list(map(int,input().split()))
a=[]
c=[]
for i in range(n):
b=list(map(int,input().split()))
for i in range(m):
t1=b[i]%d
if len(a)==0:
a.append(t1)
c.append(b[i]//d)
else:
if t1 not in a:
a.append(t1)
else:
... | 0 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,695,937,526 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x= int (input())
return ((((x//5)//4)//3)//2) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
x= int (input())
return ((((x//5)//4)//3)//2)
``` | -1 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,620,802,038 | 2,147,483,647 | PyPy 3 | OK | TESTS | 95 | 1,855 | 58,470,400 | import sys,math
from collections import defaultdict,Counter
def li(): return list(map(int,sys.stdin.readline().split()))
def ls(): return list(map(int,list(input())))
def la(): return list(input())
def ii(): return int(input())
n = ii()
d = defaultdict(lambda:0)
counter = 1
for _ in range(n):
a = input()... | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
import sys,math
from collections import defaultdict,Counter
def li(): return list(map(int,sys.stdin.readline().split()))
def ls(): return list(map(int,list(input())))
def la(): return list(input())
def ii(): return int(input())
n = ii()
d = defaultdict(lambda:0)
counter = 1
for _ in range(n):
a... | 3 | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,621,590,182 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | n = int(input())
left = 0
right = n - 1
diagonal = ""
other = ""
for i in range(n):
x = input()
diagonal += x[left] + x[right]
for j in range(n):
if j == left or j == right:
continue
else:
other += x[j]
left += 1
right -= 1
else:
if diagona... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
left = 0
right = n - 1
diagonal = ""
other = ""
for i in range(n):
x = input()
diagonal += x[left] + x[right]
for j in range(n):
if j == left or j == right:
continue
else:
other += x[j]
left += 1
right -= 1
else:
... | 0 | |
939 | C | Convenient For Everybody | PROGRAMMING | 1,600 | [
"binary search",
"two pointers"
] | null | null | In distant future on Earth day lasts for *n* hours and that's why there are *n* timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to *n* are used, i.e. there is no time "0 hours", instead of it "*n* hours" is used. When local time in the 1-st timezone is 1 ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of hours in day.
The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10<=000), where *a**i* is the number of people in the *i*-th timezone who want to participate in the contest.
The third li... | Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them. | [
"3\n1 2 3\n1 3\n",
"5\n1 2 3 4 1\n1 3\n"
] | [
"3\n",
"4\n"
] | In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will partici... | 1,500 | [
{
"input": "3\n1 2 3\n1 3",
"output": "3"
},
{
"input": "5\n1 2 3 4 1\n1 3",
"output": "4"
},
{
"input": "2\n5072 8422\n1 2",
"output": "2"
},
{
"input": "10\n7171 2280 6982 9126 9490 2598 569 6744 5754 1855\n7 9",
"output": "4"
},
{
"input": "10\n5827 8450 8288 5... | 1,660,014,010 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
s, f = list(map(int, input().split()))
num = 0
for i in range(s - 1, f - 1):
num += a[i]
amt = 0
cur = num
for t in range(n):
cur = cur - a[(s - 1 + t) % n] + a[(f - 1 + t) % n]
if (cur >= num):
num = cur
amt = t
print(n - t)
| Title: Convenient For Everybody
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In distant future on Earth day lasts for *n* hours and that's why there are *n* timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to *n* are used, ... | ```python
n = int(input())
a = list(map(int, input().split()))
s, f = list(map(int, input().split()))
num = 0
for i in range(s - 1, f - 1):
num += a[i]
amt = 0
cur = num
for t in range(n):
cur = cur - a[(s - 1 + t) % n] + a[(f - 1 + t) % n]
if (cur >= num):
num = cur
amt = t
print(n - t)
``` | 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,623,651,103 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 904 | 24,985,600 | n = int(input())
w = list(map(int, input().split()))
ent = input()
mp = {w[i]: i+1 for i in range(n)}
sorted(mp)
w.sort()
ptr = 0
stk = []
for i in range(2 * n):
if ent[i] == "0":
print(mp[w[ptr]], end=" ")
stk.append(mp[w[ptr]])
ptr += 1
else:
print(stk.pop(), end=... | 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())
w = list(map(int, input().split()))
ent = input()
mp = {w[i]: i+1 for i in range(n)}
sorted(mp)
w.sort()
ptr = 0
stk = []
for i in range(2 * n):
if ent[i] == "0":
print(mp[w[ptr]], end=" ")
stk.append(mp[w[ptr]])
ptr += 1
else:
print(stk.p... | 3 | |
554 | B | Ohana Cleans Up | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"strings"
] | null | null | Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square,... | The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100).
The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-t... | The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. | [
"4\n0101\n1000\n1111\n0101\n",
"3\n111\n111\n111\n"
] | [
"2\n",
"3\n"
] | In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything. | 500 | [
{
"input": "4\n0101\n1000\n1111\n0101",
"output": "2"
},
{
"input": "3\n111\n111\n111",
"output": "3"
},
{
"input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000",
"output": "9"
},
{
"input": "1\n1"... | 1,485,798,949 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 77 | 4,608,000 | import sys
digitInput = int((sys.stdin.readline()).strip("\n"))
digitList = []
maxCount = 0
for i in range(digitInput):
digitList.append(((sys.stdin.readline()).strip("\n")))
for n in set(digitList):
if digitList.count(n) > maxCount:
maxCount = digitList.count(n)
sys.stdout.write(str(maxCount))... | Title: Ohana Cleans Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very str... | ```python
import sys
digitInput = int((sys.stdin.readline()).strip("\n"))
digitList = []
maxCount = 0
for i in range(digitInput):
digitList.append(((sys.stdin.readline()).strip("\n")))
for n in set(digitList):
if digitList.count(n) > maxCount:
maxCount = digitList.count(n)
sys.stdout.write(str(... | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,539,840,925 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | string=input()
n=len(string)
m=0
a=[]
b=[]
c=[]
d=[]
for i in range(n):
if string[i]=='h':
a.append[i]
elif string[i]=='e':
b.append[i]
elif string[i]=='l':
c.append[i]
elif string[i]=='o':
d.append[i]
else:
pass
if a[0]<b[0]<c[0]<c[1]<d[0]:
... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
string=input()
n=len(string)
m=0
a=[]
b=[]
c=[]
d=[]
for i in range(n):
if string[i]=='h':
a.append[i]
elif string[i]=='e':
b.append[i]
elif string[i]=='l':
c.append[i]
elif string[i]=='o':
d.append[i]
else:
pass
if a[0]<b[0]<c[0]<c... | -1 |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,504,622,199 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 122 | 0 | n = int(input())
q = {}
for i in range(n):
name, score = input().strip().split()
score = int(score)
if name not in q:
q[name] = (0, i)
x = q[name]
if score > 0:
q[name] = (x[0] + score, i)
else:
q[name] = (x[0] + score, x[1])
q = list(q.items())
q.sor... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n = int(input())
q = {}
for i in range(n):
name, score = input().strip().split()
score = int(score)
if name not in q:
q[name] = (0, i)
x = q[name]
if score > 0:
q[name] = (x[0] + score, i)
else:
q[name] = (x[0] + score, x[1])
q = list(q.items()... | 0 |
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom... | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the secon... | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
... | 1,646,666,926 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | guests,guards = list(map(int,input().split()))
arrival = input()
inactive = [0]*26
active = [0]*26
flag = 0
for i in range(guests):
each = arrival[i]
inactive[ord(each)-65]=i
for i in range(guests):
each = arrival[i]
active[ord(each)-65]=1
if(sum(active)>guards):
flag =... | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here... | ```python
guests,guards = list(map(int,input().split()))
arrival = input()
inactive = [0]*26
active = [0]*26
flag = 0
for i in range(guests):
each = arrival[i]
inactive[ord(each)-65]=i
for i in range(guests):
each = arrival[i]
active[ord(each)-65]=1
if(sum(active)>guards):
... | -1 | |
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO"... | 1,610,465,976 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 92 | 307,200 | if __name__ == '__main__':
t = input()
s = "AHIMOTUWVXY"
ans = 1
for i in t:
if s.find(i) == -1:
ans = 0
break
print("YNEOS"[not (ans and t == t[::-1])::2]) | Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of ... | ```python
if __name__ == '__main__':
t = input()
s = "AHIMOTUWVXY"
ans = 1
for i in t:
if s.find(i) == -1:
ans = 0
break
print("YNEOS"[not (ans and t == t[::-1])::2])
``` | 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.