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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next... | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,607,346,107 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 | from sys import stdin, stdout
def find(node):
if dsu[node] == node:
return node
else:
dsu[node] = find(dsu[node])
return dsu[node]
n, m = map(int, stdin.readline().strip().split())
dsu = [ i for i in range(n+1)]
language = [0]*(m+1)
for j in range(n):
arr = list(map(int,... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
from sys import stdin, stdout
def find(node):
if dsu[node] == node:
return node
else:
dsu[node] = find(dsu[node])
return dsu[node]
n, m = map(int, stdin.readline().strip().split())
dsu = [ i for i in range(n+1)]
language = [0]*(m+1)
for j in range(n):
arr = lis... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 0 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,042,285 | 4,384 | Python 3 | OK | TESTS | 32 | 62 | 5,529,600 | import sys
a, b, c, d = map(int, input().split())
x, y, z = 2*a, 2*b, max(c, d)
if (a <= x <= 2 * a) and (b <= y <= 2*b) and (max(c, d) <= z <= min(2*c, 2*d)) and x > 2*d and y > 2*d:
print(x, y, z)
else:
print(-1)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can cli... | ```python
import sys
a, b, c, d = map(int, input().split())
x, y, z = 2*a, 2*b, max(c, d)
if (a <= x <= 2 * a) and (b <= y <= 2*b) and (max(c, d) <= z <= min(2*c, 2*d)) and x > 2*d and y > 2*d:
print(x, y, z)
else:
print(-1)
``` | 3 | |
859 | A | Declined Finalists | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ... | The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. | Print the minimum possible number of contestants that declined the invitation to compete onsite. | [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"5\n16 23 8 15 4\n",
"3\n14 15 92\n"
] | [
"3\n",
"0\n",
"67\n"
] | In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | 500 | [
{
"input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28",
"output": "3"
},
{
"input": "5\n16 23 8 15 4",
"output": "0"
},
{
"input": "3\n14 15 92",
"output": "67"
},
{
"input": "1\n1000000",
"output": "999975"
},
{
"input": "25\n1000000 ... | 1,591,091,151 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 108 | 0 | n=int(input())
l=[int(x) for x in input().split()]
m=max(l)
if(m<=25):
print("0")
else:
print(m-25)
| Title: Declined Finalists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t... | ```python
n=int(input())
l=[int(x) for x in input().split()]
m=max(l)
if(m<=25):
print("0")
else:
print(m-25)
``` | 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,691,246,473 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n, m, a = input().split()
a = int(a)
n = int(n)
m = int(m)
x = int(n/a)
if n % a != 0:
x += 1
y = int(m/a)
if m % a != 0:
y += 1
print(x*y)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = input().split()
a = int(a)
n = int(n)
m = int(m)
x = int(n/a)
if n % a != 0:
x += 1
y = int(m/a)
if m % a != 0:
y += 1
print(x*y)
``` | 3.977 |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,670,660,306 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 10,854,400 | from functools import cache
@cache
def f(n, b):
return (
int(n == 0 and b)
if n <= 0
else sum(f(n - i, b or i >= d) for i in range(1, k + 1)) % MOD
)
MOD = 1_000_000_007
n, k, d = map(int, input().split())
print(f(n, False))
| Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
from functools import cache
@cache
def f(n, b):
return (
int(n == 0 and b)
if n <= 0
else sum(f(n - i, b or i >= d) for i in range(1, k + 1)) % MOD
)
MOD = 1_000_000_007
n, k, d = map(int, input().split())
print(f(n, False))
``` | 3 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,693,480,593 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 186 | 0 | def Insertion_sort(tower,n):
for i in range(len(tower)):
key=tower[i]
j=i-1
while j>-1 and tower[j]>key:
tower[j+1]=tower[j]
j-=1
tower[j+1]=key
return tower
def Count_tower(tower,n):
tower_sorted=Insertion_sort(tower,n)
set_tower,c... | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
def Insertion_sort(tower,n):
for i in range(len(tower)):
key=tower[i]
j=i-1
while j>-1 and tower[j]>key:
tower[j+1]=tower[j]
j-=1
tower[j+1]=key
return tower
def Count_tower(tower,n):
tower_sorted=Insertion_sort(tower,n)
s... | 3.9535 |
27 | E | Number With The Given Amount Of Divisors | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"number theory"
] | E. Number With The Given Amount Of Divisors | 2 | 256 | Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000). | Output the smallest positive integer with exactly *n* divisors. | [
"4\n",
"6\n"
] | [
"6\n",
"12\n"
] | none | 2,500 | [
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "64"
},
{
"input": "8",
"output": "24"
},
{
"input": "9",
"output": "36"
},
{
"input": "10",
"output": "48"
},
{
"input": "15",
"output": "144"
},
{
"input": "20",
"output": "24... | 1,567,263,031 | 2,147,483,647 | PyPy 3 | OK | TESTS | 22 | 278 | 1,228,800 | n = int(input())
p = []
f = []
def prime(x):
for i in range(2,x):
if x % i == 0:
return False
return True
def factorize(x):
i = 2;
while(i*i <= x):
while(x % i == 0):
f.append(i)
x //= i
i = i+1
if(x > 1):
... | Title: Number With The Given Amount Of Divisors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
Input Specification:
The first line... | ```python
n = int(input())
p = []
f = []
def prime(x):
for i in range(2,x):
if x % i == 0:
return False
return True
def factorize(x):
i = 2;
while(i*i <= x):
while(x % i == 0):
f.append(i)
x //= i
i = i+1
if(x > 1... | 3.928211 |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,669,453,488 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 0 | from math import fabs
player1, player2 = (int(x) for x in input().split())
i = 1
pl1_win = 0
pl2_win = 0
draw = 0 # ничья
while i <= 6:
condition = fabs(i - player1) - fabs(i - player2)
if condition > 0:
pl2_win += 1
elif condition < 0:
pl1_win += 1
else:
draw += 1
i += 1
print(pl1_win, draw, ... | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
from math import fabs
player1, player2 = (int(x) for x in input().split())
i = 1
pl1_win = 0
pl2_win = 0
draw = 0 # ничья
while i <= 6:
condition = fabs(i - player1) - fabs(i - player2)
if condition > 0:
pl2_win += 1
elif condition < 0:
pl1_win += 1
else:
draw += 1
i += 1
print(pl1_w... | 3 | |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,548,335,386 | 2,147,483,647 | PyPy 3 | OK | TESTS | 13 | 280 | 204,800 | a=0
b=0
A=0
B=0
for i in range(int(input())):
t,x,y=map(int,input().split())
if t==1:
A+=10
a+=x
else:
B+=10
b+=x
if a>=A/2:
print("LIVE")
else:
print("DEAD")
if b>=B/2:
print("LIVE")
else:
print("DEAD") | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
a=0
b=0
A=0
B=0
for i in range(int(input())):
t,x,y=map(int,input().split())
if t==1:
A+=10
a+=x
else:
B+=10
b+=x
if a>=A/2:
print("LIVE")
else:
print("DEAD")
if b>=B/2:
print("LIVE")
else:
print("DEAD")
``` | 3 | |
954 | B | String Typing | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | You are given a string *s* consisting of *n* lowercase Latin letters. You have to type this string using your keyboard.
Initially, you have an empty string. Until you type the whole string, you may perform the following operation:
- add a character to the end of the string.
Besides, at most once you may perform one... | The first line of the input containing only one integer number *n* (1<=≤<=*n*<=≤<=100) — the length of the string you have to type. The second line containing the string *s* consisting of *n* lowercase Latin letters. | Print one integer number — the minimum number of operations you need to type the given string. | [
"7\nabcabca\n",
"8\nabcdefgh\n"
] | [
"5\n",
"8\n"
] | The first test described in the problem statement.
In the second test you can only type all the characters one by one. | 0 | [
{
"input": "7\nabcabca",
"output": "5"
},
{
"input": "8\nabcdefgh",
"output": "8"
},
{
"input": "100\nmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxcmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxc",
"output": "51"
},
{
"input": "99\ntrolnjmzxxrfxuexcqpjvefndwuxwsukxwmjh... | 1,656,266,644 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 28,364,800 | n = int(input())
s = input()
mx = 0
for j in s:
mx = max(mx ,s .count(j))
print(n - mx + 1)
| Title: String Typing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of *n* lowercase Latin letters. You have to type this string using your keyboard.
Initially, you have an empty string. Until you type the whole string, you may perform the following ... | ```python
n = int(input())
s = input()
mx = 0
for j in s:
mx = max(mx ,s .count(j))
print(n - mx + 1)
``` | 0 | |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,412,703,492 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | import sys
import math
n, m = [int(x) for x in (sys.stdin.readline()).split()]
ss = m % int(((1 + n) * n) / 2)
d = int(math.sqrt(1 + (ss * 2 - 2) * 4))
sq = 0
if((1 + d) / 2 != 1):
sq = (1 + d) / 2 - 1
else:
sq = 1
result = int(ss - ((sq + 1) * sq / 2))
print(result)
| Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
import sys
import math
n, m = [int(x) for x in (sys.stdin.readline()).split()]
ss = m % int(((1 + n) * n) / 2)
d = int(math.sqrt(1 + (ss * 2 - 2) * 4))
sq = 0
if((1 + d) / 2 != 1):
sq = (1 + d) / 2 - 1
else:
sq = 1
result = int(ss - ((sq + 1) * sq / 2))
print(result)
``` | 0 |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th... | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5... | 1,668,867,244 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | x,y,a,b=map(int,input().split())
print(b//(x*y)-a//(x*y)+(a%(x*y)==0)) | Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub ... | ```python
x,y,a,b=map(int,input().split())
print(b//(x*y)-a//(x*y)+(a%(x*y)==0))
``` | 0 | |
1,010 | A | Fly | PROGRAMMING | 1,500 | [
"binary search",
"math"
] | null | null | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists ... | The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted... | If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct... | [
"2\n12\n11 8\n7 5\n",
"3\n1\n1 4 1\n2 5 3\n",
"6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n"
] | [
"10.0000000000\n",
"-1\n",
"85.4800000000\n"
] | Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fu... | 500 | [
{
"input": "2\n12\n11 8\n7 5",
"output": "10.0000000000"
},
{
"input": "3\n1\n1 4 1\n2 5 3",
"output": "-1"
},
{
"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3",
"output": "85.4800000000"
},
{
"input": "3\n3\n1 2 1\n2 2 2",
"output": "-1"
},
{
"input": "4\n4\n2 3 2 2\n2... | 1,588,266,503 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | t=int(input())
a=[]
for i in range(0,t):
a_i=int(input())
a.append(a_i)
import math
for i in a:
n=int(math.log(i,10))+1
l=math.log(n,10)
while l<=n*math.log(i,10):
n=n+1
l=l+math.log(n,10)
print(n)
| Title: Fly
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will ... | ```python
t=int(input())
a=[]
for i in range(0,t):
a_i=int(input())
a.append(a_i)
import math
for i in a:
n=int(math.log(i,10))+1
l=math.log(n,10)
while l<=n*math.log(i,10):
n=n+1
l=l+math.log(n,10)
print(n)
``` | -1 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,647,108,303 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | def solve():
n = int(input())
if n==1:
print(1)
elif n==2:
print(2)
else:
a = [[1]*n]
for i in range(n-1):
t = [1]
for j in range(n-1):
temp = a[i][j+1]+t[j]
t.append(temp)
a.append(t)
print(a[n-1... | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
def solve():
n = int(input())
if n==1:
print(1)
elif n==2:
print(2)
else:
a = [[1]*n]
for i in range(n-1):
t = [1]
for j in range(n-1):
temp = a[i][j+1]+t[j]
t.append(temp)
a.append(t)
p... | 3 | |
48 | A | Rock-paper-scissors | PROGRAMMING | 900 | [
"implementation",
"schedules"
] | A. Rock-paper-scissors | 2 | 256 | Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio... | The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. | Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". | [
"rock\nrock\nrock\n",
"paper\nrock\nrock\n",
"scissors\nrock\nrock\n",
"scissors\npaper\nrock\n"
] | [
"?\n",
"F\n",
"?\n",
"?\n"
] | none | 0 | [
{
"input": "rock\nrock\nrock",
"output": "?"
},
{
"input": "paper\nrock\nrock",
"output": "F"
},
{
"input": "scissors\nrock\nrock",
"output": "?"
},
{
"input": "scissors\npaper\nrock",
"output": "?"
},
{
"input": "paper\npaper\nrock",
"output": "?"
},
{
... | 1,635,611,651 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 92 | 17,715,200 | s1 = input()
s2 = input()
s3 = input()
moves = [s1, s2, s3]
names = ['F', 'M', 'S']
set1 = set(moves)
if len(set1) == 1 or len(set1) == 3:
print('?')
else:
if 'paper' in set1 and 'scissors' in set1:
if moves.count('paper') == 2:
print(names[moves.index('scissors')])
elif ... | Title: Rock-paper-scissors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ... | ```python
s1 = input()
s2 = input()
s3 = input()
moves = [s1, s2, s3]
names = ['F', 'M', 'S']
set1 = set(moves)
if len(set1) == 1 or len(set1) == 3:
print('?')
else:
if 'paper' in set1 and 'scissors' in set1:
if moves.count('paper') == 2:
print(names[moves.index('scissors')])
... | 0 |
197 | A | Plate Game | PROGRAMMING | 1,600 | [
"constructive algorithms",
"games",
"math"
] | null | null | You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located with... | A single line contains three space-separated integers *a*, *b*, *r* (1<=≤<=*a*,<=*b*,<=*r*<=≤<=100) — the table sides and the plates' radius, correspondingly. | If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes). | [
"5 5 2\n",
"6 7 4\n"
] | [
"First\n",
"Second\n"
] | In the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses.
In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move. | 1,000 | [
{
"input": "5 5 2",
"output": "First"
},
{
"input": "6 7 4",
"output": "Second"
},
{
"input": "100 100 1",
"output": "First"
},
{
"input": "1 1 100",
"output": "Second"
},
{
"input": "13 7 3",
"output": "First"
},
{
"input": "23 7 3",
"output": "Fi... | 1,698,030,868 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | l, w, r = map(int, input().split())
area_l = 2 * r
area_w = 2 * r
if l > 2 * w - 1:
area_w *= 2
area_w -= 0.001
if l > 2 * l - 1:
area_l *= 2
area_l -= 0.001
mn = min(l, w)
base = area_w if mn == w else area_l
tot = mn // base
print("First" if tot % 2 == 1 else "Second")
| Title: Plate Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie o... | ```python
l, w, r = map(int, input().split())
area_l = 2 * r
area_w = 2 * r
if l > 2 * w - 1:
area_w *= 2
area_w -= 0.001
if l > 2 * l - 1:
area_l *= 2
area_l -= 0.001
mn = min(l, w)
base = area_w if mn == w else area_l
tot = mn // base
print("First" if tot % 2 == 1 else "Second")
... | 0 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,695,241,334 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | n = int(input())
nums = list(map(int, input().split()))
l , r = 0 , len(nums)-1
S_score , D_score = 0 , 0
s , d = 0 , 0
while l<r:
if s==d:
if nums[l] > nums[r]:
S_score += nums[l]
l+=1
else:
S_score += nums[r]
r-=1
s+=1
if d<s:
if ... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n = int(input())
nums = list(map(int, input().split()))
l , r = 0 , len(nums)-1
S_score , D_score = 0 , 0
s , d = 0 , 0
while l<r:
if s==d:
if nums[l] > nums[r]:
S_score += nums[l]
l+=1
else:
S_score += nums[r]
r-=1
s+=1
if d<s:
... | 3 | |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ... | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input":... | 1,678,974,056 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 62 | 1,843,200 | # Wadea #
n,m,colour = input().split()
n,m = int(n),int(m)
arr = []
r = set({".",colour})
for i in range(n):
s = input()
arr.append(s)
for i in range(len(arr)):
if colour in arr[i]:
for j in range(m):
if arr[i][j] == colour:
if i != 0 and arr[i-1][j] not i... | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
# Wadea #
n,m,colour = input().split()
n,m = int(n),int(m)
arr = []
r = set({".",colour})
for i in range(n):
s = input()
arr.append(s)
for i in range(len(arr)):
if colour in arr[i]:
for j in range(m):
if arr[i][j] == colour:
if i != 0 and arr[i-1... | 3.970767 |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
}... | 1,557,849,430 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 343 | 2,252,800 | def main():
n = int(input())
a = [0 for _ in range(n)]
p = [0 for _ in range(n)]
for i in range(n):
[ai, pi] = [int(_) for _ in input().split()]
a[i] = ai
p[i] = pi
sum_money = 0
bought = [False for _ in range(n)]
for i in range(n):
if not bought[i]:
... | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her ... | ```python
def main():
n = int(input())
a = [0 for _ in range(n)]
p = [0 for _ in range(n)]
for i in range(n):
[ai, pi] = [int(_) for _ in input().split()]
a[i] = ai
p[i] = pi
sum_money = 0
bought = [False for _ in range(n)]
for i in range(n):
if not bought[... | 3 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,528,655,608 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 186 | 0 | hold,total=input().split()
hold=int(hold)
total=int(total)
result=0
dict={}
dict2={}
for i in range(total):
a,b=input().split()
a=int(a)
b=int(b)
dict[b]=a
dict2[a]=b
for i in range(total):
if dict.get(max(dict))>=hold:
result+=(max(dict)*hold)
break
else:
... | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
hold,total=input().split()
hold=int(hold)
total=int(total)
result=0
dict={}
dict2={}
for i in range(total):
a,b=input().split()
a=int(a)
b=int(b)
dict[b]=a
dict2[a]=b
for i in range(total):
if dict.get(max(dict))>=hold:
result+=(max(dict)*hold)
break
... | -1 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,586,864,075 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | S = str(input())
if sum(map(str.islower, S)) >= len(S)/2:
print(S.lower())
else:
print(S.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
S = str(input())
if sum(map(str.islower, S)) >= len(S)/2:
print(S.lower())
else:
print(S.upper())
``` | 3.9455 |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,589,452,117 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 6,656,000 | n=(int(input()))
a=list(map(int,input().split()))
b=sorted(set(a))
for i in range(1,max(b)):
if i!=b[i-1]:
print(i)
break | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
n=(int(input()))
a=list(map(int,input().split()))
b=sorted(set(a))
for i in range(1,max(b)):
if i!=b[i-1]:
print(i)
break
``` | 0 |
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,557,480,896 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 187 | 8,499,200 | a=int(input())
num_list=[int(i) for i in list(input('').split(' '))]
odd=list(filter(lambda x: x%2!=0,num_list))
odd.sort(reverse=True)
if len(odd)%2==0:
print(sum(num_list))
else:
num_list.remove(odd[-1])
print(sum(num_list))
| 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
a=int(input())
num_list=[int(i) for i in list(input('').split(' '))]
odd=list(filter(lambda x: x%2!=0,num_list))
odd.sort(reverse=True)
if len(odd)%2==0:
print(sum(num_list))
else:
num_list.remove(odd[-1])
print(sum(num_list))
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,691,220,474 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | s=input()
t=input()
s1=str(s).split()
t1=str(t).split()
for i in range(len(s1)):
if s1[i]==t1[len(s1)-i-1]:
print("yes")
else:
print("no") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s=input()
t=input()
s1=str(s).split()
t1=str(t).split()
for i in range(len(s1)):
if s1[i]==t1[len(s1)-i-1]:
print("yes")
else:
print("no")
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines co... | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of t... | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 0 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#... | 1,600,937,560 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 307,200 | import sys
input = sys.stdin.readline
n,m,k=[int(x) for x in input().split()]
maze=[]
for z in range(n):
arr=list(input())
maze.append(arr)
s,cnt,first=0,0,[]
for i in range(n):
for j in range(m):
if maze[i][j]==".":
s+=1
if len(first)==0:
first.... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze w... | ```python
import sys
input = sys.stdin.readline
n,m,k=[int(x) for x in input().split()]
maze=[]
for z in range(n):
arr=list(input())
maze.append(arr)
s,cnt,first=0,0,[]
for i in range(n):
for j in range(m):
if maze[i][j]==".":
s+=1
if len(first)==0:
... | 0 | |
424 | C | Magic Formulas | PROGRAMMING | 1,600 | [
"math"
] | null | null | People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas:
Here, "mod" means the operation of taking the residue after dividing.
The expression means applying ... | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=106). The next line contains *n* integers: *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=2·109). | The only line of output should contain a single integer — the value of *Q*. | [
"3\n1 2 3\n"
] | [
"3\n"
] | none | 1,500 | [
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n65535 0",
"output": "65534"
},
{
"input": "10\n1356106972 165139648 978829595 410669403 873711167 287346624 117863440 228957745 835903650 1575323015",
"output": "948506286"
},
{... | 1,679,213,927 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
lst=list(map(int,input().split()))
s=[1 for i in range(n+1)]
for i in range(n):
s[i+1]^=(i+1)^s[i]
ans=0
print(s)
for i in range(1,n+1):
p=n//i
q=n%i
if p%2==0:
ans=ans^s[q]
else:
ans=ans^s[i-1]^s[q-1]
for i in lst:
ans^=i
print(ans) | Title: Magic Formulas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas:
He... | ```python
n=int(input())
lst=list(map(int,input().split()))
s=[1 for i in range(n+1)]
for i in range(n):
s[i+1]^=(i+1)^s[i]
ans=0
print(s)
for i in range(1,n+1):
p=n//i
q=n%i
if p%2==0:
ans=ans^s[q]
else:
ans=ans^s[i-1]^s[q-1]
for i in lst:
ans^=i
print(ans)
``` | 0 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,618,600,928 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 77 | 0 | # Collaborated with Rudransh Singh
inp = list(input())
check = ['a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9']
count = 0
for i in inp:
if i in check:
count += 1
print(count)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
# Collaborated with Rudransh Singh
inp = list(input())
check = ['a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9']
count = 0
for i in inp:
if i in check:
count += 1
print(count)
``` | 3 | |
272 | C | Dima and Staircase | PROGRAMMING | 1,500 | [
"data structures",
"implementation"
] | null | null | Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1).
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the numbe... | Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I... | [
"5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n",
"3\n1 2 3\n2\n1 1\n3 1\n",
"1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n"
] | [
"1\n3\n4\n6\n",
"1\n3\n",
"1\n3\n13\n23\n33\n"
] | The first sample are shown on the picture. | 1,500 | [
{
"input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3",
"output": "1\n3\n4\n6"
},
{
"input": "3\n1 2 3\n2\n1 1\n3 1",
"output": "1\n3"
},
{
"input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10",
"output": "1\n3\n13\n23\n33"
},
{
"input": "8\n6 10 18 23 30 31 31 33\n1\n5 3",
"output":... | 1,686,319,235 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 31 | 2,000 | 18,022,400 | def main():
n = int(input())
a = list(map(int, input().split()))
pref = [a[0]]
for i in range(1, n):
pref.append(max(pref[-1], a[i]))
m = int(input())
for i in range(m):
w, h = list(map(int, input().split()))
if i == 0:
print(pref[w-1])
... | Title: Dima and Staircase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the st... | ```python
def main():
n = int(input())
a = list(map(int, input().split()))
pref = [a[0]]
for i in range(1, n):
pref.append(max(pref[-1], a[i]))
m = int(input())
for i in range(m):
w, h = list(map(int, input().split()))
if i == 0:
print(pref[w-1])
... | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,640,054,959 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | s, t = input(), input()
if (len(s) != len(t)):
print("NO")
quit()
for index in range(len(s)):
if s[index] != t[len(s) - index - 1]:
print("NO")
quit()
print("YES") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s, t = input(), input()
if (len(s) != len(t)):
print("NO")
quit()
for index in range(len(s)):
if s[index] != t[len(s) - index - 1]:
print("NO")
quit()
print("YES")
``` | 3.969 |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,671,308,169 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 62 | 0 | n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
k = 0
i = 0
summa = 0
while a[i] < 0 and k < m and i < n:
summa += abs(a[i])
k += 1
i += 1
print(summa) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
k = 0
i = 0
summa = 0
while a[i] < 0 and k < m and i < n:
summa += abs(a[i])
k += 1
i += 1
print(summa)
``` | -1 |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,527,156,153 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 654 | 0 | n = input().split()
d = int(n[1])
n = int(n[0])
res = 0
a = list(map(int,input().split()))
for i in range(n):
for j in range(i+1,n):
if abs(a[i]-a[j]) <= d:
res +=1
print(res*2)
| Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n = input().split()
d = int(n[1])
n = int(n[0])
res = 0
a = list(map(int,input().split()))
for i in range(n):
for j in range(i+1,n):
if abs(a[i]-a[j]) <= d:
res +=1
print(res*2)
``` | 3.8365 |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,678,285,330 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 16,588,800 | length = int(input())
numbers = tuple(int(i) for i in input().split())
maximum = max(numbers)
minimum = min(numbers)
if numbers.count(maximum) == length:
print(maximum - minimum, numbers.count(maximum) - 1)
else:
print(maximum - minimum, numbers.count(maximum) * numbers.count(minimum)) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
length = int(input())
numbers = tuple(int(i) for i in input().split())
maximum = max(numbers)
minimum = min(numbers)
if numbers.count(maximum) == length:
print(maximum - minimum, numbers.count(maximum) - 1)
else:
print(maximum - minimum, numbers.count(maximum) * numbers.count(minimum))
``` | 0 | |
665 | D | Simple Subset | PROGRAMMING | 1,800 | [
"constructive algorithms",
"greedy",
"number theory"
] | null | null | A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=<<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime.
You are given an array *a* with *n* positive integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (not necessary distinct). You wan... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of integers in the array *a*.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. | On the first line print integer *m* — the maximum possible size of simple subset of *a*.
On the second line print *m* integers *b**l* — the elements of the simple subset of the array *a* with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in an... | [
"2\n2 3\n",
"2\n2 2\n",
"3\n2 1 1\n",
"2\n83 14\n"
] | [
"2\n3 2\n",
"1\n2\n",
"3\n1 1 2\n",
"2\n14 83\n"
] | none | 0 | [
{
"input": "2\n2 3",
"output": "2\n3 2"
},
{
"input": "2\n2 2",
"output": "1\n2"
},
{
"input": "3\n2 1 1",
"output": "3\n1 1 2"
},
{
"input": "2\n83 14",
"output": "2\n14 83"
},
{
"input": "10\n10 10 1 2 3 3 1 2 1 5",
"output": "4\n1 1 10 1"
},
{
"inpu... | 1,688,856,491 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 561 | 30,310,400 | import sys
readline=sys.stdin.readline
class Prime:
def __init__(self,N):
assert N<=10**8
self.smallest_prime_factor=[None]*(N+1)
for i in range(2,N+1,2):
self.smallest_prime_factor[i]=2
n=int(N**.5)+1
for p in range(3,n,2):
if self.smalles... | Title: Simple Subset
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=<<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime.
You are given an arra... | ```python
import sys
readline=sys.stdin.readline
class Prime:
def __init__(self,N):
assert N<=10**8
self.smallest_prime_factor=[None]*(N+1)
for i in range(2,N+1,2):
self.smallest_prime_factor[i]=2
n=int(N**.5)+1
for p in range(3,n,2):
if se... | 0 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,573,886,745 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 307,200 | def zero(num):
ret = 0
for char in str(num)[::-1]:
if char != '0':
break
ret += 1
return ret
n = int(input())
m = []
for i in range(n):
m.append(list(map(int, input().split())))
dp = []
for i in range(n):
dp.append([])
for j in range(n):
dp[... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
def zero(num):
ret = 0
for char in str(num)[::-1]:
if char != '0':
break
ret += 1
return ret
n = int(input())
m = []
for i in range(n):
m.append(list(map(int, input().split())))
dp = []
for i in range(n):
dp.append([])
for j in range(n):
... | 0 |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,648,628,001 | 801 | Python 3 | OK | TESTS | 38 | 92 | 0 | import sys
n, k = map(int, input().strip().split())
marks = [2] * n
if n == 1 and k > 2:
print(0)
sys.exit(0)
for i in range(n):
tot_marks = sum(marks)
if k == tot_marks:
break
else:
marks[i] += 1
print(marks.count(2)) | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
import sys
n, k = map(int, input().strip().split())
marks = [2] * n
if n == 1 and k > 2:
print(0)
sys.exit(0)
for i in range(n):
tot_marks = sum(marks)
if k == tot_marks:
break
else:
marks[i] += 1
print(marks.count(2))
``` | 3 | |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,695,314,094 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | u=input()
v=input()
u=u.lower()
v=v.lower()
cnt=0
if u>v:
print(1)
elif u<v:
print(-1)
elif u==v:
print(0) | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
u=input()
v=input()
u=u.lower()
v=v.lower()
cnt=0
if u>v:
print(1)
elif u<v:
print(-1)
elif u==v:
print(0)
``` | 3.977 |
975 | A | Aramic script | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$... | The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | 500 | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
... | 1,680,705,633 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | n =int(input())
r = map(str , input().split())
l = []
for i in r :
if sorted(i) not in l :
l.append(sorted(i))
count = 0
for i in l :
if len(set(i)) == len(i) :
count += 1
print(count) | Title: Aramic script
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the ... | ```python
n =int(input())
r = map(str , input().split())
l = []
for i in r :
if sorted(i) not in l :
l.append(sorted(i))
count = 0
for i in l :
if len(set(i)) == len(i) :
count += 1
print(count)
``` | 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,625,554,719 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | m, n = map(int, input().split())
m, n = max(m, n), min(m, n)
r = m // 2 * n
print(r) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m, n = map(int, input().split())
m, n = max(m, n), min(m, n)
r = m // 2 * n
print(r)
``` | 0 |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100... | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,642,228,004 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 62 | 0 | if __name__ == "__main__":
args = list(map(int, input().strip().split()))
rates = list(map(int, input().strip().split()))
maxd = 0
for i in range(args[0]-1):
d = rates[i] - rates[i+1]
if d >= maxd:
maxd = d
print(str(max([0, maxd - args[1]])))
... | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
if __name__ == "__main__":
args = list(map(int, input().strip().split()))
rates = list(map(int, input().strip().split()))
maxd = 0
for i in range(args[0]-1):
d = rates[i] - rates[i+1]
if d >= maxd:
maxd = d
print(str(max([0, maxd - args[1]])))
... | 3 | |
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ... | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 21474836... | 1,622,137,285 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 32 | 93 | 0 | nP, k = [int(x) for x in input().split()]
if k >= nP:
print(nP)
else:
Power = [int(x) for x in input().split()]
vic = 0
pri = 0
for x in Power:
if x == nP:
print(nP)
break
elif pri > x:
vic += 1
if vic == k:
... | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o... | ```python
nP, k = [int(x) for x in input().split()]
if k >= nP:
print(nP)
else:
Power = [int(x) for x in input().split()]
vic = 0
pri = 0
for x in Power:
if x == nP:
print(nP)
break
elif pri > x:
vic += 1
if vic == k:
... | 0 | |
846 | C | Four Segments | PROGRAMMING | 1,800 | [
"brute force",
"data structures",
"dp"
] | null | null | You are given an array of *n* integer numbers. Let *sum*(*l*,<=*r*) be the sum of all numbers on positions from *l* to *r* non-inclusive (*l*-th element is counted, *r*-th element is not counted). For indices *l* and *r* holds 0<=≤<=*l*<=≤<=*r*<=≤<=*n*. Indices in array are numbered from 0.
For example, if *a*<==<=[<... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=5000).
The second line contains *n* numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=109<=≤<=*a**i*<=≤<=109). | Choose three indices so that the value of *res* is maximal. If there are multiple answers, print any of them. | [
"3\n-1 2 3\n",
"4\n0 0 -1 0\n",
"1\n10000\n"
] | [
"0 1 3\n",
"0 0 0\n",
"1 1 1\n"
] | none | 0 | [
{
"input": "3\n-1 2 3",
"output": "0 1 3"
},
{
"input": "4\n0 0 -1 0",
"output": "0 0 0"
},
{
"input": "1\n10000",
"output": "0 0 1"
},
{
"input": "1\n-1",
"output": "0 0 0"
},
{
"input": "1\n0",
"output": "0 0 0"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0... | 1,504,630,705 | 6,805 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 109 | 819,200 |
INF = 10 ** 9 + 7
def find(cumsums, start, end): # [start, end)
# import pdb; pdb.set_trace()
ret = 0
ret_idx = start
for i in range(start, end):
if (cumsums[i] - cumsums[start]) - (cumsums[end-1] - cumsums[i]) > ret:
ret = (cumsums[i] - cumsums[start]) - (cumsums[end-1] - cumsu... | Title: Four Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers. Let *sum*(*l*,<=*r*) be the sum of all numbers on positions from *l* to *r* non-inclusive (*l*-th element is counted, *r*-th element is not counted). For indices *l* and *r* ... | ```python
INF = 10 ** 9 + 7
def find(cumsums, start, end): # [start, end)
# import pdb; pdb.set_trace()
ret = 0
ret_idx = start
for i in range(start, end):
if (cumsums[i] - cumsums[start]) - (cumsums[end-1] - cumsums[i]) > ret:
ret = (cumsums[i] - cumsums[start]) - (cumsums[end-... | 0 | |
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab... | 1,628,955,334 | 2,134 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 92 | 20,480,000 | from collections import defaultdict
import sys
input = sys.stdin.readline
n = int(input())
d = defaultdict(lambda : [])
c = defaultdict(lambda : 0)
for _ in range(n):
a = list(input().rstrip())
a0 = a[0]
d[a0].append(("".join(a) + a[-1] * (51 - len(a)), len(a)))
ans = []
for i in range(97, 123)... | Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list ... | ```python
from collections import defaultdict
import sys
input = sys.stdin.readline
n = int(input())
d = defaultdict(lambda : [])
c = defaultdict(lambda : 0)
for _ in range(n):
a = list(input().rstrip())
a0 = a[0]
d[a0].append(("".join(a) + a[-1] * (51 - len(a)), len(a)))
ans = []
for i in rang... | 0 | |
538 | D | Weird Chess | PROGRAMMING | 1,800 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size *n*<=×<=*n* cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=50).
The next *n* lines contain *n* characters each describing the position offered by Igor. The *j*-th character of the *i*-th string can have the following values:
- o — in this case the field (*i*,<=*j*) is occupied by a piece and the field may or may not... | If there is a valid set of moves, in the first line print a single word 'YES' (without the quotes). Next, print the description of the set of moves of a piece in the form of a (2*n*<=-<=1)<=×<=(2*n*<=-<=1) board, the center of the board has a piece and symbols 'x' mark cells that are attacked by it, in a format similar... | [
"5\noxxxx\nx...x\nx...x\nx...x\nxxxxo\n",
"6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.\n",
"3\no.x\noxx\no.x\n"
] | [
"YES\n....x....\n....x....\n....x....\n....x....\nxxxxoxxxx\n....x....\n....x....\n....x....\n....x....\n",
"YES\n...........\n...........\n...........\n....x.x....\n...x...x...\n.....o.....\n...x...x...\n....x.x....\n...........\n...........\n...........\n",
"NO\n"
] | In the first sample test the piece is a usual chess rook, and in the second sample test the piece is a usual chess knight. | 1,500 | [
{
"input": "5\noxxxx\nx...x\nx...x\nx...x\nxxxxo",
"output": "YES\nxxxxxxxxx\nx...xxxxx\nx...xxxxx\nx...xxxxx\nxxxxoxxxx\nxxxxx...x\nxxxxx...x\nxxxxx...x\nxxxxxxxxx"
},
{
"input": "6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.",
"output": "YES\nxxxxxxxxxxx\nxxxxxxxxxxx\nxx.x.x..xxx\nxxx.x.x.... | 1,453,488,993 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 22 | 2,000 | 307,200 | n = int(input())
grid = [ input().strip() for r in range(n) ]
pieces = []
for r in range(n):
for c in range(n):
if grid[r][c] == 'o':
pieces.append((r, c))
explained = [ [ False for c in range(n) ] for r in range(n) ]
stamp = [ [ '.' for c in range(2 * n - 1) ] for r in range(2 * n - 1) ]
for dr... | Title: Weird Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size *n*<=×<=*n* cells.... | ```python
n = int(input())
grid = [ input().strip() for r in range(n) ]
pieces = []
for r in range(n):
for c in range(n):
if grid[r][c] == 'o':
pieces.append((r, c))
explained = [ [ False for c in range(n) ] for r in range(n) ]
stamp = [ [ '.' for c in range(2 * n - 1) ] for r in range(2 * n - 1... | 0 | |
766 | B | Mahmoud and a Triangle | PROGRAMMING | 1,000 | [
"constructive algorithms",
"geometry",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments... | The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. | In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. | [
"5\n1 5 3 2 4\n",
"3\n4 1 2\n"
] | [
"YES\n",
"NO\n"
] | For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | 1,000 | [
{
"input": "5\n1 5 3 2 4",
"output": "YES"
},
{
"input": "3\n4 1 2",
"output": "NO"
},
{
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576",
"output": "NO"
},... | 1,677,585,941 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 108 | 8,089,600 | n = int(input())
a = sorted(map(int, input().split()))
def check_triangle(lst):
if sum(lst) - max(lst) > max(lst):
return True
return False
for i in range(2, n):
l, r = 0, i - 1
while l < r:
if a[l] + a[r] > a[i] and check_triangle([a[l], a[r], a[i]]):
print("YE... | Title: Mahmoud and a Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he ca... | ```python
n = int(input())
a = sorted(map(int, input().split()))
def check_triangle(lst):
if sum(lst) - max(lst) > max(lst):
return True
return False
for i in range(2, n):
l, r = 0, i - 1
while l < r:
if a[l] + a[r] > a[i] and check_triangle([a[l], a[r], a[i]]):
... | 3 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,625,566,800 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 77 | 0 | [a,b,n]=list(map(int,input().split()))
flag=0
a*=10
a+=9
if(0<=a%b<=9):
a-=a%b
n-=1
print(str(a)+'0'*(n))
else:
print(-1) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
[a,b,n]=list(map(int,input().split()))
flag=0
a*=10
a+=9
if(0<=a%b<=9):
a-=a%b
n-=1
print(str(a)+'0'*(n))
else:
print(-1)
``` | 3 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,694,669,418 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | string = input().split(' ')
number = int(string[0])
place = int(string[1])
if number%2 == 0:
if place <number/2:
print(2*place-1)
else:
print(2*(place-number/2))
else:
if place < (number+1)/2:
print(2*place-1)
else:
print(int(2*(place-(number+1)/2))) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
string = input().split(' ')
number = int(string[0])
place = int(string[1])
if number%2 == 0:
if place <number/2:
print(2*place-1)
else:
print(2*(place-number/2))
else:
if place < (number+1)/2:
print(2*place-1)
else:
print(int(2*(place-(number+1)/2)))... | 0 | |
36 | A | Extra-terrestrial Intelligence | PROGRAMMING | 1,300 | [
"implementation"
] | A. Extra-terrestrial Intelligence | 2 | 64 | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | [
"8\n00111000\n",
"7\n1001011\n",
"7\n1010100\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "8\n00111000",
"output": "YES"
},
{
"input": "7\n1001011",
"output": "NO"
},
{
"input": "7\n1010100",
"output": "YES"
},
{
"input": "5\n10101",
"output": "YES"
},
{
"input": "3\n111",
"output": "YES"
},
{
"input": "10\n0011111011",
"outp... | 1,618,983,284 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 154 | 0 | def main():
f=open('input.txt','r')
d=f.read()
k=d.split('\n')
n=int(k[0])
l=list(map(int,k[1]))
g=open('output.txt','w')
k=[]
for i in range(n):
if l[i]==1:
k+=[i]
h=[]
for i in range(len(k)-1):
h+=[k[i+1]-k[i]]
h.sort()
verdict=0
if min(h)==1:
if max(h)==1:
verdict=1
elif... | Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* da... | ```python
def main():
f=open('input.txt','r')
d=f.read()
k=d.split('\n')
n=int(k[0])
l=list(map(int,k[1]))
g=open('output.txt','w')
k=[]
for i in range(n):
if l[i]==1:
k+=[i]
h=[]
for i in range(len(k)-1):
h+=[k[i+1]-k[i]]
h.sort()
verdict=0
if min(h)==1:
if max(h)==1:
verdict... | 0 |
264 | A | Escape from Stones | PROGRAMMING | 1,200 | [
"constructive algorithms",
"data structures",
"implementation",
"two pointers"
] | null | null | Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order.
The stones always fall to the center of Liss's ... | The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r". | Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left. | [
"llrlr\n",
"rrlll\n",
"lrlrr\n"
] | [
"3\n5\n4\n2\n1\n",
"1\n2\n5\n4\n3\n",
"2\n4\n5\n3\n1\n"
] | In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1. | 500 | [
{
"input": "llrlr",
"output": "3\n5\n4\n2\n1"
},
{
"input": "rrlll",
"output": "1\n2\n5\n4\n3"
},
{
"input": "lrlrr",
"output": "2\n4\n5\n3\n1"
},
{
"input": "lllrlrllrl",
"output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1"
},
{
"input": "llrlrrrlrr",
"output": "3\n5\n6... | 1,616,786,206 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 61 | 0 | # https://codeforces.com/problemset/problem/264/A
s = input()
d = []
i = 0
j = 1
for k in range(len(s)):
mid = (i + j) / 2
d.append([mid, k + 1])
if s[k] == "l":
j = mid
else:
i = mid
for i in sorted(d, key=lambda x: x[0]):
print(i[1])
| Title: Escape from Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the ... | ```python
# https://codeforces.com/problemset/problem/264/A
s = input()
d = []
i = 0
j = 1
for k in range(len(s)):
mid = (i + j) / 2
d.append([mid, k + 1])
if s[k] == "l":
j = mid
else:
i = mid
for i in sorted(d, key=lambda x: x[0]):
print(i[1])
``` | 0 | |
198 | B | Jumping on Walls | PROGRAMMING | 1,400 | [
"shortest paths"
] | null | null | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. ... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105) — the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall — a string with the length of *n* characters. The *i*-th character represents the state of the *i*-th wall are... | Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). | [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n"
] | [
"YES\n",
"NO\n"
] | In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon. | 1,000 | [
{
"input": "7 3\n---X--X\n-X--XX-",
"output": "YES"
},
{
"input": "6 2\n--X-X-\nX--XX-",
"output": "NO"
},
{
"input": "10 1\n-X-X-X-X-X\nX-X-X-X-X-",
"output": "YES"
},
{
"input": "5 4\n-X---\n----X",
"output": "NO"
},
{
"input": "6 2\n--X--X\nXX-X-X",
"output... | 1,684,260,681 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 102,400 | n, k = map(int, input().split())
canyon = ["-" * n] * n
for i in range(n):
left, right = input().strip().split()
canyon[i] = left + right[1:]
danger = {(i, j+1) for i in range(n) for j in range(n) if canyon[i][j] == "X"}
Safe = {(0, 0)}
queue = [(0, 0)]
water_level = 0
while queue:
x, y = queue.pop(0)
... | Title: Jumping on Walls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these w... | ```python
n, k = map(int, input().split())
canyon = ["-" * n] * n
for i in range(n):
left, right = input().strip().split()
canyon[i] = left + right[1:]
danger = {(i, j+1) for i in range(n) for j in range(n) if canyon[i][j] == "X"}
Safe = {(0, 0)}
queue = [(0, 0)]
water_level = 0
while queue:
x, y = queu... | -1 | |
892 | B | Wrath | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer — the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | 1,000 | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0"... | 1,682,978,916 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
claws = list(map(int, input().split()))
claws.sort()
i, j = 0, 0
alive = n
while i < n and j < n:
while j < n and j < i + claws[i]:
j += 1
if j >= n:
break
alive = j
i += 1
print(alive) | Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ... | ```python
n = int(input())
claws = list(map(int, input().split()))
claws.sort()
i, j = 0, 0
alive = n
while i < n and j < n:
while j < n and j < i + claws[i]:
j += 1
if j >= n:
break
alive = j
i += 1
print(alive)
``` | 0 | |
19 | A | World Football Cup | PROGRAMMING | 1,400 | [
"implementation"
] | A. World Football Cup | 2 | 64 | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features *n* teams (*n* is always even) - the first *n*<=/<=2 t... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=50) — amount of the teams, taking part in the final tournament of World Cup. The following *n* lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following *... | Output *n*<=/<=2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | [
"4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n",
"2\na\nA\na-A 2:1\n"
] | [
"A\nD\n",
"a\n"
] | none | 0 | [
{
"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3",
"output": "A\nD"
},
{
"input": "2\na\nA\na-A 2:1",
"output": "a"
},
{
"input": "2\nEULEUbCmfrmqxtzvg\nuHGRmKUhDcxcfqyruwzen\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92",
"output": "EULEUbCmfrmqxtzvg"... | 1,588,753,471 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 218 | 307,200 | # our class starts here
class Info:
def __init__(self, _team_name, _points, _goal_diff, _scored_goals):
self.TeamName = _team_name
self.Points = _points
self.GoalDiff = _goal_diff
self.ScoredGoals = _scored_goals
# our class ends here
# our function here
# find index of ... | Title: World Football Cup
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup reg... | ```python
# our class starts here
class Info:
def __init__(self, _team_name, _points, _goal_diff, _scored_goals):
self.TeamName = _team_name
self.Points = _points
self.GoalDiff = _goal_diff
self.ScoredGoals = _scored_goals
# our class ends here
# our function here
# find... | 3.943211 |
979 | E | Kuro and Topological Parity | PROGRAMMING | 2,400 | [
"dp"
] | null | null | Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.
Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot o... | The first line contains two integers $n$ and $p$ ($1 \leq n \leq 50$, $0 \leq p \leq 1$) — the number of pieces and Kuro's wanted parity.
The second line contains $n$ integers $c_{1}, c_{2}, ..., c_{n}$ ($-1 \leq c_{i} \leq 1$) — the colors of the pieces. | Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $p$. | [
"3 1\n-1 0 1\n",
"2 1\n1 0\n",
"1 1\n-1\n"
] | [
"6",
"1",
"2"
] | In the first example, there are $6$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $3, 3, 5$ for the first row and $5, 3, 3$ for the second row, both from left to right. | 2,250 | [
{
"input": "3 1\n-1 0 1",
"output": "6"
},
{
"input": "2 1\n1 0",
"output": "1"
},
{
"input": "1 1\n-1",
"output": "2"
},
{
"input": "1 0\n-1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "5 1\n-1 -1 -1 -1 -1",
"output": "1651... | 1,604,729,954 | 2,147,483,647 | Python 3 | OK | TESTS | 89 | 109 | 307,200 | n,p=map(int,input().split())
nums=[0]+list(map(int,input().split()))
mod=10**9+7
f=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)]
_2=[0]*(n+1)
_2[0]=1
for i in range(1,n+1):
_2[i]=(_2[i-1]<<1)%mod
f[0][0][0][0]=1
if nums[1]!=0:
f[1][1][0][1]+=1
if nums[1]!=1:
f[1][... | Title: Kuro and Topological Parity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing... | ```python
n,p=map(int,input().split())
nums=[0]+list(map(int,input().split()))
mod=10**9+7
f=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)]
_2=[0]*(n+1)
_2[0]=1
for i in range(1,n+1):
_2[i]=(_2[i-1]<<1)%mod
f[0][0][0][0]=1
if nums[1]!=0:
f[1][1][0][1]+=1
if nums[1]!=1:
... | 3 | |
580 | C | Kefa and Park | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the v... | The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then ... | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats. | [
"4 1\n1 1 0 0\n1 2\n1 3\n1 4\n",
"7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n"
] | [
"2\n",
"2\n"
] | Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if i... | 1,500 | [
{
"input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"output": "2"
},
{
"input": "3 2\n1 1 1\n1 2\n2 3",
"output": "0"
},
{
"input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5",
"output": "1"
},
{
"inpu... | 1,689,267,523 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 33 | 2,000 | 44,236,800 | def ordering(d,n):
l=[1]
ans=[];count_=1;i=0
while count_<n:
for j in d[l[i]]:
ans+=[[l[i],j]];d[j].remove(l[i]);l+=[j];count_+=1
i+=1
return ans
n,m=map(int,input().split())
A=list(map(int,input().split()))
d_={};d_1={}#d_ stores whether a node is a leaf node or not d_1 st... | Title: Kefa and Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house... | ```python
def ordering(d,n):
l=[1]
ans=[];count_=1;i=0
while count_<n:
for j in d[l[i]]:
ans+=[[l[i],j]];d[j].remove(l[i]);l+=[j];count_+=1
i+=1
return ans
n,m=map(int,input().split())
A=list(map(int,input().split()))
d_={};d_1={}#d_ stores whether a node is a leaf node or n... | 0 | |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,662,871,447 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 93 | 16,384,000 | n = int(input())
s = input().split(" ")
s = sorted([int(i) for i in s])
start = s[0]
end = s[-1]
print(end - start, end = " ")
count_start = 0
count_end = 0
for i in s:
if i == start:
count_start += 1
if i == end:
count_end += 1
print(count_start*count_end) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
n = int(input())
s = input().split(" ")
s = sorted([int(i) for i in s])
start = s[0]
end = s[-1]
print(end - start, end = " ")
count_start = 0
count_end = 0
for i in s:
if i == start:
count_start += 1
if i == end:
count_end += 1
print(count_start*count_end)
``` | 0 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,680,529,481 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | r,c=map(int,input().split())
count=0
for i in range(1,r+1):
for j in range(1,c+1):
if(i%2!=0):
print("#",end="")
else:
if(count==0):
if(j!=c):
print(".",end="")
else:
print("#",end="")
... | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
r,c=map(int,input().split())
count=0
for i in range(1,r+1):
for j in range(1,c+1):
if(i%2!=0):
print("#",end="")
else:
if(count==0):
if(j!=c):
print(".",end="")
else:
print("#",end=""... | 0 | |
777 | E | Hanoi Factory | PROGRAMMING | 2,000 | [
"brute force",
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of rings in factory's stock.
The *i*-th of the next *n* lines contains three integers *a**i*, *b**i* and *h**i* (1<=≤<=*a**i*,<=*b**i*,<=*h**i*<=≤<=109, *b**i*<=><=*a**i*) — inner radius, outer radius and the height of t... | Print one integer — the maximum height of the tower that can be obtained. | [
"3\n1 5 1\n2 6 2\n3 7 3\n",
"4\n1 2 1\n1 3 3\n4 6 2\n5 7 1\n"
] | [
"6\n",
"4\n"
] | In the first sample, the optimal solution is to take all the rings and put them on each other in order 3, 2, 1.
In the second sample, one can put the ring 3 on the ring 4 and get the tower of height 3, or put the ring 1 on the ring 2 and get the tower of height 4. | 2,500 | [
{
"input": "3\n1 5 1\n2 6 2\n3 7 3",
"output": "6"
},
{
"input": "4\n1 2 1\n1 3 3\n4 6 2\n5 7 1",
"output": "4"
},
{
"input": "1\n1 2 1",
"output": "1"
},
{
"input": "5\n6 10 4\n9 20 19\n8 11 18\n18 20 1\n19 20 8",
"output": "50"
},
{
"input": "5\n21 25 26\n14 30 ... | 1,698,877,288 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 436 | 28,569,600 | t = [(9e9, 0, 0)]
n = int(input())
for i in range(n):
a, b, h = map(int, input().split())
t.append((b, a, h))
t.sort(reverse=True)
s, p = [0], [0] * (n + 1)
for i in range(1, n + 1):
while t[s[-1]][1] >= t[i][0]: s.pop()
p[i] = p[s[-1]] + t[i][2]
s.append(i)
print(max(p)) | Title: Hanoi Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the worke... | ```python
t = [(9e9, 0, 0)]
n = int(input())
for i in range(n):
a, b, h = map(int, input().split())
t.append((b, a, h))
t.sort(reverse=True)
s, p = [0], [0] * (n + 1)
for i in range(1, n + 1):
while t[s[-1]][1] >= t[i][0]: s.pop()
p[i] = p[s[-1]] + t[i][2]
s.append(i)
print(max(p))
``` | 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,012,767 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def gravity_switch(columns):<br/> # Sort each column in ascending order<br/> sorted_columns = [sorted(col) for col in columns]<br/><br/> # Find the maximum height across all columns<br/> max_height = max(len(col) for col in sorted_columns)<br/><br/> # Create a new list to store the final column arrangeme... | 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_switch(columns):<br/> # Sort each column in ascending order<br/> sorted_columns = [sorted(col) for col in columns]<br/><br/> # Find the maximum height across all columns<br/> max_height = max(len(col) for col in sorted_columns)<br/><br/> # Create a new list to store the final column... | -1 | |
409 | H | A + B Strikes Back | PROGRAMMING | 1,500 | [
"*special",
"brute force",
"constructive algorithms",
"dsu",
"implementation"
] | null | null | A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? | The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. | Output the sum of the given integers. | [
"5 14\n",
"381 492\n"
] | [
"19\n",
"873\n"
] | none | 0 | [
{
"input": "5 14",
"output": "19"
},
{
"input": "381 492",
"output": "873"
},
{
"input": "536 298",
"output": "834"
},
{
"input": "143 522",
"output": "665"
},
{
"input": "433 126",
"output": "559"
},
{
"input": "723 350",
"output": "1073"
},
{... | 1,632,828,026 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | j = input().split()
s = j[0]
m = j[0]
k = int(s)
l = int(m)
print(k+l) | Title: A + B Strikes Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
Input ... | ```python
j = input().split()
s = j[0]
m = j[0]
k = int(s)
l = int(m)
print(k+l)
``` | 0 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,656,521,277 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 248 | 512,000 | def solve():
n = int(input())
lst = []
ans = ""
a = 0
for _ in range(n):
s = input()
lst.append(s)
se = set(lst)
for i in se:
x = lst.count(i)
if x > a :
ans = i
a = x
print(ans)
... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
def solve():
n = int(input())
lst = []
ans = ""
a = 0
for _ in range(n):
s = input()
lst.append(s)
se = set(lst)
for i in se:
x = lst.count(i)
if x > a :
ans = i
a = x
print(ans)... | 3.937046 |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,511,945,823 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 436 | 26,009,600 | n = int(input())
a = list(map(int,input().split()))
ans = 0
if n == 1:
ans = sum(a)
else:
a.sort(reverse=True)
ans = n * a[0]
i = 1
for i in range(1,n):
ans += (n-i+1)*a[i]
i += 1
print(ans)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n = int(input())
a = list(map(int,input().split()))
ans = 0
if n == 1:
ans = sum(a)
else:
a.sort(reverse=True)
ans = n * a[0]
i = 1
for i in range(1,n):
ans += (n-i+1)*a[i]
i += 1
print(ans)
``` | 3 | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,699,721,020 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 1,331,200 | # 注意要考虑几家店价格相同的情况!!!!!!
# bisect做法:
# import bisect
# n = int(input())
# x = [int(_) for _ in input().split()]
# x.sort()
# for _ in range(int(input())):
# m = int(input())
# print(bisect.bisect_right(x, m))
n = int(input())
prices = sorted(list(map(int, input().split())))
q = int(input())
mini = prices[0]
max... | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
# 注意要考虑几家店价格相同的情况!!!!!!
# bisect做法:
# import bisect
# n = int(input())
# x = [int(_) for _ in input().split()]
# x.sort()
# for _ in range(int(input())):
# m = int(input())
# print(bisect.bisect_right(x, m))
n = int(input())
prices = sorted(list(map(int, input().split())))
q = int(input())
mini = pri... | 0 | |
413 | A | Data Recovery | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer ... | The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=<<=*n*<=≤<=100; 1<=≤<=*min*<=<<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant.
Note, that the reported temperatures, and the temperatures ... | If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). | [
"2 1 1 2\n1\n",
"3 1 1 3\n2\n",
"2 1 1 3\n2\n"
] | [
"Correct\n",
"Correct\n",
"Incorrect\n"
] | In the first test sample one of the possible initial configurations of temperatures is [1, 2].
In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].
In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3... | 500 | [
{
"input": "2 1 1 2\n1",
"output": "Correct"
},
{
"input": "3 1 1 3\n2",
"output": "Correct"
},
{
"input": "2 1 1 3\n2",
"output": "Incorrect"
},
{
"input": "3 1 1 5\n3",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 5",
"output": "Correct"
},
{
"input... | 1,614,022,423 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | if __name__ == '__main__':
cin = input
n, m, mj, mx = map(int, cin().split())
a = [int(v) for v in cin().split()]
l, r = min(a), max(a)
b = sum([a[i] - a[i - 1] for i in range(m)])
print(["Incorrect", "Correct"][l - mj + mx - r + b <= n - m])
| Title: Data Recovery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each ... | ```python
if __name__ == '__main__':
cin = input
n, m, mj, mx = map(int, cin().split())
a = [int(v) for v in cin().split()]
l, r = min(a), max(a)
b = sum([a[i] - a[i - 1] for i in range(m)])
print(["Incorrect", "Correct"][l - mj + mx - r + b <= n - m])
``` | 0 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,676,402,513 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | n=int(input())
list=[]
list1=[]
for i in range(n):
string=input()
list1.append(string)
for x in range(n):
if list1[x] in list:
print("YES")
else:
list.append(list1[x])
print("NO") | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
n=int(input())
list=[]
list1=[]
for i in range(n):
string=input()
list1.append(string)
for x in range(n):
if list1[x] in list:
print("YES")
else:
list.append(list1[x])
print("NO")
``` | 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,697,033,983 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | x, y, z = map(int, input().split())
result = min(x - y, z + 1)
print(result)
| 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
x, y, z = map(int, input().split())
result = min(x - y, z + 1)
print(result)
``` | 3 | |
542 | D | Superhero's Job | PROGRAMMING | 2,600 | [
"dfs and similar",
"dp",
"hashing",
"math",
"number theory"
] | null | null | It's tough to be a superhero. And it's twice as tough to resist the supervillain who is cool at math. Suppose that you're an ordinary Batman in an ordinary city of Gotham. Your enemy Joker mined the building of the city administration and you only have several minutes to neutralize the charge. To do that you should ent... | The single line of the input contains a single integer *A* (1<=≤<=*A*<=≤<=1012). | Print the number of solutions of the equation *J*(*x*)<==<=*A*. | [
"3\n",
"24\n"
] | [
"1\n",
"3\n"
] | Record *x*|*n* means that number *n* divides number *x*.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f651455cf24acab8e8b76da4abe0ec8f028ec17b.png" style="max-width: 100.0%;max-height: 100.0%;"/> is defined as the largest positive integer that divides both *a* and *b*.
In the first sam... | 2,250 | [] | 1,689,182,159 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689182159.412101")# 1689182159.41212 | Title: Superhero's Job
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's tough to be a superhero. And it's twice as tough to resist the supervillain who is cool at math. Suppose that you're an ordinary Batman in an ordinary city of Gotham. Your enemy Joker mined the building of the city... | ```python
print("_RANDOM_GUESS_1689182159.412101")# 1689182159.41212
``` | 0 | |
47 | D | Safe | PROGRAMMING | 2,200 | [
"brute force"
] | D. Safe | 5 | 256 | Vasya tries to break in a safe. He knows that a code consists of *n* numbers, and every number is a 0 or a 1. Vasya has made *m* attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so u... | The first input line contains two integers *n* and *m* (6<=≤<=*n*<=≤<=35,<=1<=≤<=*m*<=≤<=10) which represent the number of numbers in the code and the number of attempts made by Vasya. Then follow *m* lines, each containing space-separated *s**i* and *c**i* which correspondingly indicate Vasya’s attempt (a line contain... | Print the single number which indicates how many possible code variants that do not contradict the *m* system responses are left. | [
"6 2\n000000 2\n010100 4\n",
"6 3\n000000 2\n010100 4\n111100 0\n",
"6 3\n000000 2\n010100 4\n111100 2\n"
] | [
"6\n",
"0\n",
"1\n"
] | none | 2,000 | [
{
"input": "6 2\n000000 2\n010100 4",
"output": "6"
},
{
"input": "6 3\n000000 2\n010100 4\n111100 0",
"output": "0"
},
{
"input": "6 3\n000000 2\n010100 4\n111100 2",
"output": "1"
},
{
"input": "6 1\n101011 2",
"output": "15"
},
{
"input": "7 2\n1011111 2\n10011... | 1,690,818,382 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1690818381.9830542")# 1690818381.9830742 | Title: Safe
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya tries to break in a safe. He knows that a code consists of *n* numbers, and every number is a 0 or a 1. Vasya has made *m* attempts to enter the code. After each attempt the system told him in how many position stand the right n... | ```python
print("_RANDOM_GUESS_1690818381.9830542")# 1690818381.9830742
``` | 0 |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,697,439,252 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | str1 = input()
n, k = map(int, str1.split())
if n & 1 == False:
if n/2 >= k:
print(2*k - 1)
else:
print(2*k - n)
else:
if n/2 + 1 >= k:
print(2*k - 1)
else:
print(2*(k - int((n/2 + 1))))
| Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
str1 = input()
n, k = map(int, str1.split())
if n & 1 == False:
if n/2 >= k:
print(2*k - 1)
else:
print(2*k - n)
else:
if n/2 + 1 >= k:
print(2*k - 1)
else:
print(2*(k - int((n/2 + 1))))
``` | 3 | |
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"o... | 1,695,061,243 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 31 | 0 | n=int(input())
list1=list(map(int,input().split()))
a=0
for x in list1:
if x==1:
print(-1)
a+=1
break
if a==0:
print(1) | Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cann... | ```python
n=int(input())
list1=list(map(int,input().split()))
a=0
for x in list1:
if x==1:
print(-1)
a+=1
break
if a==0:
print(1)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 0 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,689,178,004 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689178004.1075368")# 1689178004.107552 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First o... | ```python
print("_RANDOM_GUESS_1689178004.1075368")# 1689178004.107552
``` | 0 | |
831 | B | Keyboard Layouts | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i... | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.
The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.
The third line contains a non-empty string *s* consisting of lowercase a... | Print the text if the same keys were pressed in the second layout. | [
"qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017\n",
"mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7\n"
] | [
"HelloVKCup2017\n",
"7uduGUDUUDUgudu7\n"
] | none | 750 | [
{
"input": "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017",
"output": "HelloVKCup2017"
},
{
"input": "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7",
"output": "7uduGUDUUDUgudu7"
},
{
"input": "ayvguplhjsoiencbkxdrfwmqtz\nkhzvtbspcndier... | 1,685,509,880 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 31 | 0 | a = input()
b = input()
d = {}
for i in range(26):
d[a[i]]=b[i]
d[a[i].upper()]=b[i].upper()
c = input()
ans = ''
for i in c:
if i in d.keys():
ans+=d[i]
else:
ans+=i
print(ans)
| Title: Keyboard Layouts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are gi... | ```python
a = input()
b = input()
d = {}
for i in range(26):
d[a[i]]=b[i]
d[a[i].upper()]=b[i].upper()
c = input()
ans = ''
for i in c:
if i in d.keys():
ans+=d[i]
else:
ans+=i
print(ans)
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,562,505,983 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 156 | 0 | n, a = int(input()), list(map(int, input().split()))
print(1 if sum(a) % (n + 1) == 1 else min(2, n - sum(a) % (n +1) + 1)) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n, a = int(input()), list(map(int, input().split()))
print(1 if sum(a) % (n + 1) == 1 else min(2, n - sum(a) % (n +1) + 1))
``` | 0 | |
978 | C | Letters | PROGRAMMING | 1,000 | [
"binary search",
"implementation",
"two pointers"
] | null | null | There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered from $1$ to $a_i$.
A postman delivers letters. Sometimes there is no specific dormitory and roo... | The first line contains two integers $n$ and $m$ $(1 \le n, m \le 2 \cdot 10^{5})$ — the number of dormitories and the number of letters.
The second line contains a sequence $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^{10})$, where $a_i$ equals to the number of rooms in the $i$-th dormitory. The third line contains a se... | Print $m$ lines. For each letter print two integers $f$ and $k$ — the dormitory number $f$ $(1 \le f \le n)$ and the room number $k$ in this dormitory $(1 \le k \le a_f)$ to deliver the letter. | [
"3 6\n10 15 12\n1 9 12 23 26 37\n",
"2 3\n5 10000000000\n5 6 9999999999\n"
] | [
"1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n",
"1 5\n2 1\n2 9999999994\n"
] | In the first example letters should be delivered in the following order:
- the first letter in room $1$ of the first dormitory - the second letter in room $9$ of the first dormitory - the third letter in room $2$ of the second dormitory - the fourth letter in room $13$ of the second dormitory - the fifth letter i... | 0 | [
{
"input": "3 6\n10 15 12\n1 9 12 23 26 37",
"output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12"
},
{
"input": "2 3\n5 10000000000\n5 6 9999999999",
"output": "1 5\n2 1\n2 9999999994"
},
{
"input": "1 1\n1\n1",
"output": "1 1"
},
{
"input": "5 15\n10 20 30 20 10\n1 6 10 11 15 30 31 54... | 1,674,221,839 | 739 | PyPy 3-64 | OK | TESTS | 16 | 326 | 39,526,400 | import sys
input = lambda: sys.stdin.readline().rstrip()
# ----------------------- #
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = []
s = 0
t = 0
dom = 0
room = 0
all_room = 0
for i, dom in enumerate(A, 1):
pre = all_room
all_room ... | Title: Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered fro... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
# ----------------------- #
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = []
s = 0
t = 0
dom = 0
room = 0
all_room = 0
for i, dom in enumerate(A, 1):
pre = all_room
... | 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,696,846,166 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 0 | n,x=map(int,input().split())
l=list(map(int,input().split()))
if x in l:
for i in range(len(l)):
if l[i]==x:
print(i)
else:
print(-1)
| 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
n,x=map(int,input().split())
l=list(map(int,input().split()))
if x in l:
for i in range(len(l)):
if l[i]==x:
print(i)
else:
print(-1)
``` | -1 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,680,283,491 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 6,656,000 | from functools import lru_cache
@lru_cache
def f(i):
if i == 0:
return 0
elif i == 1:
return mas[1]
else:
return max(f(i-1), f(i-2) + mas[i])
n = int(input())
a = list(map(int, input().split()))
mas = [0] * (max(a) + 1)
for i in range(1, max(a) + 1):
mas[i]... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
from functools import lru_cache
@lru_cache
def f(i):
if i == 0:
return 0
elif i == 1:
return mas[1]
else:
return max(f(i-1), f(i-2) + mas[i])
n = int(input())
a = list(map(int, input().split()))
mas = [0] * (max(a) + 1)
for i in range(1, max(a) + 1):
... | 0 | |
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,658,551,125 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 61 | 1,740,800 | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
i, j = 0, n - 1
c = n // 2
while(c):
b.append(a[i])
b.append(a[j])
c -= 1
i += 1
j -= 1
if(n % 2):
b.append(a[n // 2])
# print(b)
for i in range(1, n):... | 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 sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
i, j = 0, n - 1
c = n // 2
while(c):
b.append(a[i])
b.append(a[j])
c -= 1
i += 1
j -= 1
if(n % 2):
b.append(a[n // 2])
# print(b)
for i in ra... | 3 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,683,552,901 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | guest = input()
host = input()
pile = input()
ghChars = [0]*26
pileChars = [0]*26
for char in guest:
ghChars[ord(char) - ord('A')]+=1
for char in host:
ghChars[ord(char) - ord('A')]+=1
for char in pile:
pileChars[ord(char) - ord('A')]+=1
yes = True
for i in range(26):
if pileChars[i] - ... | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
guest = input()
host = input()
pile = input()
ghChars = [0]*26
pileChars = [0]*26
for char in guest:
ghChars[ord(char) - ord('A')]+=1
for char in host:
ghChars[ord(char) - ord('A')]+=1
for char in pile:
pileChars[ord(char) - ord('A')]+=1
yes = True
for i in range(26):
if pileC... | 0 | |
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,274,411 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 122 | 0 | s = input()
t = input()
sx = ord(s[0]) - ord('a')
sy = int(s[1])
tx = ord(t[0]) - ord('a')
ty = int(t[1])
ans = []
while sx != tx or sy != ty:
tmp = []
if sx < tx:
tmp.append('R')
sx += 1
elif sx > tx:
tmp.append('L')
sx -= 1
if sy < ty:
tmp.append('U')
... | 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
s = input()
t = input()
sx = ord(s[0]) - ord('a')
sy = int(s[1])
tx = ord(t[0]) - ord('a')
ty = int(t[1])
ans = []
while sx != tx or sy != ty:
tmp = []
if sx < tx:
tmp.append('R')
sx += 1
elif sx > tx:
tmp.append('L')
sx -= 1
if sy < ty:
tmp.append('... | 3.939 |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,689,261,533 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input()
print(25) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
n=int(input()
print(25)
``` | -1 | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,663,530,355 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 77 | 13,107,200 | s = int(input())
something = sorted([int(x) for x in input().split()])
answer = 0
add = 1
for i in range(1,s-1):
if something[i] == something[i-1] or something[i] == something[i + 1]:
pass
else:
answer += add
add += 1
print(answer) | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
s = int(input())
something = sorted([int(x) for x in input().split()])
answer = 0
add = 1
for i in range(1,s-1):
if something[i] == something[i-1] or something[i] == something[i + 1]:
pass
else:
answer += add
add += 1
print(answer)
``` | 0 | |
510 | B | Fox And Two Dots | PROGRAMMING | 1,500 | [
"dfs and similar"
] | null | null | Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50): the number of rows and columns of the board.
Then *n* lines follow, each line contains a string consisting of *m* characters, expressing colors of dots in each line. Each character is an uppercase Latin letter. | Output "Yes" if there exists a cycle, and "No" otherwise. | [
"3 4\nAAAA\nABCA\nAAAA\n",
"3 4\nAAAA\nABCA\nAADA\n",
"4 4\nYYYR\nBYBY\nBBBY\nBBBY\n",
"7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n",
"2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n"
] | In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red). | 1,000 | [
{
"input": "3 4\nAAAA\nABCA\nAAAA",
"output": "Yes"
},
{
"input": "3 4\nAAAA\nABCA\nAADA",
"output": "No"
},
{
"input": "4 4\nYYYR\nBYBY\nBBBY\nBBBY",
"output": "Yes"
},
{
"input": "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB",
"output": "Yes"
},
{
... | 1,684,174,585 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 24 | 77 | 3,993,600 | def canMove(i,j):
return i>=0 and i<n and j>=0 and j<m
def dfsMaze(i,j,pi,pj):
visited[i][j]=True
for k in range (4):
neighi=i+di[k]
neighj=j+dj[k]
if canMove(neighi,neighj) and graph[i][j]==graph[neighi][neighj] :#do not continue if you can't move to the next neighbor or if t... | Title: Fox And Two Dots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase La... | ```python
def canMove(i,j):
return i>=0 and i<n and j>=0 and j<m
def dfsMaze(i,j,pi,pj):
visited[i][j]=True
for k in range (4):
neighi=i+di[k]
neighj=j+dj[k]
if canMove(neighi,neighj) and graph[i][j]==graph[neighi][neighj] :#do not continue if you can't move to the next neighb... | 3 | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,677,564,004 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 93 | 13,824,000 | n,k = map(int,input().split())
l = list( map(int,input().split()))
s = 0
for i in range(n-1):
if l[i+1]-l[i]>k:
s=0
else:
s+=1
print(s+1) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
n,k = map(int,input().split())
l = list( map(int,input().split()))
s = 0
for i in range(n-1):
if l[i+1]-l[i]>k:
s=0
else:
s+=1
print(s+1)
``` | 3 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,545,541,855 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | brac_seq = list(input())
r = count = max = 0
max_count = 0
for b in brac_seq:
if b == '(':
r += 1
if b == ')':
if r < 1 and count > 0:
if max < count:
max = count
max_count = 1
if max == count :
max... | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
brac_seq = list(input())
r = count = max = 0
max_count = 0
for b in brac_seq:
if b == '(':
r += 1
if b == ')':
if r < 1 and count > 0:
if max < count:
max = count
max_count = 1
if max == count :
... | 0 |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,696,483,256 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | a, b = 0, 0
for _ in range(int(input())):
m, c = map(int, input().split())
if m > c:
a += 1
if m < c:
b += 1
if a > b:
print('Mishka')
if b > a:
print('Chris')
if a == b:
print('Friendship is magic!^^')
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
a, b = 0, 0
for _ in range(int(input())):
m, c = map(int, input().split())
if m > c:
a += 1
if m < c:
b += 1
if a > b:
print('Mishka')
if b > a:
print('Chris')
if a == b:
print('Friendship is magic!^^')
``` | 3 | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,660,189,498 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n, k = map(int, input().split())
l = list(map(int, input().split()))
a = list(map(int, input().split()))
pre = [0] * (n + 1)
pref = [0] * (n + 1)
for i in range(1, n + 1):
pre[i] = pre[i - 1] + (l[i - 1] * a[i - 1])
pref[i] = pref[i - 1] + l[i - 1]
mx = 0
for i in range(n-k):
mx = max(mx, pre[... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
n, k = map(int, input().split())
l = list(map(int, input().split()))
a = list(map(int, input().split()))
pre = [0] * (n + 1)
pref = [0] * (n + 1)
for i in range(1, n + 1):
pre[i] = pre[i - 1] + (l[i - 1] * a[i - 1])
pref[i] = pref[i - 1] + l[i - 1]
mx = 0
for i in range(n-k):
mx = ma... | 0 | |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,652,338,102 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 186 | 6,041,600 | from tkinter import X
n=int(input())
list1=list(map(int,input().split()))
m=int(input())
list2=list(map(int,input().split()))
d={}
for x in list1:
for y in list2:
if y/x in d:
d[y/x]+=1
else:
d[y/x]=1
print(max(d.values())) | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
from tkinter import X
n=int(input())
list1=list(map(int,input().split()))
m=int(input())
list2=list(map(int,input().split()))
d={}
for x in list1:
for y in list2:
if y/x in d:
d[y/x]+=1
else:
d[y/x]=1
print(max(d.values()))
``` | 0 | |
177 | A1 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which ha... | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 po... | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 30 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
... | 1,648,763,042 | 2,147,483,647 | Python 3 | OK | TESTS1 | 17 | 154 | 0 | n = int(input())
lst = list()
for i in range(n):
sub = list(map(int, input().split()))
lst.append(sub)
total = 0
mid = (n - 1) // 2
for i in range(n):
for j in range(n):
if i == j or j == n - i - 1:
total += lst[i][j]
total += sum(lst[mid][j] for j in range(n))
total += s... | Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the ... | ```python
n = int(input())
lst = list()
for i in range(n):
sub = list(map(int, input().split()))
lst.append(sub)
total = 0
mid = (n - 1) // 2
for i in range(n):
for j in range(n):
if i == j or j == n - i - 1:
total += lst[i][j]
total += sum(lst[mid][j] for j in range(n))
... | 3 | |
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,560,665,470 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n = int(input())
s = input()
c1 = 0
c2 = 0
for i in range(len(s) - 1):
if(s[i] == 'S' and s[i+1] == 'F'):
c1 += 1
elif(s[i] == 'F' and s[i+1] == 'S'):
c2 += 1
if(c1 > c2):
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())
s = input()
c1 = 0
c2 = 0
for i in range(len(s) - 1):
if(s[i] == 'S' and s[i+1] == 'F'):
c1 += 1
elif(s[i] == 'F' and s[i+1] == 'S'):
c2 += 1
if(c1 > c2):
print("YES")
else:
print("NO")
``` | 3 | |
769 | B | News About Credit | PROGRAMMING | 1,200 | [
"*special",
"greedy",
"two pointers"
] | null | null | Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value *a**i* — the maximum number of messages which the *i*-th student is agree to send p... | The first line contains the positive integer *n* (2<=≤<=*n*<=≤<=100) — the number of students.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* equals to the maximum number of messages which can the *i*-th student agree to send. Consider that Polycarp always has th... | Print -1 to the first line if it is impossible to inform all students about credit.
Otherwise, in the first line print the integer *k* — the number of messages which will be sent. In each of the next *k* lines print two distinct integers *f* and *t*, meaning that the student number *f* sent the message with news to t... | [
"4\n1 2 1 0\n",
"6\n2 0 1 3 2 0\n",
"3\n0 2 2\n"
] | [
"3\n1 2\n2 4\n2 3\n",
"6\n1 3\n3 4\n1 2\n4 5\n5 6\n4 6\n",
"-1\n"
] | In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit. | 1,000 | [
{
"input": "4\n1 2 1 0",
"output": "3\n1 2\n2 3\n2 4"
},
{
"input": "6\n2 0 1 3 2 0",
"output": "5\n1 4\n1 5\n4 3\n4 2\n4 6"
},
{
"input": "3\n0 2 2",
"output": "-1"
},
{
"input": "2\n0 0",
"output": "-1"
},
{
"input": "2\n1 0",
"output": "1\n1 2"
},
{
... | 1,499,898,837 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 77 | 5,529,600 | def calc_plan(info):
numbers = len(info)-1
first_point = 0
second_point = 0
out = []
while True:
if second_point == numbers:
return out
if info[first_point] == 0:
if first_point == second_point:
return []
else:
firs... | Title: News About Credit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student... | ```python
def calc_plan(info):
numbers = len(info)-1
first_point = 0
second_point = 0
out = []
while True:
if second_point == numbers:
return out
if info[first_point] == 0:
if first_point == second_point:
return []
else:
... | 0 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,626,460,132 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 22,323,200 | a,b=int(input())
c=list(map(int,input().split()))
w=list(map(int,input().split()))
mnw=min(w)
mn=min(c)
if mnw-1>=mn:
print(mnw-1)
else:
print(-1) | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
a,b=int(input())
c=list(map(int,input().split()))
w=list(map(int,input().split()))
mnw=min(w)
mn=min(c)
if mnw-1>=mn:
print(mnw-1)
else:
print(-1)
``` | -1 | |
401 | C | Team | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. | In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. | [
"1 2\n",
"4 8\n",
"4 10\n",
"1 5\n"
] | [
"101\n",
"110110110101\n",
"11011011011011\n",
"-1\n"
] | none | 1,500 | [
{
"input": "1 2",
"output": "101"
},
{
"input": "4 8",
"output": "110110110101"
},
{
"input": "4 10",
"output": "11011011011011"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "3 4",
"output": "1010101"
},
{
"input": "3 10",
"output": "-1"
},
... | 1,662,439,823 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,m = map(int,input().split())
i = 0
j = 0
res = ""
while i < n and j < m:
res += "1"*min(2,m-j)
res += "0"*min(1,n-i)
i += min(1,n-i)
j += min(2,m-j)
res += "0"*(n-i)
res += "1"*(m-j)
flag = 0
for i in range(len(res)-1):
if res[i] == "0" and res[i+1] == "0":
flag = 1
break
for i in... | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each t... | ```python
n,m = map(int,input().split())
i = 0
j = 0
res = ""
while i < n and j < m:
res += "1"*min(2,m-j)
res += "0"*min(1,n-i)
i += min(1,n-i)
j += min(2,m-j)
res += "0"*(n-i)
res += "1"*(m-j)
flag = 0
for i in range(len(res)-1):
if res[i] == "0" and res[i+1] == "0":
flag = 1
break
... | 0 | |
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,620,886,858 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 6,963,200 | n = int(input())
matrix = []
diagf = 0
elemf = 0
for _ in range(n):
matrix.append(input())
diag = matrix[0][0]
elem = matrix[0][1]
for i in range(n):
for j in range(n):
if i==j or i+j==n-1:
if matrix[i][j] != diag:
diagf = 1
break
else:
... | 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())
matrix = []
diagf = 0
elemf = 0
for _ in range(n):
matrix.append(input())
diag = matrix[0][0]
elem = matrix[0][1]
for i in range(n):
for j in range(n):
if i==j or i+j==n-1:
if matrix[i][j] != diag:
diagf = 1
break
... | 0 | |
342 | C | Cupboard and Balloons | PROGRAMMING | 1,900 | [
"geometry"
] | null | null | A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is *r*, that is, it looks like a rectangle with base *r* and height *h*<=+<=*r* from the sides. The figure be... | The single line contains two integers *r*,<=*h* (1<=≤<=*r*,<=*h*<=≤<=107). | Print a single integer — the maximum number of balloons Xenia can put in the cupboard. | [
"1 1\n",
"1 2\n",
"2 1\n"
] | [
"3\n",
"5\n",
"2\n"
] | none | 1,500 | [
{
"input": "1 1",
"output": "3"
},
{
"input": "1 2",
"output": "5"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "2 3",
"output": "4"
},
{
"input": "4 1",
"output": "1"
},
{
"input": "5 1",
"output"... | 1,676,546,760 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | def calculate_maximum_balloons(r, h):
if r == h:
return 3
if r < h:
return 1 + 2 * h
if r > h:
if h * 2 >= r:
return 2
else:
return 1
if __name__ == "__main__":
r, h = map(int, input().split())
print(calculate_maximum_balloons(r, h))
| Title: Cupboard and Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is... | ```python
def calculate_maximum_balloons(r, h):
if r == h:
return 3
if r < h:
return 1 + 2 * h
if r > h:
if h * 2 >= r:
return 2
else:
return 1
if __name__ == "__main__":
r, h = map(int, input().split())
print(calculate_maximum_balloons(r, h))
``` | 0 | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,522,506,955 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 186 | 7,065,600 | n, m = map(int, input().split())
graph = {}
for i in range(n):
graph[i+1]=[]
for i in range(m):
a, b = map(int, input().split())
graph[a] += [b]
graph[b] += [a]
group=set()
s=0
def find_group(s):
group.clear()
for i in graph:
if (len(graph[i]) == 1):
group.a... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
n, m = map(int, input().split())
graph = {}
for i in range(n):
graph[i+1]=[]
for i in range(m):
a, b = map(int, input().split())
graph[a] += [b]
graph[b] += [a]
group=set()
s=0
def find_group(s):
group.clear()
for i in graph:
if (len(graph[i]) == 1):
... | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,698,223,161 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | k,n,w=map(int,input().split());print(max(0,(k*(w+1)*(w/2)-n))) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k,n,w=map(int,input().split());print(max(0,(k*(w+1)*(w/2)-n)))
``` | 0 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,617,227,102 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 124 | 0 | number_inputs = int(input())
points = []
number_points_line = {}
number_points_column = {}
for i in range(0, number_inputs):
left, right = input().split(" ")
if left not in number_points_column:
number_points_column[left] = 1
else:
number_points_column[left] += 1
if right... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
number_inputs = int(input())
points = []
number_points_line = {}
number_points_column = {}
for i in range(0, number_inputs):
left, right = input().split(" ")
if left not in number_points_column:
number_points_column[left] = 1
else:
number_points_column[left] += 1
... | 0 | |
762 | B | USB vs. PS/2 | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings",
"two pointers"
] | null | null | Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!
The computers bought for the room were different. Some of them had only USB ... | The first line contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=105) — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.
The next line contains one integer *m* (0<=≤<=*m*<=≤<=3·105... | Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy. | [
"2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n"
] | [
"3 14\n"
] | In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. | 0 | [
{
"input": "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2",
"output": "3 14"
},
{
"input": "1 4 4\n12\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB\n281054887 USB\n875326145 USB",
"output": "8 23453... | 1,682,016,029 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 2,000 | 11,264,000 | n_usb, n_ps, n_both = map(int, input().split())
m = int(input())
usb = list()
ps = list()
extra = list()
max_usb = 0
max_ps = 0
equiped = 0
cost = 0
for _ in range(m):
value, m_type = input().split()
if m_type == "USB":
if len(usb) < n_usb:
if int(value) > max_usb:
... | Title: USB vs. PS/2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the c... | ```python
n_usb, n_ps, n_both = map(int, input().split())
m = int(input())
usb = list()
ps = list()
extra = list()
max_usb = 0
max_ps = 0
equiped = 0
cost = 0
for _ in range(m):
value, m_type = input().split()
if m_type == "USB":
if len(usb) < n_usb:
if int(value) > m... | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,639,478,225 | 2,147,483,647 | PyPy 3 | OK | TESTS | 3 | 278 | 5,939,200 |
import sys
import pprint
import logging
from logging import getLogger
def input(): return sys.stdin.readline().rstrip("\r\n")
logging.basicConfig(format="%(message)s", level=logging.WARNING,)
logger = getLogger(__name__)
logger.setLevel(logging.INFO)
def debug(msg, *args):
logger.info(f'{msg}={... | 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
import sys
import pprint
import logging
from logging import getLogger
def input(): return sys.stdin.readline().rstrip("\r\n")
logging.basicConfig(format="%(message)s", level=logging.WARNING,)
logger = getLogger(__name__)
logger.setLevel(logging.INFO)
def debug(msg, *args):
logger.info... | 3 | |
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,694,205,024 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> nk(2);
for(int i = 0; i < 2; i++){
cin >> nk[i];
}
int n = nk[0], k = nk[1];
vector<int> heights(n);
vector<int> prefixes;
int temp_p = 0;
for (in... | 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> nk(2);
for(int i = 0; i < 2; i++){
cin >> nk[i];
}
int n = nk[0], k = nk[1];
vector<int> heights(n);
vector<int> prefixes;
int temp_p = 0;
... | -1 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,688,588,260 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 46 | 2,867,200 | for _ in range(int(input())) :
length = int(input())
if (length // 2) % 2 == 0 :
print("YES")
for i in range(2 , length + 1 , 2) : print(i,end=" ")
for j in range(1 , length , 2) :
if length - 1 == j :
print(j + (length // 2),end=" ")
els... | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
for _ in range(int(input())) :
length = int(input())
if (length // 2) % 2 == 0 :
print("YES")
for i in range(2 , length + 1 , 2) : print(i,end=" ")
for j in range(1 , length , 2) :
if length - 1 == j :
print(j + (length // 2),end=" ")
... | -1 | |
253 | B | Physics Practical | PROGRAMMING | 1,400 | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer — the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one... | 1,000 | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 ... | 1,662,396,138 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,764,800 |
n = int(input())
number = []
number = list(map(int, input().split()))
small = []
large = []
for i in range(n):
if(number[i] not in small):
small.append(number[i])
large.append(number[i])
small.sort()
large.sort()
large.reverse()
count1 = 0
count2 = 0
low=small[0]
high=large[... | Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he... | ```python
n = int(input())
number = []
number = list(map(int, input().split()))
small = []
large = []
for i in range(n):
if(number[i] not in small):
small.append(number[i])
large.append(number[i])
small.sort()
large.sort()
large.reverse()
count1 = 0
count2 = 0
low=small[0]
h... | -1 |
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.