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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f... | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the numbe... | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se... | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output... | 1,494,668,869 | 769 | Python 3 | OK | TESTS | 46 | 109 | 8,704,000 | a, b, c = map(int, input().split())
n = int(input())
k = list(map(int, input().split()))
s = 0
for i in k:
if b < i < c:
s += 1
print(s) | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and... | ```python
a, b, c = map(int, input().split())
n = int(input())
k = list(map(int, input().split()))
s = 0
for i in k:
if b < i < c:
s += 1
print(s)
``` | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,689,784,557 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n=int(input())
a=list(map(int,input().split()))
x,y=0,0
for i in range(n):
k=max(a[0],a[-1])
if i%2==0:
x+=k
else:
y+=k
a.remove(k)
print(x,y)
| Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n=int(input())
a=list(map(int,input().split()))
x,y=0,0
for i in range(n):
k=max(a[0],a[-1])
if i%2==0:
x+=k
else:
y+=k
a.remove(k)
print(x,y)
``` | 3 | |
390 | A | Inna and Alarm Clock | PROGRAMMING | 0 | [
"implementation"
] | null | null | Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square.
The mornin... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100).
Note that a single point in the room can conta... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | [
"4\n0 0\n0 1\n0 2\n1 0\n",
"4\n0 0\n0 1\n1 0\n1 1\n",
"4\n1 1\n1 2\n2 3\n3 3\n"
] | [
"2\n",
"2\n",
"3\n"
] | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | 500 | [
{
"input": "4\n0 0\n0 1\n0 2\n1 0",
"output": "2"
},
{
"input": "4\n0 0\n0 1\n1 0\n1 1",
"output": "2"
},
{
"input": "4\n1 1\n1 2\n2 3\n3 3",
"output": "3"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 ... | 1,544,063,287 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 343 | 7,884,800 | n = int(input())
a = []
b = []
for _ in range(n):
xy = list(map(str,input().split()))
a.append(xy[0])
b.append(xy[1])
aa = list(set(a))
bb = list(set(b))
if(len(aa) > len(bb)):
print(len(bb))
else:
print(len(aa)) | Title: Inna and Alarm Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner a... | ```python
n = int(input())
a = []
b = []
for _ in range(n):
xy = list(map(str,input().split()))
a.append(xy[0])
b.append(xy[1])
aa = list(set(a))
bb = list(set(b))
if(len(aa) > len(bb)):
print(len(bb))
else:
print(len(aa))
``` | 3 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,690,051,288 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 102,400 | n, m = map(int, input().split(" "))
board = []
# chess = [[False for _ in range(n)] for i in range(m)]
colour = False
# False = black
# True = white
# row_checker = 0
# col_checker = 0
for row in range(n):
col = list(input())
board.append(col)
if n % 2 == 0:
for col in range(m):
... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
n, m = map(int, input().split(" "))
board = []
# chess = [[False for _ in range(n)] for i in range(m)]
colour = False
# False = black
# True = white
# row_checker = 0
# col_checker = 0
for row in range(n):
col = list(input())
board.append(col)
if n % 2 == 0:
for col in range... | 0 | |
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the chi... | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space... | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
... | 1,648,645,941 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 46 | 0 | def solve() :
s=''
for i in range(n//2):
if st[i]=='R' and st[n//2+i]=='L':
s+=f'{n//2+i+1} {i+1}\n'
else:
s+=f'{i+1} {n//2+i+1}\n'
s.strip()
with open('output.txt','w') as f :
f.write(s)
return
from sys import stdin
in... | Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t... | ```python
def solve() :
s=''
for i in range(n//2):
if st[i]=='R' and st[n//2+i]=='L':
s+=f'{n//2+i+1} {i+1}\n'
else:
s+=f'{i+1} {n//2+i+1}\n'
s.strip()
with open('output.txt','w') as f :
f.write(s)
return
from sys impor... | 3 | |
735 | D | Taxes | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while fo... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt. | Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax. | [
"4\n",
"27\n"
] | [
"2\n",
"3\n"
] | none | 1,750 | [
{
"input": "4",
"output": "2"
},
{
"input": "27",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "2000000000",
"output": "2"
},
{
"input": "26",
"output": ... | 1,603,260,053 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 | import math
#for i in range(1, 100+1):
# print(i)
n=int(input())
if n==2 or n==3:
print(1)
if n==4:
print(2)
if n>4:
m1=True
for i in range(4, n+1):
c=True
for j in range(2, int(math.sqrt(i))+1):
if i%j==0:
c=False
break
... | Title: Taxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not ... | ```python
import math
#for i in range(1, 100+1):
# print(i)
n=int(input())
if n==2 or n==3:
print(1)
if n==4:
print(2)
if n>4:
m1=True
for i in range(4, n+1):
c=True
for j in range(2, int(math.sqrt(i))+1):
if i%j==0:
c=False
b... | 0 | |
598 | C | Nearest vectors | PROGRAMMING | 2,300 | [
"geometry",
"sortings"
] | null | null | You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 ... | First line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of vectors.
The *i*-th of the following *n* lines contains two integers *x**i* and *y**i* (|*x*|,<=|*y*|<=≤<=10<=000,<=*x*2<=+<=*y*2<=><=0) — the coordinates of the *i*-th vector. Vectors are numbered from 1 to *n* in order ... | Print two integer numbers *a* and *b* (*a*<=≠<=*b*) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any. | [
"4\n-1 0\n0 -1\n1 0\n1 1\n",
"6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n"
] | [
"3 4\n",
"6 5"
] | none | 0 | [
{
"input": "4\n-1 0\n0 -1\n1 0\n1 1",
"output": "3 4"
},
{
"input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6",
"output": "5 6"
},
{
"input": "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7",
"output": "1 3"
},
{
"input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\... | 1,665,208,755 | 3,555 | PyPy 3-64 | WRONG_ANSWER | TESTS | 28 | 327 | 22,425,600 | def main():
from sys import stdin, setrecursionlimit
# setrecursionlimit(1000000)
input = stdin.readline
def iinput(): return int(input())
def sinput(): return input().rstrip()
def i0input(): return int(input()) - 1
def linput(): return list(input().split())
def liinput(): return... | Title: Nearest vectors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, min... | ```python
def main():
from sys import stdin, setrecursionlimit
# setrecursionlimit(1000000)
input = stdin.readline
def iinput(): return int(input())
def sinput(): return input().rstrip()
def i0input(): return int(input()) - 1
def linput(): return list(input().split())
def liinput... | 0 | |
99 | B | Help Chef Gerasim | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | B. Help Chef Gerasim | 0 | 256 | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup... | The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. | If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from... | [
"5\n270\n250\n250\n230\n250\n",
"5\n250\n250\n250\n250\n250\n",
"5\n270\n250\n249\n230\n250\n"
] | [
"20 ml. from cup #4 to cup #1.\n",
"Exemplary pages.\n",
"Unrecoverable configuration.\n"
] | none | 1,000 | [
{
"input": "5\n270\n250\n250\n230\n250",
"output": "20 ml. from cup #4 to cup #1."
},
{
"input": "5\n250\n250\n250\n250\n250",
"output": "Exemplary pages."
},
{
"input": "5\n270\n250\n249\n230\n250",
"output": "Unrecoverable configuration."
},
{
"input": "4\n200\n190\n210\n20... | 1,658,178,629 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import sys
input = sys.stdin.readline
n = int(input())
w = [int(input()) for _ in range(n)]
x = sum(w)/n
d = []
for i in range(n):
if w[i] != x:
d.append((w[i], i))
c = len(d)
if c == 0:
print('Exemplary pages.')
elif c != 2:
print('Unrecoverable configuration.')
else:
d.s... | Title: Help Chef Gerasim
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim ... | ```python
import sys
input = sys.stdin.readline
n = int(input())
w = [int(input()) for _ in range(n)]
x = sum(w)/n
d = []
for i in range(n):
if w[i] != x:
d.append((w[i], i))
c = len(d)
if c == 0:
print('Exemplary pages.')
elif c != 2:
print('Unrecoverable configuration.')
else... | 0 |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,620,896,935 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 77 | 7,065,600 | import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import operator
def main():
z = ''
#p = lambda *a: print(*a, flush = True)
d = defaultdict()
d['polycarp'] = [0, None]
for _ in range(int(stdin.readline())):
s = input... | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import operator
def main():
z = ''
#p = lambda *a: print(*a, flush = True)
d = defaultdict()
d['polycarp'] = [0, None]
for _ in range(int(stdin.readline())):
... | 0 | |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with... | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",... | 1,693,758,712 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | a,b=map(int,input().split())
l=list(map(int,input().split()))
k=0
f=0
ans=-1
for i in range(a):
if b<=0:
ans=i+1
break
k+=l[i]
if k>8:
b-=8
k-=8
else:
b-=k
k=0
if i==a-1 and b<=0:
print(a)
else:
print(ans)
| Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**... | ```python
a,b=map(int,input().split())
l=list(map(int,input().split()))
k=0
f=0
ans=-1
for i in range(a):
if b<=0:
ans=i+1
break
k+=l[i]
if k>8:
b-=8
k-=8
else:
b-=k
k=0
if i==a-1 and b<=0:
print(a)
else:
print(ans)
``` | 0 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,681,477,235 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 61 | 0 | def seanddi():
n=int(input())
a=[int(i) for i in input().split()]
l=0
r=n-1
s=s1=s2=0
while l<=r:
if s%2==0:
if a[r]<a[l]:
s1+=a[l]
l+=1
else:
s1+=a[r]
r-=1
else:
if a[r]<a[l]:
s2+=a[l]
l+=1
else:
... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
def seanddi():
n=int(input())
a=[int(i) for i in input().split()]
l=0
r=n-1
s=s1=s2=0
while l<=r:
if s%2==0:
if a[r]<a[l]:
s1+=a[l]
l+=1
else:
s1+=a[r]
r-=1
else:
if a[r]<a[l]:
s2+=a[l]
l+=1
else:... | 3 | |
787 | B | Not Afraid | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"math"
] | null | null | Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are *n* parallel universes participating in this event (*n* Ricks and *n* Mortys). I. e. each of *n* universes has one Rick... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104) — number of universes and number of groups respectively.
The next *m* lines contain the information about the groups. *i*-th of them first contains an integer *k* (number of times someone joined *i*-th group, *k*<=><=0) followed by ... | In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise. | [
"4 2\n1 -3\n4 -2 3 2 -3\n",
"5 2\n5 3 -2 1 -1 5\n3 -5 2 5\n",
"7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event. | 1,000 | [
{
"input": "4 2\n1 -3\n4 -2 3 2 -3",
"output": "YES"
},
{
"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5",
"output": "NO"
},
{
"input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4",
"output": "YES"
},
{
"input": "2 1\n2 -2 2",
"output": "NO"
},
{
"input": "7 7\n1 -2\n1 6\n2 7 -6\n2... | 1,490,283,691 | 2,191 | Python 3 | OK | TESTS | 65 | 78 | 6,348,800 | import sys
n, m = map(int, input().split())
a = []
for _ in range(m):
a.append(set(map(int, input().split()[1:])))
for i in a:
for j in i:
if -j in i:
break
else:
print("YES")
sys.exit()
print("NO")
| Title: Not Afraid
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are *n* parallel universes ... | ```python
import sys
n, m = map(int, input().split())
a = []
for _ in range(m):
a.append(set(map(int, input().split()[1:])))
for i in a:
for j in i:
if -j in i:
break
else:
print("YES")
sys.exit()
print("NO")
``` | 3 | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,684,932,218 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | """
Logic:
1. function keeps calling itself till 1, then swaps from 1 to n
2. so max element should be 1st element, then rest should be in ascending order
"""
n = int(input())
lst = [str(i) for i in range(1, n)]
print(str(n), " ".join(lst))
| Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
"""
Logic:
1. function keeps calling itself till 1, then swaps from 1 to n
2. so max element should be 1st element, then rest should be in ascending order
"""
n = int(input())
lst = [str(i) for i in range(1, n)]
print(str(n), " ".join(lst))
``` | 3 | |
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,689,194,795 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1689194794.809438")# 1689194794.809485 | 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
print("_RANDOM_GUESS_1689194794.809438")# 1689194794.809485
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,694,842,992 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input("n'))
s=input("string")
fs=""
if s.islower()==True and s.isalpha()==True:
for i in range(n-1):
if i==(n-1):
fs+=s
else:
inx=s.index('\n')
word=s[0]+str(inx-2)+s[inx-1]
fs+=word+'\n'
s=s[inx+1:]
prin... | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n=int(input("n'))
s=input("string")
fs=""
if s.islower()==True and s.isalpha()==True:
for i in range(n-1):
if i==(n-1):
fs+=s
else:
inx=s.index('\n')
word=s[0]+str(inx-2)+s[inx-1]
fs+=word+'\n'
s=s[inx+1:]... | -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,553,875,601 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 124 | 0 | str=input()
nc=str.count('n')
ic=str.count('i')
tc=str.count('t')
ec=str.count("e")
print(min((nc-1)//2,ec//3,ic,tc)) | 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
str=input()
nc=str.count('n')
ic=str.count('i')
tc=str.count('t')
ec=str.count("e")
print(min((nc-1)//2,ec//3,ic,tc))
``` | 0 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,578,588,724 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | n = int(input())
result = 0
minOdd = 99999999
i = 1
while(i <= n):
num = int(input())
if(num % 2 != 0):
minOdd = min(minOdd, num)
result = result + num
i = i + 1
if(result % 2 == 0):
print(result)
else:
print(result - minOdd) | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
result = 0
minOdd = 99999999
i = 1
while(i <= n):
num = int(input())
if(num % 2 != 0):
minOdd = min(minOdd, num)
result = result + num
i = i + 1
if(result % 2 == 0):
print(result)
else:
print(result - minOdd)
``` | -1 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,592,992,856 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 6,758,400 | a=input()
b=input()
n=len(a)
a=int(a,2)
b=int(b,2)
r=bin(a^b)[2:]
print('0'*(n-len(r))+str(r))
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a=input()
b=input()
n=len(a)
a=int(a,2)
b=int(b,2)
r=bin(a^b)[2:]
print('0'*(n-len(r))+str(r))
``` | 3.956411 |
687 | A | NP-Hard Problem | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or bot... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting ... | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number ... | [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"1\n2 \n2\n1 3 \n",
"-1\n"
] | In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | 500 | [
{
"input": "4 2\n1 2\n2 3",
"output": "1\n2 \n2\n1 3 "
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "-1"
},
{
"input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5",
"output": "-1"
},
{
"input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8",
"output": "-1"
... | 1,498,828,892 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 842 | 16,896,000 | n,m=map(int,input().split())
l=[[] for i in range(n+1)]
for i in range(m) :
a,b=map(int,input().split())
l[a].append(b)
l[b].append(a)
z=[-1]*(n+1)
v=[-1]*(n+1)
g=[a]
l1=[a]
l2=[]
v[a]=1
while len(g)>0 :
for x in l[g[0]] :
if v[x]==-1 :
if v[g[0]]==1 :
... | Title: NP-Hard Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of ... | ```python
n,m=map(int,input().split())
l=[[] for i in range(n+1)]
for i in range(m) :
a,b=map(int,input().split())
l[a].append(b)
l[b].append(a)
z=[-1]*(n+1)
v=[-1]*(n+1)
g=[a]
l1=[a]
l2=[]
v[a]=1
while len(g)>0 :
for x in l[g[0]] :
if v[x]==-1 :
if v[g[0]]==1 :
... | 0 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,623,226,789 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | #%%
ints = lambda x, f: f(map(int, x.split(" ")))
cons = ints(input(), list)
ins = []
for i in range(cons[1]):
ins.append(ints(input(), tuple))
s = lambda x: x[0] * x[1]
ins.sort(key=s, reverse=True)
sack = 0
i = 0
while cons[0] > 0 and i < len(ins):
if ins[i][0] <= cons[0]:
cons[... | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
#%%
ints = lambda x, f: f(map(int, x.split(" ")))
cons = ints(input(), list)
ins = []
for i in range(cons[1]):
ins.append(ints(input(), tuple))
s = lambda x: x[0] * x[1]
ins.sort(key=s, reverse=True)
sack = 0
i = 0
while cons[0] > 0 and i < len(ins):
if ins[i][0] <= cons[0]:
... | 0 |
524 | A | Возможно, вы знаете этих людей? | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b* также является другом *a*.
В этой же сети есть функция, которая демонстрирует множество людей, имеющих высокую ве... | В первой строке следуют два целых числа *m* и *k* (1<=≤<=*m*<=≤<=100, 0<=≤<=*k*<=≤<=100) — количество пар друзей и необходимый процент общих друзей для того, чтобы считаться предполагаемым другом.
В последующих *m* строках записано по два числа *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=109, *a**i*<=≠<=*b**i*), обозна... | Для всех упомянутых людей в порядке возрастания id выведите информацию о предполагаемых друзьях. Информация должна иметь вид "*id*:<= *k* *id*1 *id*2 ... *id**k*", где *id* — это id самого человека, *k* — количество его предполагаемых друзей, а *id*1, *id*2, ..., *id**k* — идентификаторы его предполагаемых друзей в воз... | [
"5 51\n10 23\n23 42\n39 42\n10 39\n39 58\n",
"5 100\n1 2\n1 3\n1 4\n2 3\n2 4\n"
] | [
"10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42\n",
"1: 0\n2: 0\n3: 1 4\n4: 1 3\n"
] | none | 500 | [
{
"input": "5 51\n10 23\n23 42\n39 42\n10 39\n39 58",
"output": "10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42"
},
{
"input": "5 100\n1 2\n1 3\n1 4\n2 3\n2 4",
"output": "1: 0\n2: 0\n3: 1 4\n4: 1 3"
},
{
"input": "4 1\n1 2\n1 3\n2 3\n4 5",
"output": "1: 0\n2: 0\n3: 0\n4: 0\n5: ... | 1,426,950,248 | 3,848 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 30 | 0 | d = {}
s = input()
m,k = [int(x) for x in s.split()]
for i in range(m):
s = input().split()
f = s[0] in d.keys()
if f:
a = 1
d[s[0]] = d[s[0]]+' '+s[1]
if not f:
d[s[0]] = s[1]
f = s[1] in d.keys()
if f:
d[s[1]] = d[s[1]]+' '+s[0]
if not f:
... | Title: Возможно, вы знаете этих людей?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b... | ```python
d = {}
s = input()
m,k = [int(x) for x in s.split()]
for i in range(m):
s = input().split()
f = s[0] in d.keys()
if f:
a = 1
d[s[0]] = d[s[0]]+' '+s[1]
if not f:
d[s[0]] = s[1]
f = s[1] in d.keys()
if f:
d[s[1]] = d[s[1]]+' '+s[0]
if no... | 0 | |
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag... | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denotin... | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the s... | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"inpu... | 1,588,515,043 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 982 | 11,571,200 | l1 = [int(num) for num in input().split()]
n = l1[0]
f = l1[1]
list1 = []
list2 = []
list3 = []
final = []
for i in range(n):
l2 = [int(x) for x in input().split()]
if l2[0] >= l2[1]:
list1.append(l2[1])
list2.append(l2[1])
list3.append(l2[1])
else:
list1.append... | Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an ass... | ```python
l1 = [int(num) for num in input().split()]
n = l1[0]
f = l1[1]
list1 = []
list2 = []
list3 = []
final = []
for i in range(n):
l2 = [int(x) for x in input().split()]
if l2[0] >= l2[1]:
list1.append(l2[1])
list2.append(l2[1])
list3.append(l2[1])
else:
li... | 0 | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,672,990,901 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 327 | 10,444,800 | import bisect
n = int(input())
a = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))
l = [a[0]]
masha = []
s = 0
for i in range(1,n):
l.append(l[-1]+a[i])
for i in range(m):
s = bisect.bisect_left(l, q[i])
masha.append(s+1)
print(*masha,sep='\n') | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
import bisect
n = int(input())
a = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))
l = [a[0]]
masha = []
s = 0
for i in range(1,n):
l.append(l[-1]+a[i])
for i in range(m):
s = bisect.bisect_left(l, q[i])
masha.append(s+1)
print(*masha,sep='\n')
``` | 3 | |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ... | 1,642,223,716 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 10,752,000 | s = input()
for i in range(int(input())):
x, y = map(int, input().split())
t, r = 0, 0
for j in s[x - 1:y]:
if j == '(': t += 1
elif j == ')' and t: t, r = t - 1, r + 1
print(r * 2) | Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two i... | ```python
s = input()
for i in range(int(input())):
x, y = map(int, input().split())
t, r = 0, 0
for j in s[x - 1:y]:
if j == '(': t += 1
elif j == ')' and t: t, r = t - 1, r + 1
print(r * 2)
``` | 0 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,698,469,644 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 12 | 1,778 | 11,878,400 | n = int(input())
l = list(map(int,input().split(' ')))
change = []
can_sell = True
i = 0
while i <n:
if l[i] == 25:
change.append(25)
elif l[i] == 100:
if 25 in change and 50 in change:
change.append(100)
change.remove(25)
change.remove(50)
... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
n = int(input())
l = list(map(int,input().split(' ')))
change = []
can_sell = True
i = 0
while i <n:
if l[i] == 25:
change.append(25)
elif l[i] == 100:
if 25 in change and 50 in change:
change.append(100)
change.remove(25)
change.remo... | 0 | |
0 | none | none | none | 0 | [
"none"
] | 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 | 0 | [
{
"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,653,941 | 441 | Python 3 | OK | TESTS | 96 | 77 | 5,529,600 | def getNumb(n):
res1 = 0
while n % 5 == 0:
res1 += 1
n /= 5
res2 = 0
while n % 2 == 0:
res2 += 1
n /= 2
return (res1, res2)
i, n = map(int, input().split())
a = getNumb(i)
print(i * 5 ** (max(n - a[0], 0)) * 2 ** (max(n - a[1], 0)))
| Title: none
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. 30000... | ```python
def getNumb(n):
res1 = 0
while n % 5 == 0:
res1 += 1
n /= 5
res2 = 0
while n % 2 == 0:
res2 += 1
n /= 2
return (res1, res2)
i, n = map(int, input().split())
a = getNumb(i)
print(i * 5 ** (max(n - a[0], 0)) * 2 ** (max(n - a[1], 0)))
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,671,791,602 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | a=int(input())
for i in range(a):
x=str(input())
if(len(x)>10):
print(x[0]+str(len(x)-2)+x[-1])
else:
print(x) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
a=int(input())
for i in range(a):
x=str(input())
if(len(x)>10):
print(x[0]+str(len(x)-2)+x[-1])
else:
print(x)
``` | 3.977 |
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S... | The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and... | Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second... | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1... | 1,646,035,075 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | pg=int(input())
a=list(map(int, input().split()))
cnt = 0
while pg>0:
pg -= a[cnt]
cnt = (cnt+1)%7
print(pg)
print(cnt) | Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s... | ```python
pg=int(input())
a=list(map(int, input().split()))
cnt = 0
while pg>0:
pg -= a[cnt]
cnt = (cnt+1)%7
print(pg)
print(cnt)
``` | 0 | |
290 | D | Orange | PROGRAMMING | 1,400 | [
"*special",
"implementation"
] | null | null | The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive. | Output the required string. | [
"AprilFool\n14\n"
] | [
"AprILFooL\n"
] | none | 0 | [
{
"input": "AprilFool\n14",
"output": "AprILFooL"
},
{
"input": "abcdefabc\n3",
"output": "ABCdefABC"
},
{
"input": "fgWjSAlPOvcAbCdDEFjz\n7",
"output": "FGwjsAlpovCABCDDEFjz"
},
{
"input": "sm\n26",
"output": "SM"
},
{
"input": "GnlFOqPeZtPiBkvvLhaDvGPgFqBTnLgMT\... | 1,660,304,002 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | import sys
input = sys.stdin.readline
s = list(input()[:-1].lower())
n = int(input())
for i in range(len(s)):
if ord(s[i]) - 96 < n:
s[i] = s[i].upper()
print(''.join(s)) | Title: Orange
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integ... | ```python
import sys
input = sys.stdin.readline
s = list(input()[:-1].lower())
n = int(input())
for i in range(len(s)):
if ord(s[i]) - 96 < n:
s[i] = s[i].upper()
print(''.join(s))
``` | 0 | ||
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* ar... | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
... | 1,502,726,885 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 4,608,000 | n=int(input())
l = input()
l = [int(i) for i in l.split()]
t= 0
if n==1 and l[0]==1:print(1)
elif n==1 and l[0]==0: print(0)
else:
for i in range(len(l)-1):
if l[i]==0 and l[i+1]==1:
t+=1
if l[i]==1 and i<=n-3 and l[i+1]==0 and l[i+2]==0:
t-=1
if l[i]=... | Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic ... | ```python
n=int(input())
l = input()
l = [int(i) for i in l.split()]
t= 0
if n==1 and l[0]==1:print(1)
elif n==1 and l[0]==0: print(0)
else:
for i in range(len(l)-1):
if l[i]==0 and l[i+1]==1:
t+=1
if l[i]==1 and i<=n-3 and l[i+1]==0 and l[i+2]==0:
t-=1
... | 0 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,592,683,423 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 13,516,800 | n=int(input())
arr=[int(x) for x in input().split()]
count=0
max=0
brr=[]
for i in range(len(arr)):
if arr[i] not in brr:
brr.append(arr[i])
count+=1
if max<count:
max=count
else:
brr.remove(arr[i])
count-=1
if max<count:
max... | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n=int(input())
arr=[int(x) for x in input().split()]
count=0
max=0
brr=[]
for i in range(len(arr)):
if arr[i] not in brr:
brr.append(arr[i])
count+=1
if max<count:
max=count
else:
brr.remove(arr[i])
count-=1
if max<count:
... | 0 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,692,068,867 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | p = input()
instructions = set("HQ9")
for char in p:
if char in instructions:
print("YES")
break
else:
print("NO")
| Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
p = input()
instructions = set("HQ9")
for char in p:
if char in instructions:
print("YES")
break
else:
print("NO")
``` | 3 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,586,874,822 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 108 | 0 | s,v1,v2,t1,t2=map(int,input().split())
if 2*t1+v1*s > 2*t2+v2*s:
print("Second")
elif 2*t1+v1*s < 2*t2+v2*s:
print("First")
else:
print("Friendship") | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s,v1,v2,t1,t2=map(int,input().split())
if 2*t1+v1*s > 2*t2+v2*s:
print("Second")
elif 2*t1+v1*s < 2*t2+v2*s:
print("First")
else:
print("Friendship")
``` | 3 | |
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 1... | 1,411,613,587 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 155 | 3,584,000 | ints = int(input())
nums = list(map(int, input().split(' ')))
left = [1]*ints
right = [1]*ints
#how many you can extend to the left
#[1, 1, 2, 1, 2, 3]
#the 3 can go to [1, 2, 3]
#both 2s can go to [1, 2]
for i in range(ints-1):
if nums[i+1] >= nums[i]:
left[i+1] += left[i]
#how many you ca... | Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the... | ```python
ints = int(input())
nums = list(map(int, input().split(' ')))
left = [1]*ints
right = [1]*ints
#how many you can extend to the left
#[1, 1, 2, 1, 2, 3]
#the 3 can go to [1, 2, 3]
#both 2s can go to [1, 2]
for i in range(ints-1):
if nums[i+1] >= nums[i]:
left[i+1] += left[i]
#how m... | 0 | |
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of ... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": ... | 1,652,374,387 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | N, K = list(map(int, input().split()))
X = []
for i in range(N): X.append(input())
P = len(input())
X.sort()
x, y = 0, 0
for i in range(N):
if len(X[i]) > P: break
elif len(X[i]) == P: y+=1
else:
y+=1
x+=1
x+=1
if x%K==0: print(x+(((x//K)-1)*5), end=" ")
else: print(x+((x//K)*... | Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords... | ```python
N, K = list(map(int, input().split()))
X = []
for i in range(N): X.append(input())
P = len(input())
X.sort()
x, y = 0, 0
for i in range(N):
if len(X[i]) > P: break
elif len(X[i]) == P: y+=1
else:
y+=1
x+=1
x+=1
if x%K==0: print(x+(((x//K)-1)*5), end=" ")
else: print(... | 0 | |
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,415,379,706 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | import sys
import math
n = int(sys.stdin.readline())
if(n - 10 == 10):
print(15)
elif(n - 10 >= 1 and n - 10 <= 11):
print(4)
else:
print(0) | 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
import sys
import math
n = int(sys.stdin.readline())
if(n - 10 == 10):
print(15)
elif(n - 10 >= 1 and n - 10 <= 11):
print(4)
else:
print(0)
``` | 3.969 |
7 | D | Palindrome Degree | PROGRAMMING | 2,200 | [
"hashing",
"strings"
] | D. Palindrome Degree | 1 | 256 | String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome.
Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For examp... | The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive. | Output the only number — the sum of the polindrome degrees of all the string's prefixes. | [
"a2A\n",
"abacaba\n"
] | [
"1",
"6"
] | none | 0 | [
{
"input": "a2A",
"output": "1"
},
{
"input": "abacaba",
"output": "6"
},
{
"input": "CCeCeCCCee",
"output": "4"
},
{
"input": "opooppppopppopoppopoooppopopooopopppooopppoppoppoppppoooppooooooopppoopoopooooppooooppppppppooopooop",
"output": "3"
},
{
"input": "odri... | 1,431,098,811 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 1,433,600 | __author__ = 'Darren'
def solve():
string = input()
n = len(string)
dp = [0 for i in range(n+1)]
degree_sum = 0
forward, backward, power = 0, 0, 1
for i in range(n):
forward = c_add(c_mul(forward, 31), ord(string[i]))
backward = c_add(c_mul(ord(string[i]), power), ... | Title: Palindrome Degree
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome.
Let's call the pa... | ```python
__author__ = 'Darren'
def solve():
string = input()
n = len(string)
dp = [0 for i in range(n+1)]
degree_sum = 0
forward, backward, power = 0, 0, 1
for i in range(n):
forward = c_add(c_mul(forward, 31), ord(string[i]))
backward = c_add(c_mul(ord(string[i])... | 0 |
736 | E | Chess Championship | PROGRAMMING | 2,900 | [
"constructive algorithms",
"flows",
"greedy",
"math"
] | null | null | Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were *m* players participating and each pair of players played exactly one game. The victory gives 2 points, draw — 1 points, lose — 0 points.
Ostap is lazy, so he never tries... | The first line of the input contains two integers *m* and *n* (1<=≤<=*n*<=≤<=*m*<=≤<=3000) — the number of participants of the tournament and the number of top results Ostap remembers.
The second line contains *n* integers, provided in non-ascending order — the number of points earned by top participants as Ostap reme... | If there is no tournament such that Ostap can obtain the given set of integers using the procedure described in the statement, then print "no" in the only line of the output. Otherwise, the first line of the output should contain the word "yes". Next *m* lines should provide the description of any valid tournament. Eac... | [
"5 5\n8 6 4 2 0\n",
"5 1\n9\n"
] | [
"yes\nXWWWW\nLXWWW\nLLXWW\nLLLXW\nLLLLX\n",
"no\n"
] | none | 2,500 | [] | 1,689,258,794 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1689258794.626286")# 1689258794.626302 | Title: Chess Championship
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were *m* players participating and each pair of players played exactly o... | ```python
print("_RANDOM_GUESS_1689258794.626286")# 1689258794.626302
``` | 0 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,652,665,782 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 10 | 62 | 28,467,200 | n,k = (map(int,input().split()))
arr = list(map(int,input().split()))
s = set(arr)
if k>len(s) :
print("NO")
else :
dif = []
ans=""
i = 0
while len(dif)<k :
while i<n :
if arr[i] not in dif :
dif.append(arr[i])
ans+=str(i+1)+" "
... | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
n,k = (map(int,input().split()))
arr = list(map(int,input().split()))
s = set(arr)
if k>len(s) :
print("NO")
else :
dif = []
ans=""
i = 0
while len(dif)<k :
while i<n :
if arr[i] not in dif :
dif.append(arr[i])
ans+=str(i+1... | 3 | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,630,591,667 | 466 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 |
#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 100000000000000000LL
#define ll long long
#define debug(x) cout << #x << " "<< x <<endl;
#define debug_vector(v) cout << #v << " "; _print(v);
const ll inf =1e9+44;
const int MAX=3e5+9;
const ll MOD= 1e9+7;
const double eps=1e-10;
d... | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 100000000000000000LL
#define ll long long
#define debug(x) cout << #x << " "<< x <<endl;
#define debug_vector(v) cout << #v << " "; _print(v);
const ll inf =1e9+44;
const int MAX=3e5+9;
const ll MOD= 1e9+7;
const double eps... | -1 | |
230 | A | Dragons | PROGRAMMING | 1,000 | [
"greedy",
"sortings"
] | null | null | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit... | The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | [
"2 2\n1 99\n100 0\n",
"10 1\n100 100\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | 500 | [
{
"input": "2 2\n1 99\n100 0",
"output": "YES"
},
{
"input": "10 1\n100 100",
"output": "NO"
},
{
"input": "123 2\n78 10\n130 0",
"output": "YES"
},
{
"input": "999 2\n1010 10\n67 89",
"output": "YES"
},
{
"input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1",
"output": "YE... | 1,699,473,791 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 248 | 0 | def bubbleSort(arr , bonus):
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already in place
for j in range(0, n-i-1):
# traverse the array from 0 to n-i-1
# Swap if the element found is greater
# than the next element
if arr[j] > arr[j+1]... | Title: Dragons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the du... | ```python
def bubbleSort(arr , bonus):
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already in place
for j in range(0, n-i-1):
# traverse the array from 0 to n-i-1
# Swap if the element found is greater
# than the next element
if arr[j] ... | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,638,540,552 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | s = str(input())
a = ""
for i in range(len(s) - 1, -1 ,-1):
a += s[i]
print(a) | 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 = str(input())
a = ""
for i in range(len(s) - 1, -1 ,-1):
a += s[i]
print(a)
``` | 0 |
520 | B | Two Buttons | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs",
"greedy",
"implementation",
"math",
"shortest paths"
] | null | null | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space . | Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*. | [
"4 6\n",
"10 1\n"
] | [
"2\n",
"9\n"
] | In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times. | 1,000 | [
{
"input": "4 6",
"output": "2"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "2 10",
"outpu... | 1,697,560,423 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | a,b=input().split()
a,b=int(a), int(b)
j=0
while a!=b:
j+=1
if (a-1)*2<b:
a*=2
else:
a-=1
print(j) | Title: Two Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by t... | ```python
a,b=input().split()
a,b=int(a), int(b)
j=0
while a!=b:
j+=1
if (a-1)*2<b:
a*=2
else:
a-=1
print(j)
``` | 0 | |
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub... | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
... | 1,566,723,380 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 0 | n=int(input())
array=list(map(int,input().split()))
array.sort(reverse=True)
for i in range(n**n):
if array[0]>array[1]:
array[0]=array[0]-array[1]
array.sort(reverse=True)
print(sum(array))
| Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that ... | ```python
n=int(input())
array=list(map(int,input().split()))
array.sort(reverse=True)
for i in range(n**n):
if array[0]>array[1]:
array[0]=array[0]-array[1]
array.sort(reverse=True)
print(sum(array))
``` | 0 | |
825 | C | Multi-judge Solving | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge).... | The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. | [
"3 3\n2 1 9\n",
"4 20\n10 3 6 3\n"
] | [
"1\n",
"0\n"
] | In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second ... | 0 | [
{
"input": "3 3\n2 1 9",
"output": "1"
},
{
"input": "4 20\n10 3 6 3",
"output": "0"
},
{
"input": "1 1000000000\n1",
"output": "0"
},
{
"input": "1 1\n3",
"output": "1"
},
{
"input": "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34... | 1,500,225,111 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 62 | 4,915,200 | n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
answer = 0
for elem in a:
while 2 * k < elem:
k *= 2
answer += 1
k = max(k, elem)
print(answer) | Title: Multi-judge Solving
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the pro... | ```python
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
answer = 0
for elem in a:
while 2 * k < elem:
k *= 2
answer += 1
k = max(k, elem)
print(answer)
``` | 3 | |
388 | A | Fox and Box Accumulation | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). | Output a single integer — the minimal possible number of piles. | [
"3\n0 0 10\n",
"5\n0 1 2 3 4\n",
"4\n0 0 0 0\n",
"9\n0 1 0 2 0 1 1 2 10\n"
] | [
"2\n",
"1\n",
"4\n",
"3\n"
] | In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | 500 | [
{
"input": "3\n0 0 10",
"output": "2"
},
{
"input": "5\n0 1 2 3 4",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "4"
},
{
"input": "9\n0 1 0 2 0 1 1 2 10",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "2\n0 0",
"output": "... | 1,601,825,307 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 108 | 0 | n=int(input())
a=list(map(int,input().split()))
temp={}
def makestrdict(s):
for l in s:
if temp.get(l):
temp[l]+=1
else:
temp[l]=1
return temp
makestrdict(a)
print(max(temp.values())) | Title: Fox and Box Accumulation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box... | ```python
n=int(input())
a=list(map(int,input().split()))
temp={}
def makestrdict(s):
for l in s:
if temp.get(l):
temp[l]+=1
else:
temp[l]=1
return temp
makestrdict(a)
print(max(temp.values()))
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,651,274,316 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 77 | 0 | s = input()
pos = s.find('h')
if pos != -1:
pos = s.find('e',pos + 1)
if pos != -1:
pos = s.find('l',pos + 1)
if pos != -1:
pos = s.find('l',pos + 1)
if pos != -1:
pos = s.find('o',pos + 1)
if pos != -1:
print('YES')
else :
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
pos = s.find('h')
if pos != -1:
pos = s.find('e',pos + 1)
if pos != -1:
pos = s.find('l',pos + 1)
if pos != -1:
pos = s.find('l',pos + 1)
if pos != -1:
pos = s.find('o',pos + 1)
if pos != -1:
print('YES')
else :
p... | 3.9615 |
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,695,407,210 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 |
x=list(map(int,input().split()))
counter=0
for i in range (3):
if x[i]==x[i+1]:
counter+=1
print (counter) | 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
x=list(map(int,input().split()))
counter=0
for i in range (3):
if x[i]==x[i+1]:
counter+=1
print (counter)
``` | 0 | |
851 | B | Arpa and an exam about geometry | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ... | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | 1,000 | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"i... | 1,572,118,800 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | import math
ax, ay, bx, by, cx, cy = input().split(' ')
ax = int(ax)
ay = int(ay)
bx = int(bx)
by = int(by)
cx = int(cx)
cy = int(cy)
dist_ab = math.sqrt( (ax - bx)**2 + (ay - by)**2 )
dist_bc = math.sqrt( (bx - cx)**2 + (by - cy)**2 )
if(dist_ab == dist_bc):
print("Yes")
else:
print("No")
... | Title: Arpa and an exam about geometry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle... | ```python
import math
ax, ay, bx, by, cx, cy = input().split(' ')
ax = int(ax)
ay = int(ay)
bx = int(bx)
by = int(by)
cx = int(cx)
cy = int(cy)
dist_ab = math.sqrt( (ax - bx)**2 + (ay - by)**2 )
dist_bc = math.sqrt( (bx - cx)**2 + (by - cy)**2 )
if(dist_ab == dist_bc):
print("Yes")
else:
print("No")
... | 0 | |
137 | A | Postcards and photos | PROGRAMMING | 900 | [
"implementation"
] | null | null | Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not ... | The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if ... | Print the only number — the minimum number of times Polycarpus has to visit the closet. | [
"CPCPCPC\n",
"CCCCCCPPPPPP\n",
"CCCCCCPPCPPPPPPPPPP\n",
"CCCCCCCCCC\n"
] | [
"7\n",
"4\n",
"6\n",
"2\n"
] | In the first sample Polycarpus needs to take one item to the closet 7 times.
In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice.
In the third sample Polycarpus can visit the closet twice, both time... | 500 | [
{
"input": "CPCPCPC",
"output": "7"
},
{
"input": "CCCCCCPPPPPP",
"output": "4"
},
{
"input": "CCCCCCPPCPPPPPPPPPP",
"output": "6"
},
{
"input": "CCCCCCCCCC",
"output": "2"
},
{
"input": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC... | 1,611,302,578 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 307,200 | s=input()
c=[]
ans=0
for i in s:
if len(c)==0:
c.append(i)
elif len(c)!=0 and i=="C" and c[-1]=="P":
ans=ans+1
c=[]
c.append(i)
elif len(c)!=0 and i=="P" and c[-1]=="C":
ans=ans+1
c=[]
c.append(i)
else:
if len(c)==5:
... | Title: Postcards and photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the r... | ```python
s=input()
c=[]
ans=0
for i in s:
if len(c)==0:
c.append(i)
elif len(c)!=0 and i=="C" and c[-1]=="P":
ans=ans+1
c=[]
c.append(i)
elif len(c)!=0 and i=="P" and c[-1]=="C":
ans=ans+1
c=[]
c.append(i)
else:
if len(c)==5... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | 0 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 ... | 1,510,504,422 | 1,722 | Python 3 | OK | TESTS | 31 | 234 | 20,480,000 | n = int(input())
t = list(map(int, input().split()))
r = {0:1} # time visited : room num
m = 1
for time in range(1, n+1):
x = t[time-1] # number written down
if x in r:
r[time] = r.pop(x)
else:
m += 1
r[time] = m
print(m)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages betw... | ```python
n = int(input())
t = list(map(int, input().split()))
r = {0:1} # time visited : room num
m = 1
for time in range(1, n+1):
x = t[time-1] # number written down
if x in r:
r[time] = r.pop(x)
else:
m += 1
r[time] = m
print(m)
``` | 3 | |
883 | G | Orientation of Edges | PROGRAMMING | 1,900 | [
"dfs and similar",
"graphs"
] | null | null | Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex *s* from the graph. Now Vasya wants to create two separate plans:
1. to orient each undirected edge in one of two possible directions to maximiz... | The first line contains three integers *n*, *m* and *s* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*m*<=≤<=3·105, 1<=≤<=*s*<=≤<=*n*) — number of vertices and edges in the graph, and the vertex Vasya has picked.
The following *m* lines contain information about the graph edges. Each line contains three integers *t**i*, *u**i* and *v*... | The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices.
A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan s... | [
"2 2 1\n1 1 2\n2 2 1\n",
"6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3\n"
] | [
"2\n-\n2\n+\n",
"6\n++-\n2\n+-+\n"
] | none | 0 | [
{
"input": "2 2 1\n1 1 2\n2 2 1",
"output": "2\n-\n2\n+"
},
{
"input": "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3",
"output": "6\n++-\n2\n+-+"
},
{
"input": "5 5 5\n2 5 3\n1 2 3\n1 4 5\n2 5 2\n1 2 1",
"output": "4\n++\n1\n--"
},
{
"input": "13 18 9\n2 3 10\n1 12 10\n1 1... | 1,596,468,389 | 2,147,483,647 | PyPy 3 | OK | TESTS | 141 | 2,963 | 69,222,400 | def put():
return map(int, input().split())
def dfs(x,flag=1):
s,vis,ans = [x],[0]*n,['+']*m
vis[x]= 1
while s:
i = s.pop()
for j,k in graph[i]:
if vis[j]==0:
if k*flag<0:
ans[abs(k)-1]='-'
elif k*flag>0:
... | Title: Orientation of Edges
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex *s* from the graph. Now Vasya wants to c... | ```python
def put():
return map(int, input().split())
def dfs(x,flag=1):
s,vis,ans = [x],[0]*n,['+']*m
vis[x]= 1
while s:
i = s.pop()
for j,k in graph[i]:
if vis[j]==0:
if k*flag<0:
ans[abs(k)-1]='-'
elif k*flag>0:
... | 3 | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,480,578,491 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | print(((int(input())//2)-1)//2) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
print(((int(input())//2)-1)//2)
``` | 0 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,663,553,241 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | n, m = (int(i) for i in input().split())
s = set(range(1, m + 1))
for _ in range(n):
x, *y = (int(i) for i in input().split())
for i in y:
s.discard(i)
res = "NO" if s else "YES"
print(res)
| Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n, m = (int(i) for i in input().split())
s = set(range(1, m + 1))
for _ in range(n):
x, *y = (int(i) for i in input().split())
for i in y:
s.discard(i)
res = "NO" if s else "YES"
print(res)
``` | 3 | |
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,698,072,447 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n = int(input())
operation_input = [list(map(str, input().split())) for i in range(n)]
x = 0
operation_plus = [['++X'], ['X++']]
operation_minus = [['--X'], ['X--']]
for i in operation_input:
if i in operation_plus:
x += 1
if i in operation_minus:
x -= 1
print(x) | 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())
operation_input = [list(map(str, input().split())) for i in range(n)]
x = 0
operation_plus = [['++X'], ['X++']]
operation_minus = [['--X'], ['X--']]
for i in operation_input:
if i in operation_plus:
x += 1
if i in operation_minus:
x -= 1
print(x)
``` | 3 | |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,598,853,243 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 966 | 6,963,200 | #!/usr/bin/env python3
if __name__ == "__main__":
n, m = map(int, input().split())
ais = list(map(int, input().split()))
ris = sorted(ais, reverse=True)
ais.sort()
maxx = 0
minn = 0
for _ in range(n):
maxx += ris[0]
ris[0] -= 1
i = 0
while i < m - 1 and ris[i] < ris[i + 1]:
ris[i], ris[i+1] = ris[i+1... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
#!/usr/bin/env python3
if __name__ == "__main__":
n, m = map(int, input().split())
ais = list(map(int, input().split()))
ris = sorted(ais, reverse=True)
ais.sort()
maxx = 0
minn = 0
for _ in range(n):
maxx += ris[0]
ris[0] -= 1
i = 0
while i < m - 1 and ris[i] < ris[i + 1]:
ris[i], ris[i+1]... | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.