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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
267 | A | Subtractions | PROGRAMMING | 900 | [
"math",
"number theory"
] | null | null | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some num... | The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). | Print the sought number of operations for each pair on a single line. | [
"2\n4 17\n7 987654321\n"
] | [
"8\n141093479\n"
] | none | 500 | [
{
"input": "2\n4 17\n7 987654321",
"output": "8\n141093479"
},
{
"input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321",
"output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479... | 1,650,784,819 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 124 | 8,908,800 |
n = int(input())
def solve(firstNum, secondNum):
if not firstNum or not secondNum:
return 0
maxNum, minNum = max(firstNum, secondNum), min(firstNum, secondNum)
remainder = maxNum % minNum
ops = (maxNum - remainder) // minNum
return ops + solve(minNum, remainder)
array =... | Title: Subtractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one o... | ```python
n = int(input())
def solve(firstNum, secondNum):
if not firstNum or not secondNum:
return 0
maxNum, minNum = max(firstNum, secondNum), min(firstNum, secondNum)
remainder = maxNum % minNum
ops = (maxNum - remainder) // minNum
return ops + solve(minNum, remainder)
... | 3 | |
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,505,656,494 | 2,994 | Python 3 | RUNTIME_ERROR | PRETESTS | 4 | 46 | 0 | n, k = map(int,input().split())
h = 0
p = 0
if int(str(n)+"0"*k)%n == 0:
m = ((int(str(n)+"0"*k)))
for i in range (1, n):
if str(n * i)[len(str(n * i)) - k:] == "0" * k or i == 1000:
p = i
break
h = (n * p)
if i == 1000:
print(m)
else:
print(min(m,h)) | Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000.... | ```python
n, k = map(int,input().split())
h = 0
p = 0
if int(str(n)+"0"*k)%n == 0:
m = ((int(str(n)+"0"*k)))
for i in range (1, n):
if str(n * i)[len(str(n * i)) - k:] == "0" * k or i == 1000:
p = i
break
h = (n * p)
if i == 1000:
print(m)
else:
print(min(m,h))
``` | -1 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,674,218,600 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | s = input()
t = input()
position = 1
index = 0
for i in range(len(t)):
if s[index] == t[i]:
position += 1
index += 1
else:
continue
print(position) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s = input()
t = input()
position = 1
index = 0
for i in range(len(t)):
if s[index] == t[i]:
position += 1
index += 1
else:
continue
print(position)
``` | 3 | |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,521,148,454 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 93 | 7,065,600 | a = list(map(int, input().split()))
t = min(a[0], a[1])
r = max(a[0], a[1])
k = a[2]+t-r
n = k>0
m = (t + min((r-t), a[2])+n*k//2)*2
print(m) | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
a = list(map(int, input().split()))
t = min(a[0], a[1])
r = max(a[0], a[1])
k = a[2]+t-r
n = k>0
m = (t + min((r-t), a[2])+n*k//2)*2
print(m)
``` | 3 | |
740 | A | Alyona and copybooks | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack ... | The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). | Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. | [
"1 1 3 4\n",
"6 2 1 1\n",
"4 4 4 4\n",
"999999999 1000000000 1000000000 1000000000\n"
] | [
"3\n",
"1\n",
"0\n",
"1000000000\n"
] | In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total.
In the third example Alyona ... | 500 | [
{
"input": "1 1 3 4",
"output": "3"
},
{
"input": "6 2 1 1",
"output": "1"
},
{
"input": "4 4 4 4",
"output": "0"
},
{
"input": "999999999 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "1016 3 2 1",
"output": "0"
},
{
"input":... | 1,562,748,984 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 20 | 140 | 0 | n, a, b, c = map(int,input().split())
ans = n % 4
if ans % 4 == 0 :
print(0)
else :
if ans == 1 :
print(min(min(3 * a, c), a + b))
elif ans == 2 :
print(min(min(2 * a, b), 2 * c))
elif ans == 3 :
print(min(min(a, b + c), 2 * c))
| Title: Alyona and copybooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the sh... | ```python
n, a, b, c = map(int,input().split())
ans = n % 4
if ans % 4 == 0 :
print(0)
else :
if ans == 1 :
print(min(min(3 * a, c), a + b))
elif ans == 2 :
print(min(min(2 * a, b), 2 * c))
elif ans == 3 :
print(min(min(a, b + c), 2 * c))
``` | 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,663,445,974 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | x=input()
y=input()
counter = 0
for i in range (len (x)):
if x[i]!=y[-i]:
counter+=1
if counter == len(x):
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
x=input()
y=input()
counter = 0
for i in range (len (x)):
if x[i]!=y[-i]:
counter+=1
if counter == len(x):
print('YES')
else:print('NO')
``` | 0 |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,627,200,119 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 186 | 20,172,800 | import math
a,b,n = map(int,input().split())
count = 1
while n >= 0:
if count % 2 != 0:
d = math.gcd(a,n)
if n >= d:
n -= d
count += 1
else:
print(1)
break
if count % 2 == 0:
d = math.gcd(b,n)
if n >= d:
... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
import math
a,b,n = map(int,input().split())
count = 1
while n >= 0:
if count % 2 != 0:
d = math.gcd(a,n)
if n >= d:
n -= d
count += 1
else:
print(1)
break
if count % 2 == 0:
d = math.gcd(b,n)
if n >=... | 3 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,626,103,664 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 77 | 6,758,400 | n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
while t>0:
t -= (86400-a[i])
i+=1
print(i)
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
while t>0:
t -= (86400-a[i])
i+=1
print(i)
``` | 3 | |
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤... | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sam... | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"inp... | 1,645,013,944 | 1,081 | PyPy 3 | OK | TESTS | 49 | 310 | 12,595,200 | import sys
import math
from collections import deque,Counter
from sys import stdin
#sys.setrecursionlimit(10**7)
int1=lambda x: int(x)-1
stinput=lambda :stdin.readline()[:-1]
ii=lambda :int(stinput())
mi=lambda :map(int, stdin.readline().split())
li=lambda :list(mi())
mi1=lambda :map(int1, stdin.readline(... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<... | ```python
import sys
import math
from collections import deque,Counter
from sys import stdin
#sys.setrecursionlimit(10**7)
int1=lambda x: int(x)-1
stinput=lambda :stdin.readline()[:-1]
ii=lambda :int(stinput())
mi=lambda :map(int, stdin.readline().split())
li=lambda :list(mi())
mi1=lambda :map(int1, stdin... | 3 | |
804 | A | Find Amir | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. | Print single integer: the minimum cost of tickets needed to visit all schools. | [
"2\n",
"10\n"
] | [
"0\n",
"4\n"
] | In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4"
},
{
"input": "43670",
"output": "21834"
},
{
"input": "4217",
"output": "2108"
},
{
"input": "17879",
"output": "8939"
},
{
"input": "31809",
"output": "15904"
},
{
"input": "... | 1,596,463,792 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 140 | 20,172,800 | I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
n=I()
print(((n+1)//2)-1) | Title: Find Amir
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel b... | ```python
I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
n=I()
print(((n+1)//2)-1)
``` | 3 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,584,366,470 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 77 | 307,200 | def snackTower(n, snacks):
sortedSnacks = sorted(snacks, reverse = True)
dailySnacks = []
count = 0
for i in range(n):
dailySnacks.append(snacks[i])
if snacks[i] == sortedSnacks[count]:
count += 1
dailySnacks.reverse()
print(*dailySnacks)
... | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
def snackTower(n, snacks):
sortedSnacks = sorted(snacks, reverse = True)
dailySnacks = []
count = 0
for i in range(n):
dailySnacks.append(snacks[i])
if snacks[i] == sortedSnacks[count]:
count += 1
dailySnacks.reverse()
print(*dailySnacks)
... | 0 | |
435 | B | Pasha Maximizes | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most *k... | The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100). | Print the maximum number that Pasha can get if he makes at most *k* swaps. | [
"1990 1\n",
"300 0\n",
"1034 2\n",
"9090000078001234 6\n"
] | [
"9190\n",
"300\n",
"3104\n",
"9907000008001234\n"
] | none | 1,000 | [
{
"input": "1990 1",
"output": "9190"
},
{
"input": "300 0",
"output": "300"
},
{
"input": "1034 2",
"output": "3104"
},
{
"input": "9090000078001234 6",
"output": "9907000008001234"
},
{
"input": "1234 3",
"output": "4123"
},
{
"input": "5 100",
"... | 1,685,421,526 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 77 | 0 | import sys
from collections import defaultdict
def perform_swaps(j, i, values):
for x in range(j, i , -1):
values[x], values[x - 1] = values[x - 1], values[x]
def main() -> None:
read = sys.stdin.readline
values, k = read().split()
k: int = int(k)
values: list[int] = [int(c) for... | Title: Pasha Maximizes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits ... | ```python
import sys
from collections import defaultdict
def perform_swaps(j, i, values):
for x in range(j, i , -1):
values[x], values[x - 1] = values[x - 1], values[x]
def main() -> None:
read = sys.stdin.readline
values, k = read().split()
k: int = int(k)
values: list[int] = [... | 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,694,623,140 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | k, n, w = input().split()
n = int(n)
k = int(k)
w = int(w)
total = 0
for i in range(1, w + 1):
total = total + (i * K)
if n < total:
print(total - n)
else:
print(0)
| 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 = input().split()
n = int(n)
k = int(k)
w = int(w)
total = 0
for i in range(1, w + 1):
total = total + (i * K)
if n < total:
print(total - n)
else:
print(0)
``` | -1 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,606,148,569 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 155 | 0 | s = input()
try:
s = s[s.index('h'):len(s)-s[::-1].index('o')]
except ValueError:
print("NO")
exit(0)
try:
if s[s.index("e"):].count('l') >= 2:
print("YES")
else:
print("NO")
except ValueError:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
try:
s = s[s.index('h'):len(s)-s[::-1].index('o')]
except ValueError:
print("NO")
exit(0)
try:
if s[s.index("e"):].count('l') >= 2:
print("YES")
else:
print("NO")
except ValueError:
print("NO")
``` | 3.9225 |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,694,508,780 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Sep 12 16:30:18 2023
@author: gzk16
"""
lucky_number = input()
numbers = [int(x) for x in lucky_number]
if all(x == 4 or x == 7 for x in numbers):
print('YES')
else:
count = 0
for number in numbers:
if number == 4 or number == 7:
... | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 12 16:30:18 2023
@author: gzk16
"""
lucky_number = input()
numbers = [int(x) for x in lucky_number]
if all(x == 4 or x == 7 for x in numbers):
print('YES')
else:
count = 0
for number in numbers:
if number == 4 or number == 7:
... | 0 |
955 | B | Not simply beatiful strings | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a ... | The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters. | Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case. | [
"ababa\n",
"zzcxx\n",
"yeee\n"
] | [
"Yes\n",
"Yes\n",
"No\n"
] | In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | 1,000 | [
{
"input": "ababa",
"output": "Yes"
},
{
"input": "zzcxx",
"output": "Yes"
},
{
"input": "yeee",
"output": "No"
},
{
"input": "a",
"output": "No"
},
{
"input": "bbab",
"output": "No"
},
{
"input": "abcd",
"output": "Yes"
},
{
"input": "abc"... | 1,521,830,944 | 8,044 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 93 | 7,065,600 | s = sorted(list(input()))
d = dict((l,s.count(l)) for l in set(s))
count = 0
for l in set(s):
if d[l] > 1:
count += 1
if count > 1:
print('Yes')
else:
print('No')
| Title: Not simply beatiful strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, abab... | ```python
s = sorted(list(input()))
d = dict((l,s.count(l)) for l in set(s))
count = 0
for l in set(s):
if d[l] > 1:
count += 1
if count > 1:
print('Yes')
else:
print('No')
``` | 0 | |
475 | B | Strongly Connected City | PROGRAMMING | 1,400 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes... | The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character... | If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". | [
"3 3\n><>\nv^v\n",
"4 6\n<><>\nv^v^v^\n"
] | [
"NO\n",
"YES\n"
] | The figure above shows street directions in the second sample test case. | 1,000 | [
{
"input": "3 3\n><>\nv^v",
"output": "NO"
},
{
"input": "4 6\n<><>\nv^v^v^",
"output": "YES"
},
{
"input": "2 2\n<>\nv^",
"output": "YES"
},
{
"input": "2 2\n>>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\n^^v",
"output": "YES"
},
{
"input": "3 4\n>>... | 1,412,516,250 | 2,250 | Python 3 | OK | TESTS | 81 | 62 | 0 | #!/usr/bin/python3
n, m = input().split()
n = int(n)
m = int(m)
if n == m == 1:
print("YES")
else:
x, y = input(), input()
x = (1 if x[0] == '<' else 0, 1 if x[-1] == '>' else 0)
y = (1 if y[0] == 'v' else 0, 1 if y[-1] == '^' else 0)
if (sum(x) + sum(y)) % 4 == 0:
print("YES")
else:
... | Title: Strongly Connected City
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one... | ```python
#!/usr/bin/python3
n, m = input().split()
n = int(n)
m = int(m)
if n == m == 1:
print("YES")
else:
x, y = input(), input()
x = (1 if x[0] == '<' else 0, 1 if x[-1] == '>' else 0)
y = (1 if y[0] == 'v' else 0, 1 if y[-1] == '^' else 0)
if (sum(x) + sum(y)) % 4 == 0:
print("YES")
... | 3 | |
884 | D | Boxes And Balls | PROGRAMMING | 2,300 | [
"data structures",
"greedy"
] | null | null | Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*.
In order to do this, Ivan will make some tu... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*. | Print one number — the minimum possible penalty of the game. | [
"3\n1 2 3\n",
"4\n2 3 4 5\n"
] | [
"6\n",
"19\n"
] | In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the r... | 0 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "4\n2 3 4 5",
"output": "19"
},
{
"input": "6\n1 4 4 4 4 4",
"output": "38"
},
{
"input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158",
"output": "8176373828"
},
{
"input": "... | 1,509,698,970 | 7,170 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | # import sys, codecs
#
# save_stdin = sys.stdin
# save_stdout = sys.stdout
# sys.stdin = codecs.open("input.txt", "r", "utf-8")
# sys.stdout = codecs.open("output.txt", "w+")
# TODO: solve
n = int(input())
colors_lens = list(map(int, input().split()))
boxes = [sum(colors_lens)]
boxes.extend([0 for __ in r... | Title: Boxes And Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤... | ```python
# import sys, codecs
#
# save_stdin = sys.stdin
# save_stdout = sys.stdout
# sys.stdin = codecs.open("input.txt", "r", "utf-8")
# sys.stdout = codecs.open("output.txt", "w+")
# TODO: solve
n = int(input())
colors_lens = list(map(int, input().split()))
boxes = [sum(colors_lens)]
boxes.extend([0 f... | 0 | |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee ... | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe ... | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperatur... | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
... | 1,686,769,956 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 1,840 | 8,089,600 | n, k, q = map(int, input().split())
# initialize temperature difference list
temperature_diffs = [0] * 200005
# loop through ranges and add temperature differences
for i in range(n):
range_start, range_end = map(int, input().split())
temperature_diffs[range_start] += 1
temperature_diffs[range_end... | Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve... | ```python
n, k, q = map(int, input().split())
# initialize temperature difference list
temperature_diffs = [0] * 200005
# loop through ranges and add temperature differences
for i in range(n):
range_start, range_end = map(int, input().split())
temperature_diffs[range_start] += 1
temperature_diffs... | 3 | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,628,891,889 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 6,963,200 | n = int(input())
counter = 0
x = []
for i in range(n):
sum_digit = i
for j in str(i):
sum_digit += int(j)
if sum_digit == n:
counter += 1
x.append(i)
print(counter)
for i in range(len(x)):
print(x[i]) | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
n = int(input())
counter = 0
x = []
for i in range(n):
sum_digit = i
for j in str(i):
sum_digit += int(j)
if sum_digit == n:
counter += 1
x.append(i)
print(counter)
for i in range(len(x)):
print(x[i])
``` | 0 | |
59 | B | Fortune Telling | PROGRAMMING | 1,200 | [
"implementation",
"number theory"
] | B. Fortune Telling | 2 | 256 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces a... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100), which is the number of flowers growing in the field. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) which represent the number of petals on a given *i*-th camomile. | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | [
"1\n1\n",
"1\n2\n",
"3\n5 6 7\n"
] | [
"1\n",
"0\n",
"13\n"
] | none | 1,000 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "3\n5 6 7",
"output": "13"
},
{
"input": "2\n5 7",
"output": "7"
},
{
"input": "3\n1 2 3",
"output": "5"
},
{
"input": "4\n4 3 1 2",
"output": "9"
},
{
"inpu... | 1,551,330,652 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 218 | 0 | n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
a=list(reversed(a))
s=0
b=[]
for i in range(n):
s+=a[i]
b.append(s)
i=n-1
while i>=0:
if b[i]%2==0:
i-=1
else:
print(b[i])
exit(0)
print(0) | Title: Fortune Telling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her han... | ```python
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
a=list(reversed(a))
s=0
b=[]
for i in range(n):
s+=a[i]
b.append(s)
i=n-1
while i>=0:
if b[i]%2==0:
i-=1
else:
print(b[i])
exit(0)
print(0)
``` | 0 |
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo... | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDL... | 1,546,249,275 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | n = int(input())
s = input()
l,r,u,d = 0, 0, 0, 0
for x in s:
if x=='L': l+=1
if x=='R': r+=1
if x=='U': u+=1
if x=='D': d+=1
print(min(l,r)*2 + min(u,d)*2) | Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the ce... | ```python
n = int(input())
s = input()
l,r,u,d = 0, 0, 0, 0
for x in s:
if x=='L': l+=1
if x=='R': r+=1
if x=='U': u+=1
if x=='D': d+=1
print(min(l,r)*2 + min(u,d)*2)
``` | 3 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,526,126,236 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 186 | 20,480,000 | input()
l = [int(i) for i in input().split()]
k = sum(l)
s = 0
i = 0
while s < k/2:
s+=l[i]
i+=1
print(i)
| Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
input()
l = [int(i) for i in input().split()]
k = sum(l)
s = 0
i = 0
while s < k/2:
s+=l[i]
i+=1
print(i)
``` | 3 | |
169 | B | Replacing Digits | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≤<=*i*<=≤<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. ... | The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators.
The given number *a* doesn't contain lead... | Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes. | [
"1024\n010\n",
"987\n1234567\n"
] | [
"1124\n",
"987\n"
] | none | 1,000 | [
{
"input": "1024\n010",
"output": "1124"
},
{
"input": "987\n1234567",
"output": "987"
},
{
"input": "10\n1",
"output": "11"
},
{
"input": "11\n1",
"output": "11"
},
{
"input": "12\n2",
"output": "22"
},
{
"input": "1\n0",
"output": "1"
},
{
... | 1,617,705,143 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | a = list(map(int, input()))
s = list(map(int, input()))
s.sort()
flag = 0
if(len(s) > 1):
for j in range(len(s)):
for i in range(len(a)):
if(a[i] < s[j]):
a[i] = s[j]
flag += 1
if(flag == len(s) - 1):
break
... | Title: Replacing Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary ... | ```python
a = list(map(int, input()))
s = list(map(int, input()))
s.sort()
flag = 0
if(len(s) > 1):
for j in range(len(s)):
for i in range(len(a)):
if(a[i] < s[j]):
a[i] = s[j]
flag += 1
if(flag == len(s) - 1):
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula
Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={... | The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. I... | In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them. | [
"4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n",
"1\n42\n",
"2\n1 1 1 1\n"
] | [
"4 3 6 2",
"42 ",
"1 1 "
] | none | 0 | [
{
"input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2",
"output": "2 3 4 6 "
},
{
"input": "1\n42",
"output": "42 "
},
{
"input": "2\n1 1 1 1",
"output": "1 1 "
},
{
"input": "2\n54748096 1 641009859 1",
"output": "54748096 641009859 "
},
{
"input": "3\n1 7 923264237 374... | 1,443,975,760 | 2,260 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
v = list(map(int, input().split()))
s = sorted(set(v))
print(*s[:-5:-1])
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula
Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest intege... | ```python
n = int(input())
v = list(map(int, input().split()))
s = sorted(set(v))
print(*s[:-5:-1])
``` | 0 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,699,538,675 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
for i in range(n):
st=str(input())
cnt=0
if st[0]=='+ or st[len(st)-1]=='+':
cnt+=1
elif st[0]=='-' or st[len(st)-1]=='-':
cnt-=1
print(cnt) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
n=int(input())
for i in range(n):
st=str(input())
cnt=0
if st[0]=='+ or st[len(st)-1]=='+':
cnt+=1
elif st[0]=='-' or st[len(st)-1]=='-':
cnt-=1
print(cnt)
``` | -1 | |
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,515,720,119 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 5,632,000 | n,k = map(int,input().split())
s=n*(n+1)/2
if k>s:
k=k%s
k=int(k)
if k==0:
print(0)
else:
y= -1+(1+8*k)**(0.5)
y=y/2
y=int(y)
k=k-(y*(y+1))//2
print(k)
| 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
n,k = map(int,input().split())
s=n*(n+1)/2
if k>s:
k=k%s
k=int(k)
if k==0:
print(0)
else:
y= -1+(1+8*k)**(0.5)
y=y/2
y=int(y)
k=k-(y*(y+1))//2
print(k)
``` | 0 |
487 | A | Fight the Monster | PROGRAMMING | 1,800 | [
"binary search",
"brute force",
"implementation"
] | null | null | A monster is attacking the Cyberland!
Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (*HP*), offensive power (*ATK*) and defensive power (*DEF*).
During the battle, every second the monster's HP decrease by *max*(0,<=*ATK**Y*<=-<=*DEF**M*), while Yang's HP ... | The first line contains three integers *HP**Y*,<=*ATK**Y*,<=*DEF**Y*, separated by a space, denoting the initial *HP*, *ATK* and *DEF* of Master Yang.
The second line contains three integers *HP**M*,<=*ATK**M*,<=*DEF**M*, separated by a space, denoting the *HP*, *ATK* and *DEF* of the monster.
The third line contains... | The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win. | [
"1 2 1\n1 100 1\n1 100 100\n",
"100 100 100\n1 1 1\n1 1 1\n"
] | [
"99\n",
"0\n"
] | For the first sample, prices for *ATK* and *DEF* are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.
For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything. | 500 | [
{
"input": "1 2 1\n1 100 1\n1 100 100",
"output": "99"
},
{
"input": "100 100 100\n1 1 1\n1 1 1",
"output": "0"
},
{
"input": "50 80 92\n41 51 56\n75 93 12",
"output": "0"
},
{
"input": "76 63 14\n89 87 35\n20 15 56",
"output": "915"
},
{
"input": "12 59 66\n43 15... | 1,656,529,002 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 171 | 2,764,800 | from bisect import *
from collections import *
import sys
import io, os
import math
import random
from heapq import *
gcd = math.gcd
sqrt = math.sqrt
maxint=10**21
def ceil(a, b):
if(b==0):
return maxint
a = -a
k = a // b
k = -k
return k
# arr=list(map(int, input().split()))... | Title: Fight the Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is attacking the Cyberland!
Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (*HP*), offensive power (*ATK*) and defensive power (*DEF*).
During t... | ```python
from bisect import *
from collections import *
import sys
import io, os
import math
import random
from heapq import *
gcd = math.gcd
sqrt = math.sqrt
maxint=10**21
def ceil(a, b):
if(b==0):
return maxint
a = -a
k = a // b
k = -k
return k
# arr=list(map(int, input()... | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,699,424,022 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 186 | 2,252,800 | n = int(input())
cnt = 0
for i in range(n):
x = [int(a) for a in input().split()]
if sum(x) >= 2:
cnt+=1
print(cnt)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input())
cnt = 0
for i in range(n):
x = [int(a) for a in input().split()]
if sum(x) >= 2:
cnt+=1
print(cnt)
``` | 3 | |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10... | 1,632,202,098 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 7,065,600 | def solve():
n=int(input())
def f(x):
s=str(x)
ans=0
for i in s:
ans+=int(i)
return ans
i=19
s=[]
while len(s)<10000:
if f(i)==10:
s.append(... | Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A singl... | ```python
def solve():
n=int(input())
def f(x):
s=str(x)
ans=0
for i in s:
ans+=int(i)
return ans
i=19
s=[]
while len(s)<10000:
if f(i)==10:
... | 0 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,691,806,388 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 307,200 | k, l, m, n, d = int(input()), int(input()), int(input()), int(input()), int(input())
x = []
count = 0
if k == 1 or l == 1 or m == 1 or n == 1:
print(d)
else:
for i in range(1, d + 1):
if i % k == 0 and i not in x:
x.append(i)
count += 1
if i % l == 0 and i n... | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
k, l, m, n, d = int(input()), int(input()), int(input()), int(input()), int(input())
x = []
count = 0
if k == 1 or l == 1 or m == 1 or n == 1:
print(d)
else:
for i in range(1, d + 1):
if i % k == 0 and i not in x:
x.append(i)
count += 1
if i % l ==... | 0 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,553,901,187 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | stones = int(input())
print(((stones*2)+1)//3)
# HaPpY NoWrUz 1398
# UBCF
# CodeForcesian
# ♥
# نشکن دلمو
| Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
stones = int(input())
print(((stones*2)+1)//3)
# HaPpY NoWrUz 1398
# UBCF
# CodeForcesian
# ♥
# نشکن دلمو
``` | 3 | |
267 | A | Subtractions | PROGRAMMING | 900 | [
"math",
"number theory"
] | null | null | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some num... | The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). | Print the sought number of operations for each pair on a single line. | [
"2\n4 17\n7 987654321\n"
] | [
"8\n141093479\n"
] | none | 500 | [
{
"input": "2\n4 17\n7 987654321",
"output": "8\n141093479"
},
{
"input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321",
"output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479... | 1,635,035,676 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 61 | 4,505,600 | from sys import stdin, stdout
def Subtractions(a, b):
result = 0
while a > 0 and b > 0:
if a > b:
result += a // b
a = a % b
elif b > a:
result += b // a
b = b % a
else:
result += 1
a = a - b
ret... | Title: Subtractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one o... | ```python
from sys import stdin, stdout
def Subtractions(a, b):
result = 0
while a > 0 and b > 0:
if a > b:
result += a // b
a = a % b
elif b > a:
result += b // a
b = b % a
else:
result += 1
a = a - ... | 3 | |
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min... | The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
... | 1,620,302,023 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 186 | 20,172,800 | import math
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
c = math.ceil(s/(n-1))
print(c)
| Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a... | ```python
import math
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
c = math.ceil(s/(n-1))
print(c)
``` | 0 | |
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 4... | 1,565,687,706 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | n = input()
a = map(int, input().split())
print(min(abs(360-2*sum(a[j:i]))for i in range(n+1)for j in range(i)))
| Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut in... | ```python
n = input()
a = map(int, input().split())
print(min(abs(360-2*sum(a[j:i]))for i in range(n+1)for j in range(i)))
``` | -1 | |
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,649,993,479 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 |
s=input();r=input()
txts = [x for x in str(s)]; txtr = [x for x in str(r)]
h=0
for i in range(len(txts)):
if txts[i] != txtr[-(i+1)]:
print("NO")
h+=1
break
if h==0:
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=input();r=input()
txts = [x for x in str(s)]; txtr = [x for x in str(r)]
h=0
for i in range(len(txts)):
if txts[i] != txtr[-(i+1)]:
print("NO")
h+=1
break
if h==0:
print("YES")
... | 3.977 |
769 | C | Cycle In Maze | PROGRAMMING | 1,700 | [
"*special",
"dfs and similar",
"graphs",
"greedy",
"shortest paths"
] | null | null | The Robot is in a rectangular maze of size *n*<=×<=*m*. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is emp... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=106) — the size of the maze and the length of the cycle.
Each of the following *n* lines contains *m* symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "... | Print the lexicographically minimum Robot's way with the length exactly *k*, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes). | [
"2 3 2\n.**\nX..\n",
"5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.\n",
"3 3 4\n***\n*X*\n***\n"
] | [
"RL\n",
"DLDDLLLRRRUURU\n",
"IMPOSSIBLE\n"
] | In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less.
In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up.
In the third sample the Robot can'... | 1,500 | [
{
"input": "2 3 2\n.**\nX..",
"output": "RL"
},
{
"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.",
"output": "DLDDLLLRRRUURU"
},
{
"input": "3 3 4\n***\n*X*\n***",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 1\nX",
"output": "IMPOSSIBLE"
},
{
"input": "1 2... | 1,545,306,170 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 7 | 530 | 268,390,400 | n, m, length = list(map(int,input().split()))
x, y = 0, 0
arr = []
for i in range(n):
arr.append(list(input()))
if "X" in arr[i]:
x, y = i, arr[i].index("X")
arr[x][y] = "."
def dfs(x, y, length):
stack = []
stack.append([x, y, 0, ""])
while stack:
now = s... | Title: Cycle In Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Robot is in a rectangular maze of size *n*<=×<=*m*. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "... | ```python
n, m, length = list(map(int,input().split()))
x, y = 0, 0
arr = []
for i in range(n):
arr.append(list(input()))
if "X" in arr[i]:
x, y = i, arr[i].index("X")
arr[x][y] = "."
def dfs(x, y, length):
stack = []
stack.append([x, y, 0, ""])
while stack:
... | 0 | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,695,477,644 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n, m = map(int, input().split())
map = []
for i in range(n):
map.append(input())
print(map)
pos = []
for i in range(n):
for j in range(m):
if map[i][j] == '*':
pos.append((i+1, j+1))
a = b = 0
if pos[0][0] != pos[1][0] and pos[0][0] != pos[2][0]:
a = pos[0][0]
elif pos[1][0] !=... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
n, m = map(int, input().split())
map = []
for i in range(n):
map.append(input())
print(map)
pos = []
for i in range(n):
for j in range(m):
if map[i][j] == '*':
pos.append((i+1, j+1))
a = b = 0
if pos[0][0] != pos[1][0] and pos[0][0] != pos[2][0]:
a = pos[0][0]
elif po... | 0 | |
61 | D | Eternal Victory | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"greedy",
"shortest paths",
"trees"
] | D. Eternal Victory | 2 | 256 | Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!
He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too ... | First line contains a single natural number *n* (1<=≤<=*n*<=≤<=105) — the amount of cities.
Next *n*<=-<=1 lines contain 3 integer numbers each *x**i*, *y**i* and *w**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=0<=≤<=*w**i*<=≤<=2<=×<=104). *x**i* and *y**i* are two ends of a road and *w**i* is the length of that road. | A single integer number, the minimal length of Shapur's travel.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"3\n1 2 3\n2 3 4\n",
"3\n1 2 3\n1 3 3\n"
] | [
"7\n",
"9\n"
] | none | 2,000 | [
{
"input": "3\n1 2 3\n2 3 4",
"output": "7"
},
{
"input": "3\n1 2 3\n1 3 3",
"output": "9"
},
{
"input": "5\n5 3 60\n4 3 63\n2 1 97\n3 1 14",
"output": "371"
},
{
"input": "3\n2 1 63\n3 1 78",
"output": "204"
},
{
"input": "13\n8 2 58\n2 1 49\n13 10 41\n11 9 67\n6... | 1,435,628,772 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 1,372 | 25,804,800 | g = [[] for _ in range(100005)]
sumx = 0
n = int(input())
for i in range(n-1):
x, y, w = map(int, input().split(' '))
g[x].append([y, w])
g[y].append([x, w])
sumx += 2*w
visited = [0] * 100005
dist = [10**18] * 100005
dist[1] = 0
def dfs(s):
visited[s] = 1
for i in g[s]:
... | Title: Eternal Victory
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!
He decided to visit a... | ```python
g = [[] for _ in range(100005)]
sumx = 0
n = int(input())
for i in range(n-1):
x, y, w = map(int, input().split(' '))
g[x].append([y, w])
g[y].append([x, w])
sumx += 2*w
visited = [0] * 100005
dist = [10**18] * 100005
dist[1] = 0
def dfs(s):
visited[s] = 1
for i in g[s... | 3.608935 |
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,660,247,825 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n,m,a = input().split()
x = int((n+a-1)/a)
y = int((m+a-1)/a)
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()
x = int((n+a-1)/a)
y = int((m+a-1)/a)
print(x*y)
``` | -1 |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,550,078,290 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | s = input()
numN = 3
numI = 1
numE = 3
numT = 1
countN = s.count('n')
countI = s.count('i')
countE = s.count('e')
countT = s.count('t')
print(min([countN//numN, countI//numI, countE//numE, countT//numT]))
| Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
s = input()
numN = 3
numI = 1
numE = 3
numT = 1
countN = s.count('n')
countI = s.count('i')
countE = s.count('e')
countT = s.count('t')
print(min([countN//numN, countI//numI, countE//numE, countT//numT]))
``` | 0 | |
33 | A | What is for dinner? | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | A. What is for dinner? | 2 | 256 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where bel... | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | [
"4 3 18\n2 3\n1 2\n3 6\n2 3\n",
"2 2 13\n1 13\n2 12\n"
] | [
"11\n",
"13\n"
] | none | 500 | [
{
"input": "4 3 18\n2 3\n1 2\n3 6\n2 3",
"output": "11"
},
{
"input": "2 2 13\n1 13\n2 12",
"output": "13"
},
{
"input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3",
"output": "8"
},
{
"input": "1 1 0\n1 3",
"output": "0"
},
{
"input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 1... | 1,564,335,549 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 248 | 0 | n, m, k = [int(i) for i in input().split()]
lst = [1000000] * m
for j in range(n):
r, c = [int(y) for y in input().split()]
lst[r - 1] = min(lst[r - 1], c)
print(min(sum(lst), k))
| Title: What is for dinner?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that... | ```python
n, m, k = [int(i) for i in input().split()]
lst = [1000000] * m
for j in range(n):
r, c = [int(y) for y in input().split()]
lst[r - 1] = min(lst[r - 1], c)
print(min(sum(lst), k))
``` | 3.938 |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,694,781,656 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 25 | 92 | 0 | n=int(input())
x={4,7}
d=str(n)
d=list(d)
d=list(map(int,d))
c=set(d)
if n%4==0 or n%7==0 or c==x:
print("YES")
else:
print("NO") | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n=int(input())
x={4,7}
d=str(n)
d=list(d)
d=list(map(int,d))
c=set(d)
if n%4==0 or n%7==0 or c==x:
print("YES")
else:
print("NO")
``` | 0 | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,641,702,603 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 12 | 93 | 3,584,000 | n,t=map(int,input().split())
a=list(map(int,input().split()))
i=1
while i<n:
if i==t:
print("YES")
exit()
i+=(a[i-1])
print("NO") | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n,t=map(int,input().split())
a=list(map(int,input().split()))
i=1
while i<n:
if i==t:
print("YES")
exit()
i+=(a[i-1])
print("NO")
``` | 0 | |
96 | B | Lucky Numbers (easy) | PROGRAMMING | 1,300 | [
"binary search",
"bitmasks",
"brute force"
] | B. Lucky Numbers (easy) | 2 | 256 | Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo... | The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=109). This number doesn't have leading zeroes. | Output the least super lucky number that is more than or equal to *n*.
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"4500\n",
"47\n"
] | [
"4747\n",
"47\n"
] | none | 1,000 | [
{
"input": "4500",
"output": "4747"
},
{
"input": "47",
"output": "47"
},
{
"input": "1",
"output": "47"
},
{
"input": "12",
"output": "47"
},
{
"input": "4587",
"output": "4747"
},
{
"input": "100",
"output": "4477"
},
{
"input": "1007",
... | 1,662,698,011 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n = int(input())
for e in [47, 74, 4477, 4747, 4774, 7447, 7474, 7744, 444777, 447477, 447747, 447774, 474477, 474747, 474774, 477447, 477474, 477744, 744477, 744747, 744774, 747447, 747474, 747744, 774447, 774474, 774744, 777444, 44447777, 44474777, 44477477, 44477747, 44477774, 44744777, 44747477, 44747747, 44747774... | Title: Lucky Numbers (easy)
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
for e in [47, 74, 4477, 4747, 4774, 7447, 7474, 7744, 444777, 447477, 447747, 447774, 474477, 474747, 474774, 477447, 477474, 477744, 744477, 744747, 744774, 747447, 747474, 747744, 774447, 774474, 774744, 777444, 44447777, 44474777, 44477477, 44477747, 44477774, 44744777, 44747477, 44747747... | 0 |
999 | A | Mishka and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ... | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are... | Print one integer — the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, M... | 0 | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1... | 1,639,727,660 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | n,m=map(int,input().split())
l=list(map(int,input().split()))
n=0
c=0
for i in l:
if i<=m:
n+=1
else:
c=i
break
if c==0:
print(n)
else:
s=l.index(c)
for j in range(len(l)-1,s-1,-1):
if l[j]<=m:
n+=1
else:
print(n)
break
... | Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his... | ```python
n,m=map(int,input().split())
l=list(map(int,input().split()))
n=0
c=0
for i in l:
if i<=m:
n+=1
else:
c=i
break
if c==0:
print(n)
else:
s=l.index(c)
for j in range(len(l)-1,s-1,-1):
if l[j]<=m:
n+=1
else:
print(n)
... | 3 | |
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember... | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks... | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZT... | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNO... | 1,693,807,280 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 36 | 171 | 9,318,400 | def solve(s,n):
if n < 26:
print(-1)
else:
used = [False] * 26
alphas = {'?':0}
for i in range(26):
if alphas.get(s[i]):
alphas[s[i]] += 1
else:
alphas[s[i]] = 1
#print(s[i],used)
if s[i] ... | Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In pa... | ```python
def solve(s,n):
if n < 26:
print(-1)
else:
used = [False] * 26
alphas = {'?':0}
for i in range(26):
if alphas.get(s[i]):
alphas[s[i]] += 1
else:
alphas[s[i]] = 1
#print(s[i],used)
... | -1 | |
23 | A | You're Given a String... | PROGRAMMING | 1,200 | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number — length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | 0 | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggg... | 1,680,955,097 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | s = input()
n = len(s)
ans = 0
for i in range(n):
for j in range(i+1, n):
substr = s[i:j+1]
if s.count(substr) >= 2:
ans = max(ans, len(substr))
print(ans)
| Title: You're Given a String...
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input Sp... | ```python
s = input()
n = len(s)
ans = 0
for i in range(n):
for j in range(i+1, n):
substr = s[i:j+1]
if s.count(substr) >= 2:
ans = max(ans, len(substr))
print(ans)
``` | 0 |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,699,205,878 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | n=input()
res = n[0].upper() + n[1:]
print(res) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
n=input()
res = n[0].upper() + n[1:]
print(res)
``` | 3 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,599,653,254 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 436 | 2,150,400 |
n=int(input(""))
r=n-10
if(r<1 or r>11):
print('0')
elif(r==10):
print('15')
else:
pritn('4')
| Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
n=int(input(""))
r=n-10
if(r<1 or r>11):
print('0')
elif(r==10):
print('15')
else:
pritn('4')
``` | -1 |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,698,000,256 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | print(4-(len(set(input().split(" "))))) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
print(4-(len(set(input().split(" ")))))
``` | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,682,516,648 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 216 | 0 | s = input()
s = s.replace("WUB", " ")
c = s.split()
for i in range(len(c)):
print(c[i], end = ' ')
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
s = input()
s = s.replace("WUB", " ")
c = s.split()
for i in range(len(c)):
print(c[i], end = ' ')
``` | 3 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,596,063,674 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 6,656,000 | def solution():
n = int(input())
arr = [int(i) for i in input().split(' ') if int(i) != 0]
print(len(set(arr)))
if __name__ == "__main__":
solution()
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
def solution():
n = int(input())
arr = [int(i) for i in input().split(' ') if int(i) != 0]
print(len(set(arr)))
if __name__ == "__main__":
solution()
``` | 3 | |
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,662,112 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | a,b=[int(x) for x in input().split(" ")]
arr=[int(x) for x in input().split(" ")]
arr.sort()
ans=0
for i in range(a):
if i == b:
break
if arr[i] < 0:
ans+=arr[i]*-1
else: ans+=arr[i]
print(ans) | 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
a,b=[int(x) for x in input().split(" ")]
arr=[int(x) for x in input().split(" ")]
arr.sort()
ans=0
for i in range(a):
if i == b:
break
if arr[i] < 0:
ans+=arr[i]*-1
else: ans+=arr[i]
print(ans)
``` | 0 |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,692,386,343 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | prob = input().split()
a = int(prob[0])
b = int(prob[1])
c = int(prob[2])
d = int(prob[3])
prob1 = a/b
prob2 = c/d
ptotal = prob1/(1 - ((1-prob1)*(1-prob2)))
print(round(ptotal, 12))
| Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
prob = input().split()
a = int(prob[0])
b = int(prob[1])
c = int(prob[2])
d = int(prob[3])
prob1 = a/b
prob2 = c/d
ptotal = prob1/(1 - ((1-prob1)*(1-prob2)))
print(round(ptotal, 12))
``` | 3 | |
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are... | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15... | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n684... | 1,521,838,133 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 7,065,600 | from math import ceil
hh,mm=map(int,input().split())
h,d,c,n=map(int,input().split())
mins=0
if hh<20:
mins=(60*(19-hh)+(60-mm))
new_h=h+mins*d
print(min((ceil(h/n))*c,ceil(new_h/n)*c*0.8)) | Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without foo... | ```python
from math import ceil
hh,mm=map(int,input().split())
h,d,c,n=map(int,input().split())
mins=0
if hh<20:
mins=(60*(19-hh)+(60-mm))
new_h=h+mins*d
print(min((ceil(h/n))*c,ceil(new_h/n)*c*0.8))
``` | 3 | |
1,004 | C | Sonya and Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi... | The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. | Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. | [
"5\n1 5 4 1 3\n",
"7\n1 2 1 1 1 3 2\n"
] | [
"9\n",
"7\n"
] | In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | 1,500 | [
{
"input": "5\n1 5 4 1 3",
"output": "9"
},
{
"input": "7\n1 2 1 1 1 3 2",
"output": "7"
},
{
"input": "10\n2 2 4 4 3 1 1 2 3 2",
"output": "14"
},
{
"input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4",
"output": "20"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,530,849,607 | 2,707 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 7,065,600 | n=int(input())
a=[int(x) for x in input().split()]
tried=set([])
ans=0
for i in range(n-1):
if(not(a[i] in tried)):
tried.add(a[i])
tested=set([])
for j in range(i+1,n):
tested.add(a[j])
ans+=len(tested)
print(ans) | Title: Sonya and Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ... | ```python
n=int(input())
a=[int(x) for x in input().split()]
tried=set([])
ans=0
for i in range(n-1):
if(not(a[i] in tried)):
tried.add(a[i])
tested=set([])
for j in range(i+1,n):
tested.add(a[j])
ans+=len(tested)
print(ans)
``` | 0 | |
149 | D | Coloring Brackets | PROGRAMMING | 1,900 | [
"dp"
] | null | null | Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it.
You are given string *s*. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain ... | The first line contains the single string *s* (2<=≤<=|*s*|<=≤<=700) which represents a correct bracket sequence. | Print the only number — the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109<=+<=7). | [
"(())\n",
"(()())\n",
"()\n"
] | [
"12\n",
"40\n",
"4\n"
] | Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below.
The two ways of coloring shown below are incorrect. | 2,500 | [
{
"input": "(())",
"output": "12"
},
{
"input": "(()())",
"output": "40"
},
{
"input": "()",
"output": "4"
},
{
"input": "((()))",
"output": "36"
},
{
"input": "()(())",
"output": "42"
},
{
"input": "()()()",
"output": "48"
},
{
"input": "(... | 1,696,387,753 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | # LUOGU_RID: 127442379
print("4") | Title: Coloring Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it.
You are given string *s*. It represents a correct bracket sequence. A correct bracket se... | ```python
# LUOGU_RID: 127442379
print("4")
``` | 0 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,579,887,035 | 2,147,483,647 | PyPy 3 | OK | TESTS | 135 | 156 | 0 | n,a,b=map(int,input().split())
l1=[]
for x in range(1,n):
l1.append(min(a//x , b//(n-x)))
print(max(l1))
| Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
n,a,b=map(int,input().split())
l1=[]
for x in range(1,n):
l1.append(min(a//x , b//(n-x)))
print(max(l1))
``` | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,691,166,072 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 154 | 0 | import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int, sys.stdin.readline().strip().split())
import bisect
left = lambda l,a : bisect.bisect_left(l,a)
right = lambda l,a: bisect.bisect_right(l,a)
s = input()
i = 0
ans = ""
while i < len(s):
if s[i] == '.' : ans +=... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int, sys.stdin.readline().strip().split())
import bisect
left = lambda l,a : bisect.bisect_left(l,a)
right = lambda l,a: bisect.bisect_right(l,a)
s = input()
i = 0
ans = ""
while i < len(s):
if s[i] == '.... | 3.9615 |
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,690,560,317 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n, c = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
answer = 1
for i in range(n):
if t[i] - t[i-1] > c:
answer = 0
answer += 1
print(answer) | 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, c = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
answer = 1
for i in range(n):
if t[i] - t[i-1] > c:
answer = 0
answer += 1
print(answer)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The Little Elephant has two permutations *a* and *b* of length *n*, consisting of numbers from 1 to *n*, inclusive. Let's denote the *i*-th (1<=≤<=*i*<=≤<=*n*) element of the permutation *a* as *a**i*, the *j*-th (1<=≤<=*j*<=≤<=*n*) element of the permutation *b* — as *b**j*.
The distance between permutations *a* and ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the permutations. The second line contains permutation *a* as *n* distinct numbers from 1 to *n*, inclusive. The numbers are separated with single spaces. The third line contains permutation *b* in the same format. | In *n* lines print *n* integers — the answers for cyclic shifts. Print the answers to the shifts in the order of the shifts' numeration in permutation *b*, that is, first for the 1-st cyclic shift, then for the 2-nd, and so on. | [
"2\n1 2\n2 1\n",
"4\n2 1 3 4\n3 4 2 1\n"
] | [
"1\n0\n",
"2\n1\n0\n1\n"
] | none | 0 | [] | 1,691,759,388 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1691759388.7838838")# 1691759388.7839005 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has two permutations *a* and *b* of length *n*, consisting of numbers from 1 to *n*, inclusive. Let's denote the *i*-th (1<=≤<=*i*<=≤<=*n*) element of the permutation *a* as *a**i*, the *j*-th (1<=≤<=*j*<=≤<=*n... | ```python
print("_RANDOM_GUESS_1691759388.7838838")# 1691759388.7839005
``` | 0 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,545,756,744 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 124 | 0 | n = int(input())
s = [x for x in input()]
if s.count('1') > 0:
print('1', '0'*s.count('0'), sep='')
else:
print('0')
| Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
n = int(input())
s = [x for x in input()]
if s.count('1') > 0:
print('1', '0'*s.count('0'), sep='')
else:
print('0')
``` | 3 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,639,910,088 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 139 | 2,355,200 | s1 = list(input())
s2 = list(input())
count = 0
i,j =len(s1)-1,len(s2)-1
while i >= 0 and j>=0:
if s1[i] == s2[j]:
count +=1
i-=1
j-=1
print(len(s1)+len(s2)-2*count)
| Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s1 = list(input())
s2 = list(input())
count = 0
i,j =len(s1)-1,len(s2)-1
while i >= 0 and j>=0:
if s1[i] == s2[j]:
count +=1
i-=1
j-=1
print(len(s1)+len(s2)-2*count)
``` | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,698,297,632 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a = input()
if a == "{}":
print(0)
else:
a.replace('{', "")
a.replace('}', '')
a= list(map(str, a.split(",")))
print(len(a))
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
a = input()
if a == "{}":
print(0)
else:
a.replace('{', "")
a.replace('}', '')
a= list(map(str, a.split(",")))
print(len(a))
``` | 0 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,691,383,641 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 31 | 921,600 | n=int(input())
str1=input().upper()
str1=list(str1)
if str1.count('A')>str1.count('D'):
print("Anton")
elif str1.count('A')<str1.count('D'):
print("Danik")
else:
print("Friendship") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
n=int(input())
str1=input().upper()
str1=list(str1)
if str1.count('A')>str1.count('D'):
print("Anton")
elif str1.count('A')<str1.count('D'):
print("Danik")
else:
print("Friendship")
``` | 3 | |
981 | D | Bookshelves | PROGRAMMING | 1,900 | [
"bitmasks",
"dp",
"greedy"
] | null | null | Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Miraculously, Mr Keks was promoted and now he is moving into a new office.
He learned that in the ne... | The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office.
The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 < a_i < 2^{50}$) — the prices of the books in the order they stand on the old shelf. | Print the maximum possible beauty of $k$ shelves in the new office. | [
"10 4\n9 14 28 1 7 13 15 29 2 31\n",
"7 3\n3 14 15 92 65 35 89\n"
] | [
"24\n",
"64\n"
] | In the first example you can split the books as follows:
$$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$
In the second example you can split the books as follows:
$$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$ | 1,750 | [
{
"input": "10 4\n9 14 28 1 7 13 15 29 2 31",
"output": "24"
},
{
"input": "7 3\n3 14 15 92 65 35 89",
"output": "64"
},
{
"input": "40 5\n6 18 24 5 14 16 31 9 15 5 25 2 18 12 19 27 10 23 23 18 22 14 1 14 6 14 17 28 11 21 8 23 10 30 21 5 17 11 26 16",
"output": "80"
},
{
"inp... | 1,689,213,154 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 64 | 108 | 5,939,200 | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 4096
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writa... | Title: Bookshelves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Mira... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 4096
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if ... | 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,561,669,740 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 218 | 0 | n = int(input())
k = [0] * 3
for _ in range(n):
t, x, y = map(int, input().split())
k[t] += x - y
for i in range(1, 3):
print('LIVE' if k[i] >= 0 else '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
n = int(input())
k = [0] * 3
for _ in range(n):
t, x, y = map(int, input().split())
k[t] += x - y
for i in range(1, 3):
print('LIVE' if k[i] >= 0 else 'DEAD')
``` | 3 | |
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicograph... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 ... | 1,699,955,492 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n,m = map(int,(input().split()))
A = [[0]*n for _ in range(n)]
B = [[0]*n for _ in range(n)]
L = [[0]*n for _ in range(n)]
ls = []
for _ in range(m):
i,j = map(int,(input().split()))
A[i][j] = 1
A[j][i] = 1
ls.append(i)
ls.append(j)
for x in range(n):
B[x][x] = ls.count(x)
for i... | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes... | ```python
n,m = map(int,(input().split()))
A = [[0]*n for _ in range(n)]
B = [[0]*n for _ in range(n)]
L = [[0]*n for _ in range(n)]
ls = []
for _ in range(m):
i,j = map(int,(input().split()))
A[i][j] = 1
A[j][i] = 1
ls.append(i)
ls.append(j)
for x in range(n):
B[x][x] = ls.count(x... | -1 | |
46 | B | T-shirts from Sponsor | PROGRAMMING | 1,100 | [
"implementation"
] | B. T-shirts from Sponsor | 2 | 256 | One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not ... | The first line contains five non-negative integers *N**S*,<=*N**M*,<=*N**L*,<=*N**XL*,<=*N**XXL* not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer *K* (1<=≤<=*K*<=≤<=1000) which represents the number of participants. The next *K* lines contain the ... | For each contestant, print a line containing the size of the T-shirt he/she got. | [
"1 0 2 0 1\n3\nXL\nXXL\nM\n"
] | [
"XXL\nL\nL\n"
] | none | 0 | [
{
"input": "1 0 2 0 1\n3\nXL\nXXL\nM",
"output": "XXL\nL\nL"
},
{
"input": "0 0 0 0 1\n1\nS",
"output": "XXL"
},
{
"input": "1 0 1 0 1\n1\nS",
"output": "S"
},
{
"input": "1 0 0 0 1\n2\nS\nL",
"output": "S\nXXL"
},
{
"input": "1 1 1 1 1\n2\nXL\nM",
"output": "... | 1,569,529,880 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 248 | 0 | l = input().split()
for i in range(len(l)):
l[i]= int(l[i])
n_sizes = ["S","M","L","XL","XXL"]
s_sizes = {
"S" : 0,
"M" : 1,
"L": 2,
"XL": 3,
"XXL":4,
}
n = int(input())
ans = ""
for i in range(n):
k = 10
size = s_sizes[input()]
for j in range(len(l)):
... | Title: T-shirts from Sponsor
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what size... | ```python
l = input().split()
for i in range(len(l)):
l[i]= int(l[i])
n_sizes = ["S","M","L","XL","XXL"]
s_sizes = {
"S" : 0,
"M" : 1,
"L": 2,
"XL": 3,
"XXL":4,
}
n = int(input())
ans = ""
for i in range(n):
k = 10
size = s_sizes[input()]
for j in range(len(... | 0 |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,598,706,770 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 312 | 0 | def do():
n = int(input())
dat = list(map(int, input().split()))
a,b = map(int, input().split())
res = 0
for i in range(a-1, b-1):
res += dat[i]
print(res)
do()
def resolve():
#input = sys.stdin.readline
from pprint import pprint
#import sys
#sys.setrecur... | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
def do():
n = int(input())
dat = list(map(int, input().split()))
a,b = map(int, input().split())
res = 0
for i in range(a-1, b-1):
res += dat[i]
print(res)
do()
def resolve():
#input = sys.stdin.readline
from pprint import pprint
#import sys
#sy... | 3.922 |
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — ... | The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has... | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
}... | 1,691,718,956 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 61 | 0 | a=int(input())
b=int(input())
c=int(input())
count=0
for i in range(1,a+1):
if i<=a and 2*i<=b and 4*i<=c:
count+=7
else:
break
print(count) | Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa... | ```python
a=int(input())
b=int(input())
c=int(input())
count=0
for i in range(1,a+1):
if i<=a and 2*i<=b and 4*i<=c:
count+=7
else:
break
print(count)
``` | 3 | |
633 | B | A Trivial Problem | PROGRAMMING | 1,300 | [
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null | Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? | The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial. | First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. | [
"1\n",
"5\n"
] | [
"5\n5 6 7 8 9 ",
"0"
] | The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. | 500 | [
{
"input": "1",
"output": "5\n5 6 7 8 9 "
},
{
"input": "5",
"output": "0"
},
{
"input": "2",
"output": "5\n10 11 12 13 14 "
},
{
"input": "3",
"output": "5\n15 16 17 18 19 "
},
{
"input": "7",
"output": "5\n30 31 32 33 34 "
},
{
"input": "12",
"ou... | 1,463,565,384 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 77 | 5,120,000 | def num5(n):
r = 0
while n:
n //= 5
r += n
return r
m = int(input())
lo = 0
hi = int(1e20)
while lo < hi:
mi = (lo + hi) // 2
if num5(mi) < m:
lo = mi + 1
else:
hi = mi
r = []
while num5(lo) == m:
r.append(lo)
lo += 1
print(len(r))
if r:
print(" ".j... | Title: A Trivial Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zer... | ```python
def num5(n):
r = 0
while n:
n //= 5
r += n
return r
m = int(input())
lo = 0
hi = int(1e20)
while lo < hi:
mi = (lo + hi) // 2
if num5(mi) < m:
lo = mi + 1
else:
hi = mi
r = []
while num5(lo) == m:
r.append(lo)
lo += 1
print(len(r))
if r:
p... | 3 | |
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,512,618,869 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 764 | 268,390,400 | n = int(input())
a = input().split()
b = []
for i in range(n):
a[i] = int(a[i])
a = sorted(a)[::-1]
b.extend(a)
while True:
if len(a) == 1:
break
b.extend(a)
x = a.pop()
print(sum(b)) | 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 = input().split()
b = []
for i in range(n):
a[i] = int(a[i])
a = sorted(a)[::-1]
b.extend(a)
while True:
if len(a) == 1:
break
b.extend(a)
x = a.pop()
print(sum(b))
``` | 0 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,698,473,491 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, k = map(int, input().split())
countCompetitions = list(map(int, input().split()))
countMembers = 0
for countCompetition in countCompetitions:
if countCompetition + k <= 5:
countMembers += 1
print(countMembers//3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split())
countCompetitions = list(map(int, input().split()))
countMembers = 0
for countCompetition in countCompetitions:
if countCompetition + k <= 5:
countMembers += 1
print(countMembers//3)
``` | 3 | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,693,023,311 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 888 | 12,595,200 | n, m = map(int, input().split())
array = list(map(int, input().split()))
queries = []
for _ in range(m):
queries.append(int(input()))
ans=[]
d=set()
for i in range(n):
d.add(array[-i-1])
ans.append(len(d))
for l in queries:
print(ans[-l]) | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n, m = map(int, input().split())
array = list(map(int, input().split()))
queries = []
for _ in range(m):
queries.append(int(input()))
ans=[]
d=set()
for i in range(n):
d.add(array[-i-1])
ans.append(len(d))
for l in queries:
print(ans[-l])
``` | 3 | |
146 | B | Lucky Mask | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a mask of a positive integer *n* the number that is obtained after successive writing ... | The only line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=105). It is guaranteed that number *b* is lucky. | In the only line print a single number — the number *c* that is sought by Petya. | [
"1 7\n",
"100 47\n"
] | [
"7\n",
"147\n"
] | none | 1,000 | [
{
"input": "1 7",
"output": "7"
},
{
"input": "100 47",
"output": "147"
},
{
"input": "458 47",
"output": "467"
},
{
"input": "7 7",
"output": "17"
},
{
"input": "547 47",
"output": "647"
},
{
"input": "77 77",
"output": "177"
},
{
"input":... | 1,619,147,119 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 218 | 2,048,000 | a, b= input().split()
hap= True
x, dig=int(a)+1, int(0)
# while(x!=0):
# x/=10
# dig+=1
while (hap):
mask=""
for y in str(x):
if(int(y)==4 or int(y)==7):
mask+=y
if(mask==b):
hap=False
print(x)
x+=1
# a+=pow(10,dig) | Title: Lucky Mask
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Pe... | ```python
a, b= input().split()
hap= True
x, dig=int(a)+1, int(0)
# while(x!=0):
# x/=10
# dig+=1
while (hap):
mask=""
for y in str(x):
if(int(y)==4 or int(y)==7):
mask+=y
if(mask==b):
hap=False
print(x)
x+=1
# a+=pow(10,dig)
``` | 3 | |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooo... | 1,583,961,148 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 109 | 409,600 | # I make this just for fun because i'm done
# Aimi Haraguni >> Konomi Suzuki >> Yui >> Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi. .. dude?
# problems that involves any kind of persistent data structures are the best of the best, are not them?
import random
N=20
ar, br = [0]*1001, [0]*52
br[0], br[... | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
# I make this just for fun because i'm done
# Aimi Haraguni >> Konomi Suzuki >> Yui >> Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi. .. dude?
# problems that involves any kind of persistent data structures are the best of the best, are not them?
import random
N=20
ar, br = [0]*1001, [0]*52
... | 3 | |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n010100101010100101001001010100101010010... | 1,536,811,902 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 124 | 0 | n = int(input())
seq = list(input())
yes = True
for i in range(len(seq)):
if seq[i] == '1':
if (i != 0 and seq[i-1] == '1') or (i != len(seq) - 1 and seq[i+1] == '1'):
yes = False
break
if i != 0 and seq[i-1] == '0':
seq[i-1] = 'x'
if i != len(seq) - 1 and seq[i+1] == '0':
seq[i+1] = 'x'
if yes and... | Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th... | ```python
n = int(input())
seq = list(input())
yes = True
for i in range(len(seq)):
if seq[i] == '1':
if (i != 0 and seq[i-1] == '1') or (i != len(seq) - 1 and seq[i+1] == '1'):
yes = False
break
if i != 0 and seq[i-1] == '0':
seq[i-1] = 'x'
if i != len(seq) - 1 and seq[i+1] == '0':
seq[i+1] = 'x'
... | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,674,413,636 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 0 | _ = input()
arr = list(map(int,input().split()))
a = max(arr) * len(arr) - sum(arr)
print(a) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
_ = input()
arr = list(map(int,input().split()))
a = max(arr) * len(arr) - sum(arr)
print(a)
``` | 3 | |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,695,574,898 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 124 | 2,048,000 | import string
alp = list(string.ascii_lowercase)
n = int(input())
w = input().lower()
count = 0
alrd=[]
for i in w:
if i in alp and i not in alrd:
count+=1
alrd.append(i)
if count==len(alp):
print("YES")
else:
print("NO") | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
import string
alp = list(string.ascii_lowercase)
n = int(input())
w = input().lower()
count = 0
alrd=[]
for i in w:
if i in alp and i not in alrd:
count+=1
alrd.append(i)
if count==len(alp):
print("YES")
else:
print("NO")
``` | 3 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,588,505,387 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 307,200 | a=[]
for i in range(3):
a.append(list(map(int,input().split())))
m,n,o=a[0][1]+a[0][2],a[1][0]+a[1][2],a[2][0]+a[2][1]
x,y,z=max(m,n,o)-m,max(m,n,o)-n,max(m,n,o)-o
x+=1
y+=1
z+=1
a[0][0],a[1][1],a[2][2]=x,y,z
for i in range(3):
for j in range(3):
print(a[i][j],end=" ")
print("")
| Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
a=[]
for i in range(3):
a.append(list(map(int,input().split())))
m,n,o=a[0][1]+a[0][2],a[1][0]+a[1][2],a[2][0]+a[2][1]
x,y,z=max(m,n,o)-m,max(m,n,o)-n,max(m,n,o)-o
x+=1
y+=1
z+=1
a[0][0],a[1][1],a[2][2]=x,y,z
for i in range(3):
for j in range(3):
print(a[i][j],end=" ")
print(... | 0 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,579,960,132 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 109 | 0 | n = int(input())
l = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
if(n < len(l)):
print(l[n-1])
else:
print(l[n%(len(l)+1)]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n = int(input())
l = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
if(n < len(l)):
print(l[n-1])
else:
print(l[n%(len(l)+1)])
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.
He knows that this year *n* competitions will take place. During the *i*-th competition the participant must as quickly as possible complete a ride along a straight... | The first line contains three integers *n*, *r* and *v* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*r*,<=*v*<=≤<=109) — the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively.
Next *n* lines contain the descriptions of the contests. The *i*-th line contains two integers *s**i... | Print *n* real numbers, the *i*-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=6.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker progr... | [
"2 1 2\n1 10\n5 9\n"
] | [
"3.849644710502\n1.106060157705\n"
] | none | 0 | [] | 1,485,146,838 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 11 | 1,060 | 4,608,000 | from math import cos, pi, sin
TWO_PI = 2*pi
def newton(x):
t = x
nt = t - (t + sin(t) - x)/(1 + cos(t))
while abs(nt - t) >= 1e-7:
t = nt
nt = t - (t + sin(t) - x)/(1 + cos(t))
return nt
def min_time(d, r, v):
k, x = divmod(d/r, TWO_PI)
t = newton(x/2)
return (2*t + k*T... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.
He knows that this year *n* competitions will take place. During the *i*-t... | ```python
from math import cos, pi, sin
TWO_PI = 2*pi
def newton(x):
t = x
nt = t - (t + sin(t) - x)/(1 + cos(t))
while abs(nt - t) >= 1e-7:
t = nt
nt = t - (t + sin(t) - x)/(1 + cos(t))
return nt
def min_time(d, r, v):
k, x = divmod(d/r, TWO_PI)
t = newton(x/2)
return ... | -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,687,423,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
tmp = map( int , input().split())
d = {}
for ele in tmp:
if ele not in d : d[ele] = 1
else : d[ele] += 1
arr = sorted(list(d.keys()))
print( d )
# print( d.keys())
print( arr )
def func( d, arr, n , ptr = 0 , prev = -1 ):
if n==ptr: return 0
ele = arr[ptr]
s... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n = int(input())
tmp = map( int , input().split())
d = {}
for ele in tmp:
if ele not in d : d[ele] = 1
else : d[ele] += 1
arr = sorted(list(d.keys()))
print( d )
# print( d.keys())
print( arr )
def func( d, arr, n , ptr = 0 , prev = -1 ):
if n==ptr: return 0
ele = arr... | 0 | |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,697,658,076 | 2,147,483,647 | PyPy 3 | OK | TESTS | 93 | 93 | 0 | n,t,k,d=map(int, input().split())
from math import ceil
time = ceil(n/k) * t
if time <= (d + t):
print("NO")
else:
print("YES") | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
n,t,k,d=map(int, input().split())
from math import ceil
time = ceil(n/k) * t
if time <= (d + t):
print("NO")
else:
print("YES")
``` | 3 | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,661,301,939 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | num = int(input())
if num % 2 == 0:
print(4)
print(num - 4)
else:
print(9)
print(num - 9)
| Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
num = int(input())
if num % 2 == 0:
print(4)
print(num - 4)
else:
print(9)
print(num - 9)
``` | 3 | |
856 | C | Eleventh Birthday | PROGRAMMING | 2,400 | [
"combinatorics",
"dp",
"math"
] | null | null | It is Borya's eleventh birthday, and he has got a great present: *n* cards with numbers. The *i*-th card has the number *a**i* written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get... | Input data contains multiple test cases. The first line of the input data contains an integer *t* — the number of test cases (1<=≤<=*t*<=≤<=100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000) — the number of cards in Borya's pre... | For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353. | [
"4\n2\n1 1\n3\n1 31 12\n3\n12345 67 84\n9\n1 2 3 4 5 6 7 8 9\n"
] | [
"2\n2\n2\n31680\n"
] | none | 0 | [] | 1,693,661,901 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | print("_RANDOM_GUESS_1693661901.0046923")# 1693661901.0047073 | Title: Eleventh Birthday
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is Borya's eleventh birthday, and he has got a great present: *n* cards with numbers. The *i*-th card has the number *a**i* written on it. Borya wants to put his cards in a row to get one greater number. For exampl... | ```python
print("_RANDOM_GUESS_1693661901.0046923")# 1693661901.0047073
``` | 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,693,464,625 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 |
n, m = map(int, input().split())
snake = [['#'] * m for _ in range(n)]
for i in range(1, n, 2):
if i % 4 == 1:
snake[i][-1] = '.'
else:
snake[i][0] = '.'
for row in snake:
print(''.join(row))
```
You can run this code and input the values of `n` and `m` to get the snake p... | 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
n, m = map(int, input().split())
snake = [['#'] * m for _ in range(n)]
for i in range(1, n, 2):
if i % 4 == 1:
snake[i][-1] = '.'
else:
snake[i][0] = '.'
for row in snake:
print(''.join(row))
```
You can run this code and input the values of `n` and `m` to get t... | -1 | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,655,536,133 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a,b=input("").split(" ")
a=float(a);b=float(b)
def GCD(x, y):
while(y):
x, y = y, x % y
return abs(x)
print(int(GCD(a,b)))
| Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
a,b=input("").split(" ")
a=float(a);b=float(b)
def GCD(x, y):
while(y):
x, y = y, x % y
return abs(x)
print(int(GCD(a,b)))
``` | 0 | |
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,622,357,248 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 |
def solve():
A = int(input())
B = list(map(int, input().split()))
res = sum(B)
for i in range(1, 6):
x = (res + i)%(A + 1)
print(i, (x))
if(x != 1):
return i
return -1
print(solve())
| 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
def solve():
A = int(input())
B = list(map(int, input().split()))
res = sum(B)
for i in range(1, 6):
x = (res + i)%(A + 1)
print(i, (x))
if(x != 1):
return i
return -1
print(solve())
``` | 0 | |
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,694,439,099 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
print((n**5)%100) | 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((n**5)%100)
``` | 0 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,688,202,923 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 372 | 0 | def tinhgiot(vitri):
L = 0
i = vitri-1
while i >= 0 and a[i] <= a[i+1]:
L += 1
i -= 1
R = 0
i = vitri+1
while i < len(a) and a[i] <= a[i-1]:
R += 1
i += 1
return L+R+1
n = int(input())
a = []
a = list(map(int, input().split()))
value... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
def tinhgiot(vitri):
L = 0
i = vitri-1
while i >= 0 and a[i] <= a[i+1]:
L += 1
i -= 1
R = 0
i = vitri+1
while i < len(a) and a[i] <= a[i-1]:
R += 1
i += 1
return L+R+1
n = int(input())
a = []
a = list(map(int, input().split())... | 3.907 |
400 | A | Inna and Choose Options | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The ... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line b... | [
"4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n"
] | [
"3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n"
] | none | 500 | [
{
"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO",
"output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"
},
{
"input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX",
"output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1"
},
{
"input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\n... | 1,569,263,509 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | le=int(input())
for _ in range(le):
str1=input()
count=0
arr=[1,2,3,4,6,12]
arr1=[]
for num in arr:
flag=False
i=12//num
for j in range(i):
if(str1[j]=="X"):
flag=True
if(j+i>=12):
flag=True
... | Title: Inna and Choose Options
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game.... | ```python
le=int(input())
for _ in range(le):
str1=input()
count=0
arr=[1,2,3,4,6,12]
arr1=[]
for num in arr:
flag=False
i=12//num
for j in range(i):
if(str1[j]=="X"):
flag=True
if(j+i>=12):
flag=Tru... | 0 | |
222 | E | Decoding Genome | PROGRAMMING | 1,900 | [
"dp",
"matrices"
] | null | null | Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbered from 1 to *m*. Special characteristics of the Martian DNA prevent some nucleotide pairs from foll... | The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*m*<=≤<=52, 0<=≤<=*k*<=≤<=*m*2).
Next *k* lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pai... | Print a single integer — the sought number modulo 1000000007 (109<=+<=7). | [
"3 3 2\nab\nba\n",
"3 3 0\n",
"2 1 1\naa\n"
] | [
"17\n",
"27\n",
"0\n"
] | In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively. | 2,500 | [
{
"input": "3 3 2\nab\nba",
"output": "17"
},
{
"input": "3 3 0",
"output": "27"
},
{
"input": "2 1 1\naa",
"output": "0"
},
{
"input": "3 5 4\ncd\nce\ned\nee",
"output": "89"
},
{
"input": "100 5 4\ncd\nce\ned\nee",
"output": "537303881"
},
{
"input":... | 1,693,388,510 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 64,307,200 | import sys
# sys.setrecursionlimit(1000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x)+'\n')
# from decimal import Decimal
# from random import randint
# from copy import deepcopy
from collections import deque,Counter
# from heapq import heapify,heappush,heappop
# from b... | Title: Decoding Genome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbe... | ```python
import sys
# sys.setrecursionlimit(1000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x)+'\n')
# from decimal import Decimal
# from random import randint
# from copy import deepcopy
from collections import deque,Counter
# from heapq import heapify,heappush,heappop... | 0 | |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n010100101010100101001001010100101010010... | 1,666,974,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | n = int(input())
seats=input()
flag=0
for i in range(n-1):
if(seats[i]==seats[i+1]):
if(seats[i]=="1" or seats[i]==seats[i+2]):
print("NO")
flag=1
break
if(flag==0):
print("YES") | Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th... | ```python
n = int(input())
seats=input()
flag=0
for i in range(n-1):
if(seats[i]==seats[i+1]):
if(seats[i]=="1" or seats[i]==seats[i+2]):
print("NO")
flag=1
break
if(flag==0):
print("YES")
``` | 0 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,697,741,004 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | from os import path
import sys
if(path.exists('input.txt')):
sys.stdin=open("input.txt","r")
sys.stdout=open("output.txt","w")
# for _ in range(int(input())):
# n = int(input())
# l = [[j for j in input()] for i in range(n)]
# print(l)
# n,k = map(int,input().split())
n = int(input()... | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
from os import path
import sys
if(path.exists('input.txt')):
sys.stdin=open("input.txt","r")
sys.stdout=open("output.txt","w")
# for _ in range(int(input())):
# n = int(input())
# l = [[j for j in input()] for i in range(n)]
# print(l)
# n,k = map(int,input().split())
n = i... | 0 | |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,618,511,883 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 62 | 0 | n=int(input())
l=[]
k=3
while(k):
a=int(input())
l.append(a)
k-=1
mn=min(l)
if mn==l[-1]:
d=min(l[0],l[1]) + (l[2] * (n-2))
print(d)
else:
d=min(l[0],l[1])*(n-1)
print(d)
| Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
n=int(input())
l=[]
k=3
while(k):
a=int(input())
l.append(a)
k-=1
mn=min(l)
if mn==l[-1]:
d=min(l[0],l[1]) + (l[2] * (n-2))
print(d)
else:
d=min(l[0],l[1])*(n-1)
print(d)
``` | 0 | |
616 | A | Comparing Two Long Integers | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can r... | The first line contains a non-negative integer *a*.
The second line contains a non-negative integer *b*.
The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if *a*<=<<=*b* and the symbol ">" if *a*<=><=*b*. If the numbers are equal print the symbol "=". | [
"9\n10\n",
"11\n10\n",
"00012345\n12345\n",
"0123\n9\n",
"0123\n111\n"
] | [
"<\n",
">\n",
"=\n",
">\n",
">\n"
] | none | 0 | [
{
"input": "9\n10",
"output": "<"
},
{
"input": "11\n10",
"output": ">"
},
{
"input": "00012345\n12345",
"output": "="
},
{
"input": "0123\n9",
"output": ">"
},
{
"input": "0123\n111",
"output": ">"
},
{
"input": "9\n9",
"output": "="
},
{
... | 1,697,249,285 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using i64 = long long;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string a, b;
std::cin >> a >> b;
std::reverse(b.begin(), b.end());
std::reverse(a.begin(), a.end());
while (a.back() == '0') a.pop_back();... | Title: Comparing Two Long Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use th... | ```python
#include <bits/stdc++.h>
using i64 = long long;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string a, b;
std::cin >> a >> b;
std::reverse(b.begin(), b.end());
std::reverse(a.begin(), a.end());
while (a.back() == '0') a.p... | -1 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,675,344,566 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | a,b=map(int,input().split())
v=max(a,b)
vv=6-(v-1)
if 6//vv==6/vv:
print(f"{1}/{6 // vv}")
else:
print(f"{vv}/{6}") | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
a,b=map(int,input().split())
v=max(a,b)
vv=6-(v-1)
if 6//vv==6/vv:
print(f"{1}/{6 // vv}")
else:
print(f"{vv}/{6}")
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.