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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,699,460,933 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | def do(_):
return sum(int(x) for x in input().split()) > 1
n = range(int(input()))
ans = sum(map(do, n))
print(ans)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
def do(_):
return sum(int(x) for x in input().split()) > 1
n = range(int(input()))
ans = sum(map(do, n))
print(ans)
``` | 3 | |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,531,108,116 | 7,116 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | import sys
n, k, M, D = map(int, sys.stdin.readline().strip().split())
#n = 10000
#k = 11
#D = 1000
#for x in range(1, 100):
# R = n // x
# A = (R + k - 1) // k
# if A > D:
# continue
# print(x, A, A * x)
R = n // M
A = (R + k - 1) // k
best = A * M
if A + 1 <= D:
R2 = k * A + 1
x2 = n //... | Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
import sys
n, k, M, D = map(int, sys.stdin.readline().strip().split())
#n = 10000
#k = 11
#D = 1000
#for x in range(1, 100):
# R = n // x
# A = (R + k - 1) // k
# if A > D:
# continue
# print(x, A, A * x)
R = n // M
A = (R + k - 1) // k
best = A * M
if A + 1 <= D:
R2 = k * A + 1
... | 0 | |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,598,587,564 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 93 | 0 | n=int(input())
print(n-2 if n>2 else n+2)
| Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
n=int(input())
print(n-2 if n>2 else n+2)
``` | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,691,667,967 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | a = input()
a = a.replace("WUB"," ")
b = a.replace(" ","")
print(b)
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
a = input()
a = a.replace("WUB"," ")
b = a.replace(" ","")
print(b)
``` | 0 | |
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd... | 1,679,391,831 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 61 | 1,945,600 | a=list(input())
b=list(input())
a1=sorted(a);b1=sorted(b);la=0;lb=0
la=len(a)
lb=len(b)
m= max(la, lb)
if a==b:
print(-1)
elif m in [0,1]:
print(-1)
else:
print(m)
| Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two ... | ```python
a=list(input())
b=list(input())
a1=sorted(a);b1=sorted(b);la=0;lb=0
la=len(a)
lb=len(b)
m= max(la, lb)
if a==b:
print(-1)
elif m in [0,1]:
print(-1)
else:
print(m)
``` | 3 | |
701 | B | Cells Not Under Attack | PROGRAMMING | 1,200 | [
"data structures",
"math"
] | null | null | Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the col... | Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. | [
"3 3\n1 1\n3 1\n2 2\n",
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n"
] | [
"4 2 0 \n",
"16 9 \n",
"9999800001 \n"
] | On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | 750 | [
{
"input": "3 3\n1 1\n3 1\n2 2",
"output": "4 2 0 "
},
{
"input": "5 2\n1 5\n5 1",
"output": "16 9 "
},
{
"input": "100000 1\n300 400",
"output": "9999800001 "
},
{
"input": "10 4\n2 8\n1 8\n9 8\n6 9",
"output": "81 72 63 48 "
},
{
"input": "30 30\n3 13\n27 23\n18... | 1,626,091,734 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 1,559 | 33,587,200 | rows = set()
columns = set()
n, m = map(int, input().split())
n_rows = 0
n_columns = 0
ans = n*n
for i in range(m):
x, y = map(int, input().split())
if x not in rows:
rows.add(x)
n_rows += 1
if y not in columns:
columns.add(y)
n_columns += 1
print(ans - n*(n_rows + ... | Title: Cells Not Under Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's a... | ```python
rows = set()
columns = set()
n, m = map(int, input().split())
n_rows = 0
n_columns = 0
ans = n*n
for i in range(m):
x, y = map(int, input().split())
if x not in rows:
rows.add(x)
n_rows += 1
if y not in columns:
columns.add(y)
n_columns += 1
print(ans - n*... | 3 | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,488,055,838 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 46 | 4,608,000 | n=int(input(""))
x=int(input(""))
nums=[0,1,2,2,1]
if nums[n]==x: print(0)
elif nums[(n-2)%5]==x: print(1)
else: print(2) | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
n=int(input(""))
x=int(input(""))
nums=[0,1,2,2,1]
if nums[n]==x: print(0)
elif nums[(n-2)%5]==x: print(1)
else: print(2)
``` | -1 | |
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,544,596,901 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 498 | 2,662,400 | n = int(input())
c = []; d = []
for I in range (n):
a, b = map(int, input ().split ())
c.append(a)
d.append(b)
print(min(c.count(1), c.count(0)) + min (d.count(1), d.count(0))) | 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
n = int(input())
c = []; d = []
for I in range (n):
a, b = map(int, input ().split ())
c.append(a)
d.append(b)
print(min(c.count(1), c.count(0)) + min (d.count(1), d.count(0)))
``` | 3 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,679,727,588 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | from math import *
n,x,y=map(int,input().split())
print(ceil((n*y/100)-x)) | Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
from math import *
n,x,y=map(int,input().split())
print(ceil((n*y/100)-x))
``` | 0 | |
616 | A | Comparing Two Long Integers | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can r... | The first line contains a non-negative integer *a*.
The second line contains a non-negative integer *b*.
The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if *a*<=<<=*b* and the symbol ">" if *a*<=><=*b*. If the numbers are equal print the symbol "=". | [
"9\n10\n",
"11\n10\n",
"00012345\n12345\n",
"0123\n9\n",
"0123\n111\n"
] | [
"<\n",
">\n",
"=\n",
">\n",
">\n"
] | none | 0 | [
{
"input": "9\n10",
"output": "<"
},
{
"input": "11\n10",
"output": ">"
},
{
"input": "00012345\n12345",
"output": "="
},
{
"input": "0123\n9",
"output": ">"
},
{
"input": "0123\n111",
"output": ">"
},
{
"input": "9\n9",
"output": "="
},
{
... | 1,639,484,326 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | a = input()
b = input()
i = 0
while a[i] == '0' and i < len(a)-1:
i += 1
a = a[i:]
i = 0
while b[i] == '0' and i < len(b)-1:
i += 1
b = b[i:]
if len(a) == len(b):
ans_found = False
for i in range(len(a)):
if a[i] < b[i]:
ans_found = True
print('<')
... | Title: Comparing Two Long Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use th... | ```python
a = input()
b = input()
i = 0
while a[i] == '0' and i < len(a)-1:
i += 1
a = a[i:]
i = 0
while b[i] == '0' and i < len(b)-1:
i += 1
b = b[i:]
if len(a) == len(b):
ans_found = False
for i in range(len(a)):
if a[i] < b[i]:
ans_found = True
pri... | 0 | |
435 | A | Queue on Bus Stop | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). | Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. | [
"4 3\n2 3 2 1\n",
"3 4\n1 2 1\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "4 3\n2 3 2 1",
"output": "3"
},
{
"input": "3 4\n1 2 1",
"output": "1"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "6 4\n1 3 2 3 4 1",
"output": "5"
},
{
"input": "6 8\n6 1 1 1 4 5",
... | 1,542,881,439 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | import math
a = list(map(int,input().split()))
people = list(map(int,input().split()))
total_group = a[0]
seat_bus = a[1]
max_bus = total_group * seat_bus
check = 0
loop = math.ceil(total_group)
##sums = sum(people)
skip = False
rem = 0
temp = people[0]
prev = 0
cookies = 0
for i in range(0,loop-1):
if temp + ... | Title: Queue on Bus Stop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand... | ```python
import math
a = list(map(int,input().split()))
people = list(map(int,input().split()))
total_group = a[0]
seat_bus = a[1]
max_bus = total_group * seat_bus
check = 0
loop = math.ceil(total_group)
##sums = sum(people)
skip = False
rem = 0
temp = people[0]
prev = 0
cookies = 0
for i in range(0,loop-1):
... | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,632,066,868 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 6,963,200 | def solve():
s = input() + ' '
ans = ''
n = len(s) - 1
i = 0
while(i != n):
if(s[i] == '.'):
ans += '0'
i += 1
continue
if(s[i] == '-' and s[i + 1] == '.'):
ans += '1'
i += 2
continue
el... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
def solve():
s = input() + ' '
ans = ''
n = len(s) - 1
i = 0
while(i != n):
if(s[i] == '.'):
ans += '0'
i += 1
continue
if(s[i] == '-' and s[i + 1] == '.'):
ans += '1'
i += 2
continue
... | 3.95603 |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,435,254,531 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 156 | 307,200 | from itertools import combinations
n = int(input())
a = '101010101010101010'
b = []
for i in range(1,11):
s = list(set(combinations(a,i)))
for j in range(len(s)):
s[j] = int(''.join(s[j]))
b.extend(s)
b = sorted(set(b))
m = len(b)
#print(b)
#print(m)
for i in range(m):
if(b[i] > n):
print(i-1)
exit()
... | Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
from itertools import combinations
n = int(input())
a = '101010101010101010'
b = []
for i in range(1,11):
s = list(set(combinations(a,i)))
for j in range(len(s)):
s[j] = int(''.join(s[j]))
b.extend(s)
b = sorted(set(b))
m = len(b)
#print(b)
#print(m)
for i in range(m):
if(b[i] > n):
print(i-1)
... | 3.919711 |
908 | B | New Year and Buggy Bot | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex... | The first line of input will contain two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50), denoting the dimensions of the maze.
The next *n* lines will contain exactly *m* characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in t... | Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit. | [
"5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012\n",
"6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021\n",
"5 3\n...\n.S.\n###\n.E.\n...\n3\n"
] | [
"1\n",
"14\n",
"0\n"
] | For the first sample, the only valid mapping is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a55361bde12e4223a96f0e1d83b94428f26f02.png" style="max-width: 100.0%;max-height: 100.0%;"/>, where *D* is down, *L* is left, *U* is up, *R* is right. | 750 | [
{
"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012",
"output": "1"
},
{
"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021",
"output": "14"
},
{
"input": "5 3\n...\n.S.\n###\n.E.\n...\n3",
"output": "0"
},
{
"input": "10 10\n.#... | 1,514,749,052 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 62 | 5,529,600 | m, n = map(int, input().split())
arr = []
num = 0
for i in range(m):
a = input()
if 'S' in a:
xs = a.index('S')
ys = i
if 'E' in a:
xe = a.index('E')
ye = i
arr.append(a)
direct = [[1, 0], [-1, 0], [0, 1], [0, -1]]
nums = [int(i) for i in input()]
for i in d... | Title: New Year and Buggy Bot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its star... | ```python
m, n = map(int, input().split())
arr = []
num = 0
for i in range(m):
a = input()
if 'S' in a:
xs = a.index('S')
ys = i
if 'E' in a:
xe = a.index('E')
ye = i
arr.append(a)
direct = [[1, 0], [-1, 0], [0, 1], [0, -1]]
nums = [int(i) for i in input()]
... | 3 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,639,979,627 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 60 | 0 | k=int(input())
a=sorted(list(map(int,input().split())))
i=11
j=0
sum=0
while(sum<k):
sum=sum+a[i]
i-=1
j+=1
print(j)
| Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
k=int(input())
a=sorted(list(map(int,input().split())))
i=11
j=0
sum=0
while(sum<k):
sum=sum+a[i]
i-=1
j+=1
print(j)
``` | 0 | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,696,310,194 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 92 | 0 | #Coder_1_neel
a=int(input())
c=input()
c=c+"0"
cou=0
for i in range(a):
if c[i]==c[i+1]:
cou+=1
print(cou) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
#Coder_1_neel
a=int(input())
c=input()
c=c+"0"
cou=0
for i in range(a):
if c[i]==c[i+1]:
cou+=1
print(cou)
``` | 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,674,467,156 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 77 | 0 | n=int(input())
list=[]
count1=0
count2=0
list+=map(int,input().split())
while len(list)>0:
max1=max(list[0],list[len(list)-1])
count1+=max1
list.remove(max1)
if len(list)>0:
max1=max(list[0],list[len(list)-1])
count2+=max1
list.remove(max1)
print(count1,count2) | 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())
list=[]
count1=0
count2=0
list+=map(int,input().split())
while len(list)>0:
max1=max(list[0],list[len(list)-1])
count1+=max1
list.remove(max1)
if len(list)>0:
max1=max(list[0],list[len(list)-1])
count2+=max1
list.remove(max1)
print(count1,cou... | 3 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,696,537,214 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,867,200 | from sys import stdin, stdout
def main():
n, v, p = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
a_dict = {a[i]: i for i in range(n)}
for i in range(len(b)):
bi = a_dict[b[i]]
v += bi + 1
p += n... | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
from sys import stdin, stdout
def main():
n, v, p = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
a_dict = {a[i]: i for i in range(n)}
for i in range(len(b)):
bi = a_dict[b[i]]
v += bi + 1
... | -1 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,649,522,746 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 0 | card_list = list(input())
minimum_flips = 0
for card in card_list:
if (card.isdigit() and int(card) % 2 != 0) or (card in ['a', 'e', 'i', 'o', 'u']):
minimum_flips += 1
print(minimum_flips)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
card_list = list(input())
minimum_flips = 0
for card in card_list:
if (card.isdigit() and int(card) % 2 != 0) or (card in ['a', 'e', 'i', 'o', 'u']):
minimum_flips += 1
print(minimum_flips)
``` | 3 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,694,886,077 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = 0
b = 0
d = 0
for _ in range(5):
base = list(input().split(" "))
n += 1
if "1" in base:
d = n
a = 0
for i in base:
a += 1
if i == "1":
b = a
break
if (a > 3 ):
a = a - 3
else:
a = 3 - a
if (b > 3 ):
b = ... | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
n = 0
b = 0
d = 0
for _ in range(5):
base = list(input().split(" "))
n += 1
if "1" in base:
d = n
a = 0
for i in base:
a += 1
if i == "1":
b = a
break
if (a > 3 ):
a = a - 3
else:
a = 3 - a
if (b > 3 )... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,634,006,352 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Oct 12 10:06:36 2021
@author: Boush
"""
n = int(input())
s = list(map(int,input().split()))
check = ''
for i in range(1,n-1):
d = (s[i-1]+s[i+1])/2
if s[i]==d:
check = check+'0'
else:check = check+'1'
a = int(check.find('1'))
b = int(c... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 12 10:06:36 2021
@author: Boush
"""
n = int(input())
s = list(map(int,input().split()))
check = ''
for i in range(1,n-1):
d = (s[i-1]+s[i+1])/2
if s[i]==d:
check = check+'0'
else:check = check+'1'
a = int(check.find('1'))
... | 0 |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,687,081,823 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 1,126,400 | from typing import List, Tuple
def kruskal(n: int, edges: List[Tuple[int, int, int]]) -> int:
parent = [i for i in range(n)]
rank = [0] * n
edges.sort(key=lambda x: x[2])
res = 0
for u, v, w in edges:
while u != parent[u]:
u = parent[u]
while v != parent[v]:
... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
from typing import List, Tuple
def kruskal(n: int, edges: List[Tuple[int, int, int]]) -> int:
parent = [i for i in range(n)]
rank = [0] * n
edges.sort(key=lambda x: x[2])
res = 0
for u, v, w in edges:
while u != parent[u]:
u = parent[u]
while v != parent[v]:
... | -1 | |
415 | A | Mashmokh and Lights | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turn... | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*).
It is guaranteed that all lights... | Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off. | [
"5 4\n4 3 1 2\n",
"5 5\n5 4 3 2 1\n"
] | [
"1 1 3 4 4 \n",
"1 2 3 4 5 \n"
] | In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus bu... | 500 | [
{
"input": "5 4\n4 3 1 2",
"output": "1 1 3 4 4 "
},
{
"input": "5 5\n5 4 3 2 1",
"output": "1 2 3 4 5 "
},
{
"input": "16 11\n8 5 12 10 14 2 6 3 15 9 1",
"output": "1 2 2 2 5 5 5 8 8 8 8 8 8 8 8 8 "
},
{
"input": "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 6... | 1,396,799,597 | 797 | Python 3 | OK | TESTS | 31 | 77 | 0 | import sys
file = sys.stdin
__author__ = 'RaiaN'
n, m = file.readline().split(' ')
n = int(n)
m = int(m)
ms = [int(val) for val in file.readline().split(' ')]
dsb = [0]*n
for val in ms:
for i in range(val-1, n):
if dsb[i] == 0:
dsb[i] = val
print(' '.join(str(x) for x in dsb)... | Title: Mashmokh and Lights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. ... | ```python
import sys
file = sys.stdin
__author__ = 'RaiaN'
n, m = file.readline().split(' ')
n = int(n)
m = int(m)
ms = [int(val) for val in file.readline().split(' ')]
dsb = [0]*n
for val in ms:
for i in range(val-1, n):
if dsb[i] == 0:
dsb[i] = val
print(' '.join(str(x) for... | 3 | |
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ... | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and... | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 ... | 1,479,635,914 | 3,214 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<int> > field;
vector<int> left;
vector<int> right;
vector<int> up;
vector<int> down;
field.resize(n);
left.resize(n, m);
right.resize(n, -1);
up.r... | Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to pl... | ```python
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<int> > field;
vector<int> left;
vector<int> right;
vector<int> up;
vector<int> down;
field.resize(n);
left.resize(n, m);
right.resize(n, -1);... | -1 | |
666 | A | Reberland Linguistics | PROGRAMMING | 1,800 | [
"dp",
"implementation",
"strings"
] | null | null | First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.
For example, you should know l... | The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters. | On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes.
Print suffixes in lexicographical (alphabetical) order. | [
"abacabaca\n",
"abaca\n"
] | [
"3\naca\nba\nca\n",
"0\n"
] | The first test was analysed in the problem statement.
In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix. | 500 | [
{
"input": "abacabaca",
"output": "3\naca\nba\nca"
},
{
"input": "abaca",
"output": "0"
},
{
"input": "gzqgchv",
"output": "1\nhv"
},
{
"input": "iosdwvzerqfi",
"output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer"
},
{
"input": "oawtxikrpvfuzugjweki",
"output... | 1,698,494,624 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 102,400 | if __name__ == "__main__":
pass
s = str(input())
s = s[5:]
n = len(s)
arr = []
cash = []
if n == 0 or n == 1: print(0)
elif n == 2:
print(1)
print(s)
elif n == 3:
print(2)
print(s[1:2])
print(s)
else:
s = s[::-1]
arr.append(s[1] + s[0])
for i in range(2, n-1):
if s[i+1] + s[i] n... | Title: Reberland Linguistics
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental kn... | ```python
if __name__ == "__main__":
pass
s = str(input())
s = s[5:]
n = len(s)
arr = []
cash = []
if n == 0 or n == 1: print(0)
elif n == 2:
print(1)
print(s)
elif n == 3:
print(2)
print(s[1:2])
print(s)
else:
s = s[::-1]
arr.append(s[1] + s[0])
for i in range(2, n-1):
if s[i+1... | 0 | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,628,365,026 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 171 | 14,438,400 | #!/bin/python3
def LectureSleep(k, n, theorems, behavior):
# 1 <= k <= n
if k == n:
print(sum(theorems))
return
awakeSum = 0
for i in range(n):
awakeSum += theorems[i]*behavior[i]
sleepSum = 0
for i in range(k):
sleepSum += theorems[i]*(1-behavior[i])
maxSleepSum = sleepSum
for i in ra... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
#!/bin/python3
def LectureSleep(k, n, theorems, behavior):
# 1 <= k <= n
if k == n:
print(sum(theorems))
return
awakeSum = 0
for i in range(n):
awakeSum += theorems[i]*behavior[i]
sleepSum = 0
for i in range(k):
sleepSum += theorems[i]*(1-behavior[i])
maxSleepSum = sleepSum
f... | 3 | |
1,007 | B | Pave the Parallelepiped | PROGRAMMING | 2,400 | [
"bitmasks",
"brute force",
"combinatorics",
"math",
"number theory"
] | null | null | You are given a rectangular parallelepiped with sides of positive integer lengths $A$, $B$ and $C$.
Find the number of different groups of three integers ($a$, $b$, $c$) such that $1\leq a\leq b\leq c$ and parallelepiped $A\times B\times C$ can be paved with parallelepipeds $a\times b\times c$. Note, that all small p... | The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases.
Each of the next $t$ lines contains three integers $A$, $B$ and $C$ ($1 \leq A, B, C \leq 10^5$) — the sizes of the parallelepiped. | For each test case, print the number of different groups of three points that satisfy all given conditions. | [
"4\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n"
] | [
"1\n4\n4\n165\n"
] | In the first test case, rectangular parallelepiped $(1, 1, 1)$ can be only divided into rectangular parallelepiped with sizes $(1, 1, 1)$.
In the second test case, rectangular parallelepiped $(1, 6, 1)$ can be divided into rectangular parallelepipeds with sizes $(1, 1, 1)$, $(1, 1, 2)$, $(1, 1, 3)$ and $(1, 1, 6)$.
I... | 1,000 | [
{
"input": "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100",
"output": "1\n4\n4\n165"
},
{
"input": "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2... | 1,536,048,110 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 3,276,800 | t = int(input())
def solve(n):
res = []
for i in range(1,int(n**0.5)+1):
if n % i == 0:
res.append(i)
res.append(n//i)
return sorted(set(res))
for _ in range(t):
A,B,C = map(int,input().split())
A = solve(A)
B = solve(B)
C = solve(C)
visited = set()
res = 0
for a in A:
for b in B... | Title: Pave the Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular parallelepiped with sides of positive integer lengths $A$, $B$ and $C$.
Find the number of different groups of three integers ($a$, $b$, $c$) such that $1\leq a\leq b\leq c$ and par... | ```python
t = int(input())
def solve(n):
res = []
for i in range(1,int(n**0.5)+1):
if n % i == 0:
res.append(i)
res.append(n//i)
return sorted(set(res))
for _ in range(t):
A,B,C = map(int,input().split())
A = solve(A)
B = solve(B)
C = solve(C)
visited = set()
res = 0
for a in A:
... | 0 | |
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which... | The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. | Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",... | 1,637,506,394 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 295 | 4,608,000 | string = input()
i = 0
j = 0
n = len(string)
string = list(map(int,string))
ans = 0
for i in range(n):
if (string[i])%4 == 0:
ans+=1
if i >=1:
value = string[i-1]*10 + string[i]
if value%4 == 0:
ans += (i)
print(ans)
| Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother... | ```python
string = input()
i = 0
j = 0
n = len(string)
string = list(map(int,string))
ans = 0
for i in range(n):
if (string[i])%4 == 0:
ans+=1
if i >=1:
value = string[i-1]*10 + string[i]
if value%4 == 0:
ans += (i)
print(ans)
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,603,374,173 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,150,400 | s=input()
def diff(a,b):
return sum(i==j for i,j in map(a,b))
print(a.lower() if diff(a,a.lower())<=diff(a,a.upper()) else a.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
def diff(a,b):
return sum(i==j for i,j in map(a,b))
print(a.lower() if diff(a,a.lower())<=diff(a,a.upper()) else a.upper())
``` | -1 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,684,693,723 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 124 | 0 | lines = int(input())
x, y, z = 0, 0, 0
for i in range(lines):
line = list(map(int, input().split()))
x, y, z = x+line[0], y+line[1], z+line[2]
if x == 0 and y == 0 and z == 0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
lines = int(input())
x, y, z = 0, 0, 0
for i in range(lines):
line = list(map(int, input().split()))
x, y, z = x+line[0], y+line[1], z+line[2]
if x == 0 and y == 0 and z == 0:
print("YES")
else:
print("NO")
``` | 3.969 |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,587,565,089 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 109 | 204,800 | a,b,c=[int(i) for i in input().split()]
a*=10
f=1
for i in range(0,10):
if((a+i)%b==0):
print(str(a+i)+"0"*(c-1))
f=0
break
if f==1:
print(-1) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a,b,c=[int(i) for i in input().split()]
a*=10
f=1
for i in range(0,10):
if((a+i)%b==0):
print(str(a+i)+"0"*(c-1))
f=0
break
if f==1:
print(-1)
``` | 3 | |
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n... | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7... | 1,691,116,899 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,867,200 | def judge(mid):
a = mid * sum_B
b = mid * sum_S
c = mid * sum_C
need_B = max(0, a - tmpa)
need_S = max(0, b - tmpb)
need_C = max(0, c - tmpc)
Spend = need_B * sum_a + need_S * sum_b + need_C * sum_c
return Spend <= sum
str_ = input()
sum_B = sum_S = sum_C = 0
for x in str_:
... | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ... | ```python
def judge(mid):
a = mid * sum_B
b = mid * sum_S
c = mid * sum_C
need_B = max(0, a - tmpa)
need_S = max(0, b - tmpb)
need_C = max(0, c - tmpc)
Spend = need_B * sum_a + need_S * sum_b + need_C * sum_c
return Spend <= sum
str_ = input()
sum_B = sum_S = sum_C = 0
for x... | -1 | |
760 | B | Frodo and pillows | PROGRAMMING | 1,500 | [
"binary search",
"greedy"
] | null | null | *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge... | The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. | Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n"
] | [
"2\n",
"4\n",
"3\n"
] | In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third exa... | 1,000 | [
{
"input": "4 6 2",
"output": "2"
},
{
"input": "3 10 3",
"output": "4"
},
{
"input": "3 6 1",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000 1",
"output": "1000000000"
},
{
... | 1,585,881,211 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 307,200 |
n, m , k = [int(i) for i in input().split()]
def get_min_pillow(bed, h):
res = (h-1) * h /2
if bed > h-1:
res += bed - h + 1
elif bed < h-1:
temp = h-1 - bed
res -= temp * (temp + 1)/2
return res
def check(h):
return (get_min_pillow(k-1, h) + h + get_min_pillow(n-k, h))... | Title: Frodo and pillows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma... | ```python
n, m , k = [int(i) for i in input().split()]
def get_min_pillow(bed, h):
res = (h-1) * h /2
if bed > h-1:
res += bed - h + 1
elif bed < h-1:
temp = h-1 - bed
res -= temp * (temp + 1)/2
return res
def check(h):
return (get_min_pillow(k-1, h) + h + get_min_pillo... | 0 | |
989 | B | A Tide of Riverscape | PROGRAMMING | 1,200 | [
"constructive algorithms",
"strings"
] | null | null | "Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks a... | The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' c... | Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)). | [
"10 7\n1.0.1.0.1.\n",
"10 6\n1.0.1.1000\n",
"10 9\n1........1\n"
] | [
"1000100010\n",
"1001101000\n",
"No\n"
] | In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the onl... | 1,000 | [
{
"input": "10 7\n1.0.1.0.1.",
"output": "1000100010"
},
{
"input": "10 6\n1.0.1.1000",
"output": "1001101000"
},
{
"input": "10 9\n1........1",
"output": "No"
},
{
"input": "1 1\n.",
"output": "No"
},
{
"input": "5 1\n0...1",
"output": "00001"
},
{
"i... | 1,528,728,088 | 3,988 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 77 | 0 | def solve(n, p, seq):
if n == p:
fill_all(seq)
else:
for i in range(n - p):
if seq[i] != seq[i + p] and seq[i] != '.' and seq[i + p] != '.':
fill_all(seq)
break
elif seq[i] == '.':
seq[i] = seq[i + p]
fill_al... | Title: A Tide of Riverscape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its... | ```python
def solve(n, p, seq):
if n == p:
fill_all(seq)
else:
for i in range(n - p):
if seq[i] != seq[i + p] and seq[i] != '.' and seq[i + p] != '.':
fill_all(seq)
break
elif seq[i] == '.':
seq[i] = seq[i + p]
... | 0 | |
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid show... | The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov... | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
... | 1,676,766,198 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n,m=map(int,input().split())
x=n+m
y=n*m
if n==m and n>m and n%2==0 and m%2==0:
print('Malvika')
else:
print('Akshat')
| Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid... | ```python
n,m=map(int,input().split())
x=n+m
y=n*m
if n==m and n>m and n%2==0 and m%2==0:
print('Malvika')
else:
print('Akshat')
``` | 0 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,550,741,891 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 140 | 0 | def binary(n):
b = ''
while n > 0:
b = chr(n % 2 + ord('0')) + b
n //= 2
return b
x = '1'
for c in (input()):
if c == '4':
x += '0'
else:
x += '1'
res = 1
cur = 2
y = binary(cur)
while x != y:
cur += 1
res += 1
y = binary(cur)
print(re... | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
def binary(n):
b = ''
while n > 0:
b = chr(n % 2 + ord('0')) + b
n //= 2
return b
x = '1'
for c in (input()):
if c == '4':
x += '0'
else:
x += '1'
res = 1
cur = 2
y = binary(cur)
while x != y:
cur += 1
res += 1
y = binary(cur)... | 3 | |
985 | A | Chess Placing | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .
In one step you can move... | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100, *n* is even) — the size of the chessboard.
The second line of the input contains integer numbers (1<=≤<=*p**i*<=≤<=*n*) — initial positions of the pieces. It is guaranteed that all the positions are distinct. | Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color. | [
"6\n1 2 6\n",
"10\n1 2 3 4 5\n"
] | [
"2\n",
"10\n"
] | In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.
In the second example the possible strategy is to move... | 0 | [
{
"input": "6\n1 2 6",
"output": "2"
},
{
"input": "10\n1 2 3 4 5",
"output": "10"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 ... | 1,546,067,243 | 1,042 | PyPy 3 | OK | TESTS | 27 | 139 | 0 | n = int(input())
m = n - 1
pos = reversed(sorted(map(int,input().split())))
odd = 0;even = 0
for p in pos:
even+=abs(n-p)
n-=2
odd+=abs(m-p)
m-=2
print (min(odd,even))
| Title: Chess Placing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than... | ```python
n = int(input())
m = n - 1
pos = reversed(sorted(map(int,input().split())))
odd = 0;even = 0
for p in pos:
even+=abs(n-p)
n-=2
odd+=abs(m-p)
m-=2
print (min(odd,even))
``` | 3 | |
719 | B | Anatoly and Cockroaches | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectio... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ... | 1,000 | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrb... | 1,579,853,032 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | n=int(input())
s=list(input())
s2=list(s[::])*1
q=[0]*n
q2=[0]*n
for i in range(n-1):
if s[i]==s[i+1]:
q[i+1]=list({'r','b'}-set(s[i+1]))[0]
s[i+1]=list({'r','b'}-set(s[i+1]))[0]
if s2[i]==s2[i+1]:
q2[i]=list({'r','b'}-set(s2[i]))[0]
s2[i]=list({'r','b'}-set(s2[i]))[0]... | Title: Anatoly and Cockroaches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches... | ```python
n=int(input())
s=list(input())
s2=list(s[::])*1
q=[0]*n
q2=[0]*n
for i in range(n-1):
if s[i]==s[i+1]:
q[i+1]=list({'r','b'}-set(s[i+1]))[0]
s[i+1]=list({'r','b'}-set(s[i+1]))[0]
if s2[i]==s2[i+1]:
q2[i]=list({'r','b'}-set(s2[i]))[0]
s2[i]=list({'r','b'}-set(... | 0 | |
817 | A | Treasure Hunt | PROGRAMMING | 1,200 | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be perfo... | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espr... | 0 | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81... | 1,497,615,390 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 62 | 0 | x1,y1,x2,y2=map(int,input().split())
a,b=map(int,input().split())
if (x2-x1)%a==0 and (y2-y1)%b==0:
if ((x2-x1)//a)%2==((y2-y1)//b)%2:
print ("YES")
else:
print ("NO")
else:
print ("NO")
| Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with... | ```python
x1,y1,x2,y2=map(int,input().split())
a,b=map(int,input().split())
if (x2-x1)%a==0 and (y2-y1)%b==0:
if ((x2-x1)//a)%2==((y2-y1)//b)%2:
print ("YES")
else:
print ("NO")
else:
print ("NO")
``` | 3 | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,637,771,807 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s1 = int(input())
s2 = input()
c = 0
i = 0
while i < (s1-1) :
if s2[i]! = s2[i+1] :
c+= 1
i = i+2
else:
i = i+1
D = s1-c
print(D)
| Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
s1 = int(input())
s2 = input()
c = 0
i = 0
while i < (s1-1) :
if s2[i]! = s2[i+1] :
c+= 1
i = i+2
else:
i = i+1
D = s1-c
print(D)
``` | -1 | |
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,600,534,852 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 186 | 307,200 | n , m = map(int , input().split())
c= {}
for _ in range(m):
a , b = map(int , input().split())
c[b] = a
c = sorted(c.items() , key=lambda x:x[0] , reverse = True)
M = 0
for i , t in c:
if n <= 0:
break
s = min(n , t)
M += s*i
n = n-t
print(M) | 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
n , m = map(int , input().split())
c= {}
for _ in range(m):
a , b = map(int , input().split())
c[b] = a
c = sorted(c.items() , key=lambda x:x[0] , reverse = True)
M = 0
for i , t in c:
if n <= 0:
break
s = min(n , t)
M += s*i
n = n-t
print(M)
``` | 0 |
58 | B | Coins | PROGRAMMING | 1,300 | [
"greedy"
] | B. Coins | 2 | 256 | In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d... | The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin. | Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coin... | [
"10\n",
"4\n",
"3\n"
] | [
"10 5 1\n",
"4 2 1\n",
"3 1\n"
] | none | 1,000 | [
{
"input": "10",
"output": "10 5 1"
},
{
"input": "4",
"output": "4 2 1"
},
{
"input": "3",
"output": "3 1"
},
{
"input": "2",
"output": "2 1"
},
{
"input": "5",
"output": "5 1"
},
{
"input": "6",
"output": "6 3 1"
},
{
"input": "7",
"o... | 1,684,438,852 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
arr = [10]
for i in range(n, 0, -1):
for j in range(len(arr)):
if arr[j] % i != 0:
break
if j == len(arr) - 1:
arr.append(i)
arr.remove(arr[0])
print(list(arr))
| Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following... | ```python
n = int(input())
arr = [10]
for i in range(n, 0, -1):
for j in range(len(arr)):
if arr[j] % i != 0:
break
if j == len(arr) - 1:
arr.append(i)
arr.remove(arr[0])
print(list(arr))
``` | 0 |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,685,459,933 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 61 | 154 | 1,638,400 | n = int(input())
a = list(map(int, input().split()))
m = []
for i in range(len(a)):
kol = 0
for j in range(len(a)):
if a[i] == a[j]:
kol += 1
m.append(kol)
print(max(m), len(set(a)))
| Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = int(input())
a = list(map(int, input().split()))
m = []
for i in range(len(a)):
kol = 0
for j in range(len(a)):
if a[i] == a[j]:
kol += 1
m.append(kol)
print(max(m), len(set(a)))
``` | 3.958448 |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,690,883,020 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | # LUOGU_RID: 118467538
def bus_to_udayland(n, seats):
for i in range(n):
if 'OO' in seats[i]:
return "YES", [seat.replace('OO', '++') if seat == 'OO|OX' else seat for seat in seats]
return "NO", []
n = int(input())
seats = [input() for _ in range(n)]
result, modified_seats = bus_t... | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
# LUOGU_RID: 118467538
def bus_to_udayland(n, seats):
for i in range(n):
if 'OO' in seats[i]:
return "YES", [seat.replace('OO', '++') if seat == 'OO|OX' else seat for seat in seats]
return "NO", []
n = int(input())
seats = [input() for _ in range(n)]
result, modified_sea... | 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,649,997,255 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | s= input()
temp= ['h','e','l','l','o']
idx=0
for i in s:
if idx ==0:
if i == temp[idx]:
idx+=1
elif idx < len(temp):
if i == temp[idx]:
idx+=1
elif idx >= len(temp):
print("YES")
break
if idx < len(temp):
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()
temp= ['h','e','l','l','o']
idx=0
for i in s:
if idx ==0:
if i == temp[idx]:
idx+=1
elif idx < len(temp):
if i == temp[idx]:
idx+=1
elif idx >= len(temp):
print("YES")
break
if idx < len(temp):
print("NO")
... | 0 |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,677,495,229 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | soks, mama = map(int,input().split())
day = 0
while soks>0:
soks-=1
day+=1
if day % mama == 0:
print(f'Мама пришла на {day} день')
soks+=1
print(day) | Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
soks, mama = map(int,input().split())
day = 0
while soks>0:
soks-=1
day+=1
if day % mama == 0:
print(f'Мама пришла на {day} день')
soks+=1
print(day)
``` | 0 | |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,585,497,013 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 0 | l=list(map(int,input().split()))
if l[0]%l[1]==0:print((l[2]//l[0]))
elif l[1]%l[0]==0:print((l[2]//l[1]))
else:print(l[2]//(l[0]*l[1])) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
l=list(map(int,input().split()))
if l[0]%l[1]==0:print((l[2]//l[0]))
elif l[1]%l[0]==0:print((l[2]//l[1]))
else:print(l[2]//(l[0]*l[1]))
``` | 0 | |
510 | B | Fox And Two Dots | PROGRAMMING | 1,500 | [
"dfs and similar"
] | null | null | Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50): the number of rows and columns of the board.
Then *n* lines follow, each line contains a string consisting of *m* characters, expressing colors of dots in each line. Each character is an uppercase Latin letter. | Output "Yes" if there exists a cycle, and "No" otherwise. | [
"3 4\nAAAA\nABCA\nAAAA\n",
"3 4\nAAAA\nABCA\nAADA\n",
"4 4\nYYYR\nBYBY\nBBBY\nBBBY\n",
"7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n",
"2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n"
] | In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red). | 1,000 | [
{
"input": "3 4\nAAAA\nABCA\nAAAA",
"output": "Yes"
},
{
"input": "3 4\nAAAA\nABCA\nAADA",
"output": "No"
},
{
"input": "4 4\nYYYR\nBYBY\nBBBY\nBBBY",
"output": "Yes"
},
{
"input": "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB",
"output": "Yes"
},
{
... | 1,682,071,363 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 46 | 512,000 | n, m = map(int, input().split())
# créer une liste pour stocker le terrain
grid = []
for i in range(n):
grid.append(input())
# initialiser les directions possibles
di = [1,-1,0,0]
dj = [0,0,1,-1]
# initialiser une liste pour stocker les cases visitées
visited = [[False]*m for i in range(n)]
# fonc... | Title: Fox And Two Dots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase La... | ```python
n, m = map(int, input().split())
# créer une liste pour stocker le terrain
grid = []
for i in range(n):
grid.append(input())
# initialiser les directions possibles
di = [1,-1,0,0]
dj = [0,0,1,-1]
# initialiser une liste pour stocker les cases visitées
visited = [[False]*m for i in range(n)]... | -1 | |
873 | E | Awards For Contestants | PROGRAMMING | 2,300 | [
"brute force",
"data structures",
"dp"
] | null | null | Alexey recently held a programming contest for students from Berland. *n* students participated in a contest, *i*-th of them solved *a**i* problems. Now he wants to award some contestants. Alexey can award the students with diplomas of three different degrees. Each student either will receive one diploma of some degree... | The first line contains one integer number *n* (3<=≤<=*n*<=≤<=3000).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5000). | Output *n* numbers. *i*-th number must be equal to the degree of diploma *i*-th contestant will receive (or <=-<=1 if he doesn't receive any diploma).
If there are multiple optimal solutions, print any of them. It is guaranteed that the answer always exists. | [
"4\n1 2 3 4\n",
"6\n1 4 3 1 1 2\n"
] | [
"3 3 2 1 \n",
"-1 1 2 -1 -1 3 \n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "3 3 2 1 "
},
{
"input": "6\n1 4 3 1 1 2",
"output": "-1 1 2 -1 -1 3 "
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,512,536,235 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 5,734,400 | import math
def swap(a, i,j):
tmp = a[i]
a[i] = a[j]
a[j] = tmp
def quicksort(a,ind,l,r):
if l >= r: return()
mid = (l+r)//2
midval = a[mid]
left = l
right = r
while (left <= right):
while (a[left] > midval): left += 1
while (a[right] < mi... | Title: Awards For Contestants
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alexey recently held a programming contest for students from Berland. *n* students participated in a contest, *i*-th of them solved *a**i* problems. Now he wants to award some contestants. Alexey can award the st... | ```python
import math
def swap(a, i,j):
tmp = a[i]
a[i] = a[j]
a[j] = tmp
def quicksort(a,ind,l,r):
if l >= r: return()
mid = (l+r)//2
midval = a[mid]
left = l
right = r
while (left <= right):
while (a[left] > midval): left += 1
while (a[r... | 0 | |
960 | D | Full Binary Tree Queries | PROGRAMMING | 2,100 | [
"brute force",
"implementation",
"trees"
] | null | null | You have a full binary tree having infinite levels.
Each node has an initial value. If a node has value *x*, then its left child has value 2·*x* and its right child has value 2·*x*<=+<=1.
The value of the root is 1.
You need to answer *Q* queries.
There are 3 types of queries:
1. Cyclically shift the values of... | The first line contains a single integer *Q* (1<=≤<=*Q*<=≤<=105).
Then *Q* queries follow, one per line:
- Queries of type 1 and 2 have the following format: *T* *X* *K* (1<=≤<=*T*<=≤<=2; 1<=≤<=*X*<=≤<=1018; 0<=≤<=|*K*|<=≤<=1018), where *T* is type of the query.- Queries of type 3 have the following format: 3 *X* (... | For each query of type 3, print the values of all nodes encountered in descending order. | [
"5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8\n",
"5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14\n"
] | [
"12 6 3 1 \n12 6 2 1 \n8 4 2 1 \n",
"14 7 3 1 \n14 6 3 1 \n14 6 2 1 \n"
] | Following are the images of the first 4 levels of the tree in the first test case:
Original:
After query 1 2 1:
After query 2 4 -1: | 2,000 | [
{
"input": "5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8",
"output": "12 6 3 1 \n12 6 2 1 \n8 4 2 1 "
},
{
"input": "5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14",
"output": "14 7 3 1 \n14 6 3 1 \n14 6 2 1 "
},
{
"input": "6\n3 1\n2 1 0\n3 10\n2 1 -4\n3 10\n2 10 -5",
"output": "1 \n10 5 2 1 \n10 5 2 1 "
... | 1,523,460,525 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 7,065,600 | def xtopos(level, x):
cur = x-_2[level]+1
if a[level] < 0:
tmp = abs(a[level])//_2[level]
a[level] = a[level]+tmp*_2[level]
while a[level] < 0:
a[level] = a[level]+_2[level]
a[level] = a[level]%_2[level]
cur = (cur+a[level])%_2[level]
if cur == 0:
cur = _2[level]
... | Title: Full Binary Tree Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a full binary tree having infinite levels.
Each node has an initial value. If a node has value *x*, then its left child has value 2·*x* and its right child has value 2·*x*<=+<=1.
The value of the ro... | ```python
def xtopos(level, x):
cur = x-_2[level]+1
if a[level] < 0:
tmp = abs(a[level])//_2[level]
a[level] = a[level]+tmp*_2[level]
while a[level] < 0:
a[level] = a[level]+_2[level]
a[level] = a[level]%_2[level]
cur = (cur+a[level])%_2[level]
if cur == 0:
cur = ... | 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,691,332,052 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | word = str(input())
if len(word)> 10:
print(word[0] + str(len(word[1:len(word)-1])) + word[-1]) | 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
word = str(input())
if len(word)> 10:
print(word[0] + str(len(word[1:len(word)-1])) + word[-1])
``` | 0 |
859 | B | Lazy Security Guard | PROGRAMMING | 1,000 | [
"brute force",
"geometry",
"math"
] | null | null | Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite ... | Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route. | Print the minimum perimeter that can be achieved. | [
"4\n",
"11\n",
"22\n"
] | [
"8\n",
"14\n",
"20\n"
] | Here are some possible shapes for the examples:
<img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 750 | [
{
"input": "4",
"output": "8"
},
{
"input": "11",
"output": "14"
},
{
"input": "22",
"output": "20"
},
{
"input": "3",
"output": "8"
},
{
"input": "1024",
"output": "128"
},
{
"input": "101",
"output": "42"
},
{
"input": "30",
"output":... | 1,640,117,153 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 93 | 0 | import math
n = int(input())
r = math.ceil(math.sqrt(n))
print(r*2 + math.ceil(n/r)*2) | Title: Lazy Security Guard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is... | ```python
import math
n = int(input())
r = math.ceil(math.sqrt(n))
print(r*2 + math.ceil(n/r)*2)
``` | 3 | |
858 | C | Did you mean... | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"implementation"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 1,500 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx... | 1,508,009,540 | 2,147,483,647 | Python 3 | OK | TESTS | 108 | 62 | 2,150,400 | def check3x(s):
if (s==s[0]*len(s)) or (len(s)<3):
return True
return False
s=input()
c=''
a=s
k=0
for i in range(len(s)):
if s[i] in 'uioea':
c=''
continue
c+=s[i]
if (not check3x(c)) and (c in a):
x=i+k
k+=1
a=a[:x]+' '+a[x:]
... | Title: Did you mean...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (... | ```python
def check3x(s):
if (s==s[0]*len(s)) or (len(s)<3):
return True
return False
s=input()
c=''
a=s
k=0
for i in range(len(s)):
if s[i] in 'uioea':
c=''
continue
c+=s[i]
if (not check3x(c)) and (c in a):
x=i+k
k+=1
a=a[:x]+' '+a[... | 3 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,610,799,595 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 307,200 | n=int(input())
ct=0
while(len(str(n))!=1):
digits=[]
while(n!=0):
r=n%10
n=n//10
digits.append(r)
#print(digits)
n=sum(digits)
ct+=1
print(ct) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
n=int(input())
ct=0
while(len(str(n))!=1):
digits=[]
while(n!=0):
r=n%10
n=n//10
digits.append(r)
#print(digits)
n=sum(digits)
ct+=1
print(ct)
``` | 0 |
558 | E | A Simple Task | PROGRAMMING | 2,300 | [
"data structures",
"sortings",
"strings"
] | null | null | This task is very simple. Given a string *S* of length *n* and *q* queries each query is on the format *i* *j* *k* which means sort the substring consisting of the characters from *i* to *j* in non-decreasing order if *k*<==<=1 or in non-increasing order if *k*<==<=0.
Output the final string after applying the queries... | The first line will contain two integers *n*,<=*q* (1<=≤<=*n*<=≤<=105, 0<=≤<=*q*<=≤<=50<=000), the length of the string and the number of queries respectively.
Next line contains a string *S* itself. It contains only lowercase English letters.
Next *q* lines will contain three integers each *i*,<=*j*,<=*k* (1<=≤<=*i... | Output one line, the string *S* after applying the queries. | [
"10 5\nabacdabcda\n7 10 0\n5 8 1\n1 4 0\n3 6 0\n7 10 1\n",
"10 1\nagjucbvdfk\n1 10 1\n"
] | [
"cbcaaaabdd",
"abcdfgjkuv"
] | First sample test explanation:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3ac4e8cc7e335675a4a2b7b4758bfb3865377cea.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a90b5b03cf59288d8861f0142ecbdf6b12f69e5... | 2,500 | [
{
"input": "10 5\nabacdabcda\n7 10 0\n5 8 1\n1 4 0\n3 6 0\n7 10 1",
"output": "cbcaaaabdd"
},
{
"input": "10 1\nagjucbvdfk\n1 10 1",
"output": "abcdfgjkuv"
},
{
"input": "10 6\nrmaahmdmuo\n1 3 1\n4 6 0\n5 6 1\n7 8 0\n8 10 0\n8 9 1",
"output": "amrmahmoud"
},
{
"input": "10 5\... | 1,437,220,156 | 2,056 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n, q = map(int, input().split(" "))
s = list(input())
for a in range(0, q):
i, j, k = map(int, input().split(" "))
s[i-1:j] = sorted(s[i-1:j], reverse=1-k)
print(s) | Title: A Simple Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This task is very simple. Given a string *S* of length *n* and *q* queries each query is on the format *i* *j* *k* which means sort the substring consisting of the characters from *i* to *j* in non-decreasing order if *k*... | ```python
n, q = map(int, input().split(" "))
s = list(input())
for a in range(0, q):
i, j, k = map(int, input().split(" "))
s[i-1:j] = sorted(s[i-1:j], reverse=1-k)
print(s)
``` | 0 | |
1,010 | A | Fly | PROGRAMMING | 1,500 | [
"binary search",
"math"
] | null | null | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists ... | The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted... | If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct... | [
"2\n12\n11 8\n7 5\n",
"3\n1\n1 4 1\n2 5 3\n",
"6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n"
] | [
"10.0000000000\n",
"-1\n",
"85.4800000000\n"
] | Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fu... | 500 | [
{
"input": "2\n12\n11 8\n7 5",
"output": "10.0000000000"
},
{
"input": "3\n1\n1 4 1\n2 5 3",
"output": "-1"
},
{
"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3",
"output": "85.4800000000"
},
{
"input": "3\n3\n1 2 1\n2 2 2",
"output": "-1"
},
{
"input": "4\n4\n2 3 2 2\n2... | 1,533,189,914 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 109 | 307,200 | rd = lambda: list(map(int, input().split()))
n, m = rd(), rd()[0]
r = m
for x in rd() + rd():
if x > 1:
r *= x
r /= x - 1
else:
print(-1)
exit()
print(r - m)
| Title: Fly
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will ... | ```python
rd = lambda: list(map(int, input().split()))
n, m = rd(), rd()[0]
r = m
for x in rd() + rd():
if x > 1:
r *= x
r /= x - 1
else:
print(-1)
exit()
print(r - m)
``` | 3 | |
999 | B | Reversing Encryption | PROGRAMMING | 900 | [
"implementation"
] | null | null | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algor... | The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. | Print a string $s$ such that the above algorithm results in $t$. | [
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] | [
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\nj... | 1,624,850,637 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 |
n = int(input())
str = list(input())
i = 1
while (i <= n):
if (n%i == 0):
str = list(reversed(str[:i:])) + str[i::]
i += 1
print(''.join(str)) | Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$... | ```python
n = int(input())
str = list(input())
i = 1
while (i <= n):
if (n%i == 0):
str = list(reversed(str[:i:])) + str[i::]
i += 1
print(''.join(str))
``` | 3 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,688,740,396 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,867,200 | import math
n=input()
a=[int(i) for i in input().split()]
c1=a.count(1)
c2=a.count(2)
c3=a.count(3)
c4=a.count(4)
mn13=min(c1,c3)
c1-=mn13;c3-=mn13
mn12=min(c1//2+c1%2,c2)
c1-=(mn12*2);c2-=mn12
ans=c4+c3+mn13+mn12+math.ceil(c1/4)+math.ceil(c2/2)
print(ans) | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
import math
n=input()
a=[int(i) for i in input().split()]
c1=a.count(1)
c2=a.count(2)
c3=a.count(3)
c4=a.count(4)
mn13=min(c1,c3)
c1-=mn13;c3-=mn13
mn12=min(c1//2+c1%2,c2)
c1-=(mn12*2);c2-=mn12
ans=c4+c3+mn13+mn12+math.ceil(c1/4)+math.ceil(c2/2)
print(ans)
``` | -1 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,683,008,081 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 248 | 13,721,600 |
n,t = list(map(int,input().split()))
nums = list(map(int,input().split()))
prefix_sum = [nums[0]]*n
for i in range(1,n):
prefix_sum[i] = prefix_sum[i-1]+nums[i]
# print()
prefix_sum = [0] +prefix_sum
# print(prefix_sum)
def binary_search(i):
save = prefix_sum[i]
i = i-1
j=len(nums)
# print(sa... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n,t = list(map(int,input().split()))
nums = list(map(int,input().split()))
prefix_sum = [nums[0]]*n
for i in range(1,n):
prefix_sum[i] = prefix_sum[i-1]+nums[i]
# print()
prefix_sum = [0] +prefix_sum
# print(prefix_sum)
def binary_search(i):
save = prefix_sum[i]
i = i-1
j=len(nums)
... | 3 | |
765 | A | Neverending competitions | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team ... | In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX"... | If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". | [
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n"
] | [
"home\n",
"contest\n"
] | In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | 500 | [
{
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO",
"output": "home"
},
{
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP",
"output": "contest"
},
{
"input": "1\nESJ\nESJ->TSJ",
"output": "contest"
},
{
"input": "2\nXMR\nFAJ->XMR\nXMR->FAJ",
"output": "home"
},
... | 1,674,311,606 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 46 | 0 | number = int(input())
home = input()
total_out = 0
total_in = 0
for _ in range(number):
if input()[-3:] == home:
total_in += 1
else:
total_out += 1
print(('contest', 'home')[total_in == total_out]) | Title: Neverending competitions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei... | ```python
number = int(input())
home = input()
total_out = 0
total_in = 0
for _ in range(number):
if input()[-3:] == home:
total_in += 1
else:
total_out += 1
print(('contest', 'home')[total_in == total_out])
``` | 3 | |
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C... | 1,390,272,164 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 77 | 3,788,800 | # -*- coding: utf-8 -*-
n = int(input())
if n % 2 == 0:
print(n*n // 2)
print('\n'.join([('C.' if i % 2 == 0 else '.C') * (n//2) for i in range(n)]))
else:
p = n // 2
q = (n+1) // 2
print(p*p + q*q)
print('\n'.join([('C.' * p + 'C') if i % 2 == 0 else ('.C' * p + '.') for i in range(n... | Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or... | ```python
# -*- coding: utf-8 -*-
n = int(input())
if n % 2 == 0:
print(n*n // 2)
print('\n'.join([('C.' if i % 2 == 0 else '.C') * (n//2) for i in range(n)]))
else:
p = n // 2
q = (n+1) // 2
print(p*p + q*q)
print('\n'.join([('C.' * p + 'C') if i % 2 == 0 else ('.C' * p + '.') for i ... | 3 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,688,485,869 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 0 | s=input()
ss=[input() for i in range(10)]
for i in range(0,80,10):
print(ss.index(s[i:i+10]),end='') | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
s=input()
ss=[input() for i in range(10)]
for i in range(0,80,10):
print(ss.index(s[i:i+10]),end='')
``` | 3.969 |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,587,115,126 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 0 | pass_code = input()
int_code = []
password = ''
lst = []
for i in range(0,7):
int_code.append(input())
for i in range(0,7):
for j in range(0,10):
if pass_code[i*10:(i+1)*10] == int_code[j]:
password += str(j+1)
print(password)
| Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
pass_code = input()
int_code = []
password = ''
lst = []
for i in range(0,7):
int_code.append(input())
for i in range(0,7):
for j in range(0,10):
if pass_code[i*10:(i+1)*10] == int_code[j]:
password += str(j+1)
print(password)
``` | -1 |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,694,017,925 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | print('#',%,%,%'):set($.+2):
| Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
print('#',%,%,%'):set($.+2):
``` | -1 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,694,443,840 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 46 | 0 | n,m=map(int,input().split())
key=0
for i in range(n):
row=input().split()
for c in row:
if c=='C'or c=='Y'or c=='M':
key=1
if key==1:
print("#Color")
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n,m=map(int,input().split())
key=0
for i in range(n):
row=input().split()
for c in row:
if c=='C'or c=='Y'or c=='M':
key=1
if key==1:
print("#Color")
else:
print("#Black&White")
``` | 3 | |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,612,244,823 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 624 | 17,510,400 | # cook your dish here
import sys
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(10**6)
n,m=list(map(int,input().split()))
c=list(map(int,input().split()))
d=defaultdict(list)
for i in range(m):
x,y=map(int,input().split())
d[x].append(y)
d[y].append(x)
an... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
# cook your dish here
import sys
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(10**6)
n,m=list(map(int,input().split()))
c=list(map(int,input().split()))
d=defaultdict(list)
for i in range(m):
x,y=map(int,input().split())
d[x].append(y)
d[y].app... | 3 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,626,239,411 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 154 | 21,504,000 | n,m=map(int,input().split());l=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())));mi=102
for i in range(n-1,-1,-1):
k=0
for j in range(n):
if 2*l[j]<=l[i]:k+=1;break
for j in range(n):
if l[i]>=l[j] :k+=1
if k==(n+1):mi=min(l[i],mi)
k=1
for i in b:
if mi<i:pass
else:k=... | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
n,m=map(int,input().split());l=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())));mi=102
for i in range(n-1,-1,-1):
k=0
for j in range(n):
if 2*l[j]<=l[i]:k+=1;break
for j in range(n):
if l[i]>=l[j] :k+=1
if k==(n+1):mi=min(l[i],mi)
k=1
for i in b:
if mi<i:pass... | 0 | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,690,890,176 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 466 | 0 | n = int(input())
g = [-1] * n
for i in range(n):
g[i] = max(-1,int(input())-1)
m = 1
for i in range(n):
if g[i] == -1:
continue
s = g[i]
t = 1
while s != -1:
s = g[s]
t += 1
if t > m: m = t
print(m)
| Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
n = int(input())
g = [-1] * n
for i in range(n):
g[i] = max(-1,int(input())-1)
m = 1
for i in range(n):
if g[i] == -1:
continue
s = g[i]
t = 1
while s != -1:
s = g[s]
t += 1
if t > m: m = t
print(m)
``` | 3 | |
884 | B | Japanese Crosswords Strike Back | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<... | The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output":... | 1,660,949,876 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n, x = input().split(' ')
n, x = int(n), int(x)
string = input()
score = 0
for char in string:
if (char == ' '):
score += 1
else:
score += int(char)
if(score == x):
print('YES')
else:
print('NO')
| Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ... | ```python
n, x = input().split(' ')
n, x = int(n), int(x)
string = input()
score = 0
for char in string:
if (char == ' '):
score += 1
else:
score += int(char)
if(score == x):
print('YES')
else:
print('NO')
``` | 0 | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,566,394,278 | 258 | PyPy 3 | OK | TESTS | 106 | 155 | 1,228,800 | # Contest: Codeforces Round #415 (Div. 2) (https://codeforces.com/contest/810)
# Problem: A: Straight <<A>> (https://codeforces.com/contest/810/problem/A)
def rint():
return int(input())
def rints():
return list(map(int, input().split()))
n, k = rints()
a = rints()
sa = sum(a)
for i in range(20000):
if... | Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
# Contest: Codeforces Round #415 (Div. 2) (https://codeforces.com/contest/810)
# Problem: A: Straight <<A>> (https://codeforces.com/contest/810/problem/A)
def rint():
return int(input())
def rints():
return list(map(int, input().split()))
n, k = rints()
a = rints()
sa = sum(a)
for i in range(2000... | 3 | |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,590,756,193 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 372 | 2,252,800 | import heapq
n = int(input())
arr = [int(x) for x in input().split()]
heap = []
# heap = heapq.heapify(arr)
arr.sort()
i = 0
while i < n-1:
if arr[i+1] - arr[i] > 1:
ans = arr[i]+1
i+=1
if i == n-1:
print(ans)
else:
print(arr[n-1]+1)
| Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
import heapq
n = int(input())
arr = [int(x) for x in input().split()]
heap = []
# heap = heapq.heapify(arr)
arr.sort()
i = 0
while i < n-1:
if arr[i+1] - arr[i] > 1:
ans = arr[i]+1
i+=1
if i == n-1:
print(ans)
else:
print(arr[n-1]+1)
``` | -1 |
505 | A | Mr. Kitayuta's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes... | The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. | If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. | [
"revive\n",
"ee\n",
"kitayuta\n"
] | [
"reviver\n",
"eye",
"NA\n"
] | For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | 500 | [
{
"input": "revive",
"output": "reviver"
},
{
"input": "ee",
"output": "eee"
},
{
"input": "kitayuta",
"output": "NA"
},
{
"input": "evima",
"output": "NA"
},
{
"input": "a",
"output": "aa"
},
{
"input": "yutampo",
"output": "NA"
},
{
"inpu... | 1,578,571,360 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | s = list(input())
l = len(s)
le = s[:l//2]
ri = s[l//2:]
if l&1:
if le == ri[1:][::-1]:
print("".join(le+ri[:1]*2+ri[1:]))
else:
print("NA")
else:
if le[0] != ri[l//2-1]:
ri = ri[1:]
ri.append(le[0])
if le == ri[::-1]:
print("".join(le+... | Title: Mr. Kitayuta's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re... | ```python
s = list(input())
l = len(s)
le = s[:l//2]
ri = s[l//2:]
if l&1:
if le == ri[1:][::-1]:
print("".join(le+ri[:1]*2+ri[1:]))
else:
print("NA")
else:
if le[0] != ri[l//2-1]:
ri = ri[1:]
ri.append(le[0])
if le == ri[::-1]:
print("... | 0 | |
952 | A | Quirky Quantifiers | PROGRAMMING | 800 | [
"math"
] | null | null | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1. | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999). | Output 0 or 1. | [
"13\n",
"927\n",
"48\n"
] | [
"1\n",
"1\n",
"0\n"
] | none | 0 | [
{
"input": "13",
"output": "1"
},
{
"input": "927",
"output": "1"
},
{
"input": "48",
"output": "0"
},
{
"input": "10",
"output": "0"
},
{
"input": "999",
"output": "1"
},
{
"input": "142",
"output": "0"
},
{
"input": "309",
"output": "... | 1,633,877,477 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 77 | 6,758,400 | print([1,0][(int(input()))%2==0]) | Title: Quirky Quantifiers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1.
Input Specification:
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output Specification:
Output 0 or 1.
Demo Input:
['1... | ```python
print([1,0][(int(input()))%2==0])
``` | 3 | |
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer. | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output... | 1,680,182,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | print(1 << int(input()))
#########################################
## ##
## Implemented by brownfox2k6 ##
## ##
######################################### | Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output Specification:
Output a single integer.
De... | ```python
print(1 << int(input()))
#########################################
## ##
## Implemented by brownfox2k6 ##
## ##
#########################################
``` | 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,699,344,813 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | word = (input())
aranan = ["H", "Q", "9"]
lastrng = len(word)
con = 0
for i in range(0,lastrng):
if word[i] in aranan:
con = 1
break
else:
con = 0
if con == 1:
print("YES")
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
word = (input())
aranan = ["H", "Q", "9"]
lastrng = len(word)
con = 0
for i in range(0,lastrng):
if word[i] in aranan:
con = 1
break
else:
con = 0
if con == 1:
print("YES")
else:
print("NO")
``` | 3 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,592,081,510 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 0 | pwr = [int(x) for x in input().split()]
pwr.sort()
mins = 0
# move towards x=y line
while pwr[1] - pwr[0] > 1:
pwr[0] += 1
pwr[1] -= 2
mins += 1
# move in 2-minute steps diagonally
while sum(pwr) > 4:
pwr[0] -= 1
pwr[1] -= 1
mins += 2
# add last minute or two
if pwr[0] == 2:
mins += 1
else... | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
pwr = [int(x) for x in input().split()]
pwr.sort()
mins = 0
# move towards x=y line
while pwr[1] - pwr[0] > 1:
pwr[0] += 1
pwr[1] -= 2
mins += 1
# move in 2-minute steps diagonally
while sum(pwr) > 4:
pwr[0] -= 1
pwr[1] -= 1
mins += 2
# add last minute or two
if pwr[0] == 2:
mins... | 0 | |
688 | A | Opponents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar... | The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th op... | Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. | [
"2 2\n10\n00\n",
"4 1\n0100\n",
"4 5\n1101\n1111\n0110\n1011\n1111\n"
] | [
"2\n",
"1\n",
"2\n"
] | In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | 500 | [
{
"input": "2 2\n10\n00",
"output": "2"
},
{
"input": "4 1\n0100",
"output": "1"
},
{
"input": "4 5\n1101\n1111\n0110\n1011\n1111",
"output": "2"
},
{
"input": "3 2\n110\n110",
"output": "2"
},
{
"input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111... | 1,673,291,525 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 62 | 0 | n,d = map(int,input().split())
schedule = []
for i in range(d):
schedule.append(list(input()))
longest_streak = 0
streak_counter = 0
for day in schedule:
if '0' in day:
streak_counter += 1
if streak_counter > longest_streak:
longest_streak = streak_counter
else:
streak_counter = ... | Title: Opponents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of th... | ```python
n,d = map(int,input().split())
schedule = []
for i in range(d):
schedule.append(list(input()))
longest_streak = 0
streak_counter = 0
for day in schedule:
if '0' in day:
streak_counter += 1
if streak_counter > longest_streak:
longest_streak = streak_counter
else:
streak_... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 0 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx... | 1,506,941,870 | 4,970 | Python 3 | WRONG_ANSWER | TESTS | 6 | 61 | 0 | if __name__ == "__main__":
string = input().lower()
vowels = set("aeiou")
space_indices = []
current_consonant_set = set()
num_consonants = 0
for index, char in enumerate(string):
if char in vowels:
num_consonants = 0
current_consonant_set = set()
else:
current_consonant_set.add(char)
num_consona... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 2... | ```python
if __name__ == "__main__":
string = input().lower()
vowels = set("aeiou")
space_indices = []
current_consonant_set = set()
num_consonants = 0
for index, char in enumerate(string):
if char in vowels:
num_consonants = 0
current_consonant_set = set()
else:
current_consonant_set.add(char)
n... | 0 | |
620 | B | Grandfather Dovlet’s calculator | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | 0 | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "287333... | 1,643,783,006 | 2,147,483,647 | PyPy 3 | OK | TESTS | 11 | 155 | 1,433,600 | a, b = map(int, input().split())
memo = {0: 6, 1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
s = 0
for i in range(a, b + 1):
tmp = i
while tmp:
s += memo[tmp % 10]
tmp //= 10
print(s) | Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](... | ```python
a, b = map(int, input().split())
memo = {0: 6, 1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
s = 0
for i in range(a, b + 1):
tmp = i
while tmp:
s += memo[tmp % 10]
tmp //= 10
print(s)
``` | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,699,367,434 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | t = int(input())
cnt = 0
for i in range(t):
x, y, z = input().split(" ")
if int(x) + int(y) + int(z) >= 2: cnt += 1
print(cnt)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
t = int(input())
cnt = 0
for i in range(t):
x, y, z = input().split(" ")
if int(x) + int(y) + int(z) >= 2: cnt += 1
print(cnt)
``` | 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,697,550,555 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | num = int(input())
x = 0
for i in range(num):
s = input()
if s[1] == "+":
x += 1
else:
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
num = int(input())
x = 0
for i in range(num):
s = input()
if s[1] == "+":
x += 1
else:
x -= 1
print(x)
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,695,905,738 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | a,n,m=int(input()),0,0
x=list(map(int,input().split()))
for j in range(1,len(x)+1):
m=0
for i in x:
m+=1
if i==j and j!=len(x):
print(m,end=" ")
break
elif i==j and j==len(x):
print(m)
break | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
a,n,m=int(input()),0,0
x=list(map(int,input().split()))
for j in range(1,len(x)+1):
m=0
for i in x:
m+=1
if i==j and j!=len(x):
print(m,end=" ")
break
elif i==j and j==len(x):
print(m)
break
``` | 3 | |
920 | F | SUM and REPLACE | PROGRAMMING | 2,000 | [
"brute force",
"data structures",
"dsu",
"number theory"
] | null | null | Let *D*(*x*) be the number of positive divisors of a positive integer *x*. For example, *D*(2)<==<=2 (2 is divisible by 1 and 2), *D*(6)<==<=4 (6 is divisible by 1, 2, 3 and 6).
You are given an array *a* of *n* integers. You have to process two types of queries:
1. REPLACE *l* *r* — for every replace *a**i* with *... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the elements of the array.
Then *m* lines follow, each containin... | For each SUM query print the answer to it. | [
"7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7\n"
] | [
"30\n13\n4\n22\n"
] | none | 0 | [
{
"input": "7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7",
"output": "30\n13\n4\n22"
},
{
"input": "4 2\n1 1 1 3\n1 1 4\n2 1 4",
"output": "5"
},
{
"input": "10 2\n1 1 1 1 1 1 1 1 1 9\n1 1 10\n2 1 10",
"output": "12"
},
{
"input": "4 2\n1 1 3 1\n1 1 4\n2 1 4"... | 1,517,588,165 | 6,065 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <map>
#include <iterator>
#include <unordered_map>
#include <stdio.h>
#include <string>
#include <iomanip>
using namespace std;
typedef long long ll;
#define int long long
const int sze = 1 << 19,... | Title: SUM and REPLACE
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let *D*(*x*) be the number of positive divisors of a positive integer *x*. For example, *D*(2)<==<=2 (2 is divisible by 1 and 2), *D*(6)<==<=4 (6 is divisible by 1, 2, 3 and 6).
You are given an array *a* of *n* intege... | ```python
#include <iostream>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <map>
#include <iterator>
#include <unordered_map>
#include <stdio.h>
#include <string>
#include <iomanip>
using namespace std;
typedef long long ll;
#define int long long
const int sze ... | -1 | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,663,833,656 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 468 | 4,403,200 | x,y,k=map(int,input().split())
p,s=[[0]*(2+x) for i in range(y+2)],0
for i in range(k):
px,py=map(int,input().split())
p[py][px]=1
if all([p[py+1][px],p[py+1][px+1],p[py][px+1]]):
s=1
elif all([p[py-1][px],p[py-1][px+1],p[py][px+1]]):
s=1
elif all([p[py+1][px],p[py+1][px-1... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
x,y,k=map(int,input().split())
p,s=[[0]*(2+x) for i in range(y+2)],0
for i in range(k):
px,py=map(int,input().split())
p[py][px]=1
if all([p[py+1][px],p[py+1][px+1],p[py][px+1]]):
s=1
elif all([p[py-1][px],p[py-1][px+1],p[py][px+1]]):
s=1
elif all([p[py+1][px],p[... | 3 | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,691,351,065 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 93 | 2,560,000 | # https://codeforces.com/problemset/problem/189/A
# A. Cut Ribbon
n, a, b, c = map(int, input().split(" "))
ans = 0
for i in range(n+1):
for j in range(n+1 - i):
k = n - i - j
if i%a == 0 and j%b == 0 and k%c == 0:
s = i/a + j/b + k/c
if s > ans:
ans = s
print(in... | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
# https://codeforces.com/problemset/problem/189/A
# A. Cut Ribbon
n, a, b, c = map(int, input().split(" "))
ans = 0
for i in range(n+1):
for j in range(n+1 - i):
k = n - i - j
if i%a == 0 and j%b == 0 and k%c == 0:
s = i/a + j/b + k/c
if s > ans:
ans = s
... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,632,077,138 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 154 | 6,963,200 | s=int(input())
m=0
n=0
o=0
for i in range(s):
l=input()
x,y,z=map(int,l.split(' '))
m=m+x
n=n+y
o=o+z
if m==0 and n==0 and o==0:
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
s=int(input())
m=0
n=0
o=0
for i in range(s):
l=input()
x,y,z=map(int,l.split(' '))
m=m+x
n=n+y
o=o+z
if m==0 and n==0 and o==0:
print('YES')
else:
print('NO')
``` | 3.94853 |
55 | D | Beautiful numbers | PROGRAMMING | 2,500 | [
"dp",
"number theory"
] | D. Beautiful numbers | 4 | 256 | Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges. | The first line of the input contains the number of cases *t* (1<=≤<=*t*<=≤<=10). Each of the next *t* lines contains two natural numbers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=9<=·1018).
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %... | Output should contain *t* numbers — answers to the queries, one number per line — quantities of beautiful numbers in given intervals (from *l**i* to *r**i*, inclusively). | [
"1\n1 9\n",
"1\n12 15\n"
] | [
"9\n",
"2\n"
] | none | 2,000 | [
{
"input": "1\n1 9",
"output": "9"
},
{
"input": "1\n12 15",
"output": "2"
},
{
"input": "1\n25 53",
"output": "7"
},
{
"input": "1\n1 1000",
"output": "138"
},
{
"input": "1\n1 100000",
"output": "4578"
},
{
"input": "2\n234 59843\n46 3243",
"outp... | 1,559,638,949 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 186 | 0 | def BF(x):
temp=x
count=0
while(x>0):
r=x%10
if((temp%r)==0):
count+=1
x=x//10
if(count==len(str(temp))):
return True
n=int(input())
for i in range(0,n):
l,r=map(int,input().split())
count=0
for i in rang... | Title: Beautiful numbers
Time Limit: 4 seconds
Memory Limit: 256 megabytes
Problem Description:
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count ... | ```python
def BF(x):
temp=x
count=0
while(x>0):
r=x%10
if((temp%r)==0):
count+=1
x=x//10
if(count==len(str(temp))):
return True
n=int(input())
for i in range(0,n):
l,r=map(int,input().split())
count=0
for... | -1 |
586 | B | Laurenty and Shop | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The town where Laurenty lives in is not large. The houses in it are located in two rows, *n* houses in each... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=50) — the number of houses in each row.
Each of the next two lines contains *n*<=-<=1 space-separated integer — values *a**ij* (1<=≤<=*a**ij*<=≤<=100).
The last line contains *n* space-separated integers *b**j* (1<=≤<=*b**j*<=≤<=100). | Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home. | [
"4\n1 2 3\n3 2 1\n3 2 2 3\n",
"3\n1 2\n3 3\n2 1 3\n",
"2\n1\n1\n1 1\n"
] | [
"12\n",
"11\n",
"4\n"
] | The first sample is shown on the figure above.
In the second sample, Laurenty's path can look as follows:
- Laurenty crosses the avenue, the waiting time is 3; - Laurenty uses the second crossing in the first row, the waiting time is 2; - Laurenty uses the first crossing in the first row, the waiting time is 1; ... | 1,000 | [
{
"input": "4\n1 2 3\n3 2 1\n3 2 2 3",
"output": "12"
},
{
"input": "3\n1 2\n3 3\n2 1 3",
"output": "11"
},
{
"input": "2\n1\n1\n1 1",
"output": "4"
},
{
"input": "2\n1\n1\n2 1",
"output": "5"
},
{
"input": "3\n1 100\n1 1\n100 100 100",
"output": "204"
},
... | 1,573,580,937 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | n=int(input())
a=[0] + list(map(int,input().split()))
b= list(map(int,input().split())) + [0]
arr=list(map(int,input().split()))
for i in range(1,n):
a[i]+=a[i-1]
b[-i-1]+=b[-i]
# for i in range(1,n):
# # a[i]+=a[i-1]
# b[-i-1]+=b[-i]
# print(a)
# print(b)
# print(arr)
m=10*... | Title: Laurenty and Shop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The ... | ```python
n=int(input())
a=[0] + list(map(int,input().split()))
b= list(map(int,input().split())) + [0]
arr=list(map(int,input().split()))
for i in range(1,n):
a[i]+=a[i-1]
b[-i-1]+=b[-i]
# for i in range(1,n):
# # a[i]+=a[i-1]
# b[-i-1]+=b[-i]
# print(a)
# print(b)
# print(arr... | 3 | |
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,601,273,667 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 216 | 0 | n = int(input())
wk = [int(_) for _ in input().split()]
n, i = n%sum(wk), 6
if n == 0:
n = sum(wk)
while n > 0:
i = (i+1)%7
n -= wk[i]
print(i+1)
| 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
n = int(input())
wk = [int(_) for _ in input().split()]
n, i = n%sum(wk), 6
if n == 0:
n = sum(wk)
while n > 0:
i = (i+1)%7
n -= wk[i]
print(i+1)
``` | 3 | |
906 | B | Seating of Students | PROGRAMMING | 2,200 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with *n* rows and *m*... | The only line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105; *n*·*m*<=≤<=105) — the number of rows and the number of columns in the required matrix. | If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next *n* lines output *m* integers which form the required matrix. | [
"2 4\n",
"2 1\n"
] | [
"YES\n5 4 7 2 \n3 6 1 8 \n",
"NO\n"
] | In the first test case the matrix initially looks like this:
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | 1,250 | [
{
"input": "2 4",
"output": "YES\n5 4 7 2 \n3 6 1 8 "
},
{
"input": "2 1",
"output": "NO"
},
{
"input": "1 1",
"output": "YES\n1"
},
{
"input": "1 2",
"output": "NO"
},
{
"input": "1 3",
"output": "NO"
},
{
"input": "2 2",
"output": "NO"
},
{
... | 1,514,065,197 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 |
/// The worst problem I've ever seen:(
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const ll maxn = 2e5 + 1000;
const ll mod = 1e9 + 7;
vector < int > a[maxn];
int b[maxn];
map < pair < int , int > , bool > bad;
pair < int ... | Title: Seating of Students
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neigh... | ```python
/// The worst problem I've ever seen:(
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const ll maxn = 2e5 + 1000;
const ll mod = 1e9 + 7;
vector < int > a[maxn];
int b[maxn];
map < pair < int , int > , bool > bad;
p... | -1 | |
988 | B | Substrings Sort | PROGRAMMING | 1,100 | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su... | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | 0 | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "Y... | 1,691,435,646 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
strings = []
for i in range(n):
strings.append(input())
strings = sorted(strings, key=len, reverse=True)
answer = "YES"
for i in range(len(strings)-1):
if strings[i+1] not in strings[i]:
answer = "NO"
print(answer) | Title: Substrings Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String ... | ```python
n = int(input())
strings = []
for i in range(n):
strings.append(input())
strings = sorted(strings, key=len, reverse=True)
answer = "YES"
for i in range(len(strings)-1):
if strings[i+1] not in strings[i]:
answer = "NO"
print(answer)
``` | 0 | |
637 | A | Voting for Photos | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms",
"implementation"
] | null | null | After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like. | Print the identifier of the photo which won the elections. | [
"5\n1 3 2 2 1\n",
"9\n100 200 300 200 100 300 300 100 200\n"
] | [
"2\n",
"300\n"
] | In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
- more likes than the photo with id 3; - as many likes as the photo with id 1, but t... | 500 | [
{
"input": "5\n1 3 2 2 1",
"output": "2"
},
{
"input": "9\n100 200 300 200 100 300 300 100 200",
"output": "300"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "5\n1 3 4 2 2",
"output": "2"
},
{
"input... | 1,622,772,299 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | x = int(input())
x2 = input()
a = 0
raw_num = [] # 1 3 2 2 1
unraw_num = []
z = []
for i in x2.split(" "):
raw_num.append(i)
while x > a :
y = x2.split()
unraw_num.append(y.count(y[0]))
a += 1
v = 0
for i in raw_num:
if raw_num[v][0] == str(unraw_num[-1]):
z.append (... | Title: Voting for Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rule... | ```python
x = int(input())
x2 = input()
a = 0
raw_num = [] # 1 3 2 2 1
unraw_num = []
z = []
for i in x2.split(" "):
raw_num.append(i)
while x > a :
y = x2.split()
unraw_num.append(y.count(y[0]))
a += 1
v = 0
for i in raw_num:
if raw_num[v][0] == str(unraw_num[-1]):
... | 0 | |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on... | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4... | 1,620,382,434 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 6,963,200 | # import math
n=int(input())
#r1,c1,r2,c2 = map(int, input().strip().split(' '))
#lst = list(map(int, input().strip().split(' ')))
d=-1
s=n//2
if n%4==0:
d=0
elif n%2!=0:
d=n//2+1
s=n//2+1
else:
d=1
print(d)
##
if n==1:
print(s,0,end=" ")
elif n==2:
print(s,1,end=" ")
elif n==... | Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help P... | ```python
# import math
n=int(input())
#r1,c1,r2,c2 = map(int, input().strip().split(' '))
#lst = list(map(int, input().strip().split(' ')))
d=-1
s=n//2
if n%4==0:
d=0
elif n%2!=0:
d=n//2+1
s=n//2+1
else:
d=1
print(d)
##
if n==1:
print(s,0,end=" ")
elif n==2:
print(s,1,end=" ")... | 0 | |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,673,544,697 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 514 | 268,390,400 | n, k = list(map(int, input().split()))
a = [1]
new_min_num = 2
for i in range(n - 1):
a.append(new_min_num)
a += a
a = a[:-1]
new_min_num += 1
print(a[k - 1]) | Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
n, k = list(map(int, input().split()))
a = [1]
new_min_num = 2
for i in range(n - 1):
a.append(new_min_num)
a += a
a = a[:-1]
new_min_num += 1
print(a[k - 1])
``` | 0 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,690,002,989 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a, b, c = int(input()), int(input()), int(input())
val = [a, b, c]
_max = max(val)
val.remove(_max)
product = lambda x: x[0] * x[1]
p = product(val)
s = sum(val)
print(_max * (s if s > p else p))
| Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a, b, c = int(input()), int(input()), int(input())
val = [a, b, c]
_max = max(val)
val.remove(_max)
product = lambda x: x[0] * x[1]
p = product(val)
s = sum(val)
print(_max * (s if s > p else p))
``` | 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,610,029,713 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 78 | 0 | s=input()
if 'h' in s and 'e' in s and 'll' in s and 'o' in s:
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()
if 'h' in s and 'e' in s and 'll' in s and 'o' in s:
print('YES')
else: print('NO')
``` | 0 |
386 | B | Fly, freebies, fly! | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation"
] | null | null | Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" — then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis *n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100), where *n* — the number of students shouted "Fly, freebie, fly!" The second line contains *n* positive integers *t**i* (1<=≤<=*t**i*<=≤<=1000).
The last line contains integer *T* (1<=≤<=*T*<=≤<=1000) — the time interval during which the freebie was n... | Print a single integer — the largest number of people who will pass exam tomorrow because of the freebie visit. | [
"6\n4 1 7 8 3 8\n1\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "6\n4 1 7 8 3 8\n1",
"output": "3"
},
{
"input": "4\n4 2 1 5\n2",
"output": "2"
},
{
"input": "10\n4 7 1 3 8 5 2 1 8 4\n3",
"output": "6"
},
{
"input": "8\n39 49 37 28 40 17 50 2\n10",
"output": "3"
},
{
"input": "2\n1 1\n1",
"output": "2"
},
{
... | 1,605,966,160 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | n = int(input())
m = [int(s) for s in input().split()]
t = int(input())
m.sort()
left = 0
right = n
max = 1
while right - left > 1:
middle = (right + left) // 2
sum = 0
for i in range(n - middle):
if m[i + middle] - m[i] <= t:
sum += 1
if max < sum:
left = middl... | Title: Fly, freebies, fly!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" — then flo... | ```python
n = int(input())
m = [int(s) for s in input().split()]
t = int(input())
m.sort()
left = 0
right = n
max = 1
while right - left > 1:
middle = (right + left) // 2
sum = 0
for i in range(n - middle):
if m[i + middle] - m[i] <= t:
sum += 1
if max < sum:
le... | 0 | |
38 | C | Blinds | PROGRAMMING | 1,400 | [
"brute force"
] | C. Blinds | 2 | 256 | The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are *n* blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they ... | The first output line contains two space-separated integers *n* and *l* (1<=≤<=*n*,<=*l*<=≤<=100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated *n* integers *a**i*. They are the lengths of initial stripes in... | Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0. | [
"4 2\n1 2 3 4\n",
"5 3\n5 5 7 3 1\n",
"2 3\n1 2\n"
] | [
"8\n",
"15\n",
"0\n"
] | In the first sample test the required window is 2 × 4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length ... | 0 | [
{
"input": "4 2\n1 2 3 4",
"output": "8"
},
{
"input": "5 3\n5 5 7 3 1",
"output": "15"
},
{
"input": "2 3\n1 2",
"output": "0"
},
{
"input": "2 2\n3 3",
"output": "6"
},
{
"input": "5 2\n2 4 1 1 3",
"output": "8"
},
{
"input": "7 4\n3 2 1 1 1 3 2",
... | 1,660,666,219 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))
ans=0
for i in range (x,101):
s=0
for j in l:
s+=j-j%i
ans=max(s,ans)
print(ans) | Title: Blinds
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are *n* blind stripes with the width of 1 in the factory warehouse for blind production.... | ```python
n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))
ans=0
for i in range (x,101):
s=0
for j in l:
s+=j-j%i
ans=max(s,ans)
print(ans)
``` | 3.977 |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,691,496,060 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n = int(input())
c = 1
if n%4==0 or n%7==0:
print("YES")
c = 3
n = str(n)
l = [i for i in n.rstrip()]
if "4" in l or "7" in l:
print("YES")
else:
print("NO")
| Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
c = 1
if n%4==0 or n%7==0:
print("YES")
c = 3
n = str(n)
l = [i for i in n.rstrip()]
if "4" in l or "7" in l:
print("YES")
else:
print("NO")
``` | 0 | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,696,517,672 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | from sys import stdin
n, _ = map(int, stdin.readline().strip().split())
arr = sorted(map(int, stdin.readline().strip().split()))
q = list(map(int, stdin.readline().strip().split()))
for i in q:
a, b = 0, n-1
while a <= b:
mid = (a+b)//2
if arr[mid] == i:
while mid <= b:
if arr[mid] != i:
break
... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
from sys import stdin
n, _ = map(int, stdin.readline().strip().split())
arr = sorted(map(int, stdin.readline().strip().split()))
q = list(map(int, stdin.readline().strip().split()))
for i in q:
a, b = 0, n-1
while a <= b:
mid = (a+b)//2
if arr[mid] == i:
while mid <= b:
if arr[mid] != i:
... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.