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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,582,642,544 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 124 | 0 | n=int(input())
l=list(map(int,input().split()))
s=list(set(l))
if 0 in s:
s.remove(0)
print(len(s))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n=int(input())
l=list(map(int,input().split()))
s=list(set(l))
if 0 in s:
s.remove(0)
print(len(s))
``` | 3 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,671,748,211 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,764,800 | # توكلت على الله
import sys
input = sys.stdin.readline
def solve():
num = int(input())
color = "RGBOYIV"
pre = "OYIV"*1000
result = color + pre
print(coror[:num:])
for i in range(int(input())):
solve() | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
# توكلت على الله
import sys
input = sys.stdin.readline
def solve():
num = int(input())
color = "RGBOYIV"
pre = "OYIV"*1000
result = color + pre
print(coror[:num:])
for i in range(int(input())):
solve()
``` | -1 |
196 | C | Paint Tree | PROGRAMMING | 2,200 | [
"constructive algorithms",
"divide and conquer",
"geometry",
"sortings",
"trees"
] | null | null | You are given a tree with *n* vertexes and *n* points on a plane, no three points lie on one straight line.
Your task is to paint the given tree on a plane, using the given points as vertexes.
That is, you should correspond each vertex of the tree to exactly one point and each point should correspond to a vertex. If... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1500) — the number of vertexes on a tree (as well as the number of chosen points on the plane).
Each of the next *n*<=-<=1 lines contains two space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the numbers of tree vertexe... | Print *n* distinct space-separated integers from 1 to *n*: the *i*-th number must equal the number of the vertex to place at the *i*-th point (the points are numbered in the order, in which they are listed in the input).
If there are several solutions, print any of them. | [
"3\n1 3\n2 3\n0 0\n1 1\n2 0\n",
"4\n1 2\n2 3\n1 4\n-1 -2\n3 5\n-3 3\n2 0\n"
] | [
"1 3 2\n",
"4 2 1 3\n"
] | The possible solutions for the sample are given below. | 1,500 | [] | 1,692,431,221 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1692431221.2318246")# 1692431221.231841 | Title: Paint Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tree with *n* vertexes and *n* points on a plane, no three points lie on one straight line.
Your task is to paint the given tree on a plane, using the given points as vertexes.
That is, you should correspo... | ```python
print("_RANDOM_GUESS_1692431221.2318246")# 1692431221.231841
``` | 0 | |
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,510,230,158 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 819,200 | def pr(i,n):
if(i%2==0):
x='C'
for i in range(0,n):
print(x,end='')
if(x=='C'):
x='.'
else:
x='C'
else:
x='.'
for i in range(0,n):
print(x,end='')
if(x=='C'):
... | 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
def pr(i,n):
if(i%2==0):
x='C'
for i in range(0,n):
print(x,end='')
if(x=='C'):
x='.'
else:
x='C'
else:
x='.'
for i in range(0,n):
print(x,end='')
if(x=='C'):
... | 0 | |
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,618,043,565 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | a, b, n = [int(x) for x in input().split()]
for i in range(10):
temp = str(a) + str(i)
if(int(temp) % b == 0):
a = temp
break
if(int(a) % b != 0):
a = -1
else:
a = a + ('0'*(n-1))
print(a) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a, b, n = [int(x) for x in input().split()]
for i in range(10):
temp = str(a) + str(i)
if(int(temp) % b == 0):
a = temp
break
if(int(a) % b != 0):
a = -1
else:
a = a + ('0'*(n-1))
print(a)
``` | 3 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,674,652,026 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | if __name__ == '__main__':
n = int(input())
weights = list(map(int, input().split()))
weights.sort(reverse=True)
instability = 0
for ind in range(len(weights)):
for ind1 in range(ind+1,len(weights)):
weight1 = []
weight1.extend(weights[0:ind])
weight1.extend(weights[ind+1:ind1])
weight1.extend(weigh... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
if __name__ == '__main__':
n = int(input())
weights = list(map(int, input().split()))
weights.sort(reverse=True)
instability = 0
for ind in range(len(weights)):
for ind1 in range(ind+1,len(weights)):
weight1 = []
weight1.extend(weights[0:ind])
weight1.extend(weights[ind+1:ind1])
weight1.ex... | 0 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,648,308,091 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | n=int(input())
t=(n//3)*2
print(1+t if n%3 else t) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
n=int(input())
t=(n//3)*2
print(1+t if n%3 else t)
``` | 3 | |
483 | B | Friends and Presents | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the... | The only line contains four positive integers *cnt*1, *cnt*2, *x*, *y* (1<=≤<=*cnt*1,<=*cnt*2<=<<=109; *cnt*1<=+<=*cnt*2<=≤<=109; 2<=≤<=*x*<=<<=*y*<=≤<=3·104) — the numbers that are described in the statement. It is guaranteed that numbers *x*, *y* are prime. | Print a single integer — the answer to the problem. | [
"3 1 2 3\n",
"1 3 2 3\n"
] | [
"5\n",
"4\n"
] | In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first... | 1,000 | [
{
"input": "3 1 2 3",
"output": "5"
},
{
"input": "1 3 2 3",
"output": "4"
},
{
"input": "916200 69682 2 3",
"output": "1832399"
},
{
"input": "808351 17767 433 509",
"output": "826121"
},
{
"input": "8851 901 20897 26183",
"output": "9752"
},
{
"input... | 1,514,666,729 | 2,129 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 5,529,600 | a, b, x, y = map(int, input().split())
p = a / (x - 1)
if p % 1 != 0:
p = (p + 1) // 1
k = p * x - 1
g = b / (y - 1)
if g % 1 != 0:
g = (g + 1) // 1
ans = g * y - 1
print(int(max(ans - (b % (y - 1)), k - (a % (x - 1)))))
| Title: Friends and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented num... | ```python
a, b, x, y = map(int, input().split())
p = a / (x - 1)
if p % 1 != 0:
p = (p + 1) // 1
k = p * x - 1
g = b / (y - 1)
if g % 1 != 0:
g = (g + 1) // 1
ans = g * y - 1
print(int(max(ans - (b % (y - 1)), k - (a % (x - 1)))))
``` | 0 | |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,587,804,647 | 2,147,483,647 | PyPy 3 | OK | TESTS | 78 | 155 | 1,536,000 | n=int(input())
s=input()
x=s.lstrip('<').rstrip('>')
print(n-len(x)) | Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
n=int(input())
s=input()
x=s.lstrip('<').rstrip('>')
print(n-len(x))
``` | 3 | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,656,613,276 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | def solve(info, lst):
consecutive_seconds = info[1]
number_of_words = 0
for indx in range(0, len(lst)-1):
if lst[indx+1] - lst[indx] <= consecutive_seconds:
number_of_words += 1
else:
number_of_words = 1
print(number_of_words)
info = list(map(int, input().split()))
lst ... | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
def solve(info, lst):
consecutive_seconds = info[1]
number_of_words = 0
for indx in range(0, len(lst)-1):
if lst[indx+1] - lst[indx] <= consecutive_seconds:
number_of_words += 1
else:
number_of_words = 1
print(number_of_words)
info = list(map(int, input().split... | 0 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,587,478,703 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 78 | 0 | n, m = map(int, input().split())
c = 0
for i in range(n) :
nums1 = [int(num) for num in input().split()]
for i in range(m) :
if nums1[2*i] == 0 or nums1[(2*i)+1] == 0 :
c = c+1
print(c)
| Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
n, m = map(int, input().split())
c = 0
for i in range(n) :
nums1 = [int(num) for num in input().split()]
for i in range(m) :
if nums1[2*i] == 0 or nums1[(2*i)+1] == 0 :
c = c+1
print(c)
``` | 0 | |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,587,851,615 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | n=int(input())
l=[int(i) for i in input().split()]
z,mi=[],None
if(len(l)==3):
print(l[2]-l[1])
else:
for j in range(n):
if(j>0):
z.append(l[j]-l[j-1])
if(j>1):
if(mi==None):
mi=j-2
elif(z[mi]+z[mi+1]>z[j-2]+z[j-1]):
... | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n=int(input())
l=[int(i) for i in input().split()]
z,mi=[],None
if(len(l)==3):
print(l[2]-l[1])
else:
for j in range(n):
if(j>0):
z.append(l[j]-l[j-1])
if(j>1):
if(mi==None):
mi=j-2
elif(z[mi]+z[mi+1]>z[j-2]+z[j-1]):
... | 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,694,017,072 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | s = input()
# Initialize pointers for "hello" and the input string
hello_ptr = 0
# Iterate through the input string
for char in s:
if char == "hello"[hello_ptr]:
hello_ptr += 1
if hello_ptr == 5: # If we have matched all characters in "hello"
print("YES")
break
... | 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()
# Initialize pointers for "hello" and the input string
hello_ptr = 0
# Iterate through the input string
for char in s:
if char == "hello"[hello_ptr]:
hello_ptr += 1
if hello_ptr == 5: # If we have matched all characters in "hello"
print("YES")
... | 3.977 |
828 | A | Restaurant Tables | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the d... | Print the total number of people the restaurant denies service to. | [
"4 1 2\n1 2 1 1\n",
"4 1 1\n1 1 2 1\n"
] | [
"0\n",
"2\n"
] | In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin... | 500 | [
{
"input": "4 1 2\n1 2 1 1",
"output": "0"
},
{
"input": "4 1 1\n1 1 2 1",
"output": "2"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 1 2\n2 2",
"output": "0"
},
{
"input": "5 1 3\n1 2 2 2 1",
"output": "1"
},
{
"input": "7 6 1\n1 1 1 1 1 1... | 1,621,147,081 | 2,147,483,647 | Python 3 | OK | TESTS | 97 | 124 | 3,788,800 | def checkSat(a, b, l):
OneT = a;
TwoT = b;
ParTwoT = 0;
Satisfied = 0;
for i in range(len(l)):
if(l[i]==1):
if(OneT!=0):
OneT -= 1
Satisfied +=1
else:
if(TwoT!=0):
TwoT -= 1
... | Title: Restaurant Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, i... | ```python
def checkSat(a, b, l):
OneT = a;
TwoT = b;
ParTwoT = 0;
Satisfied = 0;
for i in range(len(l)):
if(l[i]==1):
if(OneT!=0):
OneT -= 1
Satisfied +=1
else:
if(TwoT!=0):
TwoT -= 1
... | 3 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,617,362,500 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 62 | 0 | n, k = map(int, input().split())
a = list(map(int, input().split()))
s = list(set(a))
if len(s) >= k:
print("YES")
for r in range(k):
print(a.index(s[r]) + 1, end=' ')
else:
print("NO") | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = list(set(a))
if len(s) >= k:
print("YES")
for r in range(k):
print(a.index(s[r]) + 1, end=' ')
else:
print("NO")
``` | 3 | |
409 | C | Magnum Opus | PROGRAMMING | 1,700 | [
"*special"
] | null | null | Salve, mi amice.
Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.
Rp:
I Aqua Fortis
I Aqua Regia
II Amalgama
VII Minium
IV Vitriol
Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci... | The first line of input contains several space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100). | Print a single integer. | [
"2 4 6 8 10\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "2 4 6 8 10",
"output": "1"
},
{
"input": "50 27 17 31 89",
"output": "4"
},
{
"input": "50 87 29 81 21",
"output": "5"
},
{
"input": "74 21 36 68 80",
"output": "9"
},
{
"input": "75 82 48 95 12",
"output": "3"
},
{
"input": "41 85 14 43 23... | 1,609,232,753 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 109 | 0 | a,b,c,d,e = map(int,input().split())
print(min(a,b,c // 2,d // 7,e // 4)) | Title: Magnum Opus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Salve, mi amice.
Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.
Rp:
I Aqua Fortis
I Aqua Regia
II Amalgama
VII... | ```python
a,b,c,d,e = map(int,input().split())
print(min(a,b,c // 2,d // 7,e // 4))
``` | 3 | |
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output":... | 1,675,501,720 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 4,300,800 | def main(n):
m = n%7
weeks = n//7
if m==0:
return f'{n//7*2} {n//7*2}'
elif m==2:
return f'{weeks*2} {weeks*2+2}'
elif m>=2 and m<=5:
return f'{weeks*2} {weeks*2+2}'
else:
return f'{weeks*2+1} {weeks*2+2}'
print(main(int(input()))) | Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maxim... | ```python
def main(n):
m = n%7
weeks = n//7
if m==0:
return f'{n//7*2} {n//7*2}'
elif m==2:
return f'{weeks*2} {weeks*2+2}'
elif m>=2 and m<=5:
return f'{weeks*2} {weeks*2+2}'
else:
return f'{weeks*2+1} {weeks*2+2}'
print(main(int(input())))
``` | 0 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,656,861,671 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 78 | 204,800 | a1,a2,a3,a4 = map(int,input().split())
s = input()
c = 0
for i in s:
if i == '1':
c+=a1
if i == '2':
c+=a2
if i == '3':
c+=a3
if i == '4':
c+=a4
print(c) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
a1,a2,a3,a4 = map(int,input().split())
s = input()
c = 0
for i in s:
if i == '1':
c+=a1
if i == '2':
c+=a2
if i == '3':
c+=a3
if i == '4':
c+=a4
print(c)
``` | 3 | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,695,484,953 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 78 | 13,209,600 | class Solution:
def __init__(self):
pass
def solve(self):
n, c = map(int, input().split())
result = 0
milestone = list(map(int, input().split()))
prev = 0
for time in milestone:
if time - prev <= c:
result += 1
else:
result = 1
prev = time
print(result)
if __nam... | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
class Solution:
def __init__(self):
pass
def solve(self):
n, c = map(int, input().split())
result = 0
milestone = list(map(int, input().split()))
prev = 0
for time in milestone:
if time - prev <= c:
result += 1
else:
result = 1
prev = time
print(result)
... | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,637,336,019 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 |
n=int(input())
count=0
for i in range(1,n):
if (n%i) == 0:
count = count + 1
print(count) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
n=int(input())
count=0
for i in range(1,n):
if (n%i) == 0:
count = count + 1
print(count)
``` | 3 | |
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,635,587,487 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 28,364,800 | a = input()
b = input()
x, y = "", ""
while a[0] == "0" or a[-1] == "0":
if a[0] == "0":
a = a[1:]
if a[-1] == "0":
a = a[:-1]
while b[0] == "0" or b[-1] == "0":
if b[0] == "0":
b = b[1:]
if b[-1] == "0":
b = b[:-1]
a, b = int(a), int(b)
if a > b:
print(">")
elif a < b:
prin... | 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()
x, y = "", ""
while a[0] == "0" or a[-1] == "0":
if a[0] == "0":
a = a[1:]
if a[-1] == "0":
a = a[:-1]
while b[0] == "0" or b[-1] == "0":
if b[0] == "0":
b = b[1:]
if b[-1] == "0":
b = b[:-1]
a, b = int(a), int(b)
if a > b:
print(">")
elif a < ... | 0 | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,683,149,651 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a, b = map(int, input().split())
def findGCD(a, b):
if b == 0:
return a
return findGCD(b, a % 2)
print(findGCD(a, b)) | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
a, b = map(int, input().split())
def findGCD(a, b):
if b == 0:
return a
return findGCD(b, a % 2)
print(findGCD(a, b))
``` | 0 | |
68 | A | Irrational problem | PROGRAMMING | 1,100 | [
"implementation",
"number theory"
] | A. Irrational problem | 2 | 256 | Little Petya was given this problem for homework:
You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x*)<==<=*x*.
It is a pity that Petya forgot the order in which the remainders should be taken and wr... | First line of the input will contain 6 integers, separated by spaces: *p*1,<=*p*2,<=*p*3,<=*p*4,<=*a*,<=*b* (1<=≤<=*p*1,<=*p*2,<=*p*3,<=*p*4<=≤<=1000,<=0<=≤<=*a*<=≤<=*b*<=≤<=31415).
It is guaranteed that numbers *p*1,<=*p*2,<=*p*3,<=*p*4 will be pairwise distinct. | Output the number of integers in the given range that have the given property. | [
"2 7 1 8 2 8\n",
"20 30 40 50 0 100\n",
"31 41 59 26 17 43\n"
] | [
"0\n",
"20\n",
"9\n"
] | none | 500 | [
{
"input": "2 7 1 8 2 8",
"output": "0"
},
{
"input": "20 30 40 50 0 100",
"output": "20"
},
{
"input": "31 41 59 26 17 43",
"output": "9"
},
{
"input": "1 2 3 4 0 0",
"output": "1"
},
{
"input": "1 2 3 4 1 1",
"output": "0"
},
{
"input": "1 2 999 1000... | 1,541,700,124 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 218 | 0 | p1,p2,p3,p4,a,b = map(int,input().strip().split())
m=min(min(min(p1,p2),p3),p4)
if m<a:
print(0)
else:
t=(m-a)
if b<m:
t=t-(m-b-1)
print(t)
| Title: Irrational problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya was given this problem for homework:
You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x... | ```python
p1,p2,p3,p4,a,b = map(int,input().strip().split())
m=min(min(min(p1,p2),p3),p4)
if m<a:
print(0)
else:
t=(m-a)
if b<m:
t=t-(m-b-1)
print(t)
``` | 3.9455 |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,694,276,810 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,764,800 | level = set(range(1, int(input()) + 1))
x = list(map(int, input().split()))
x = list(map(int, input().split()))
x = set(x[1:])
y = set(y[1:])
print('I become the guy.' if level - (x | y) == set() else 'Oh, my keyboard!') | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
level = set(range(1, int(input()) + 1))
x = list(map(int, input().split()))
x = list(map(int, input().split()))
x = set(x[1:])
y = set(y[1:])
print('I become the guy.' if level - (x | y) == set() else 'Oh, my keyboard!')
``` | -1 | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,639,939,361 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
numbers = list(map(int , input().split()))
res = sum(numbers)// (n//2)
answers = []
for i in range(len(numbers)):
for j in range(len(numbers)):
if i != j and numbers[i] + numbers[j] == res and j not in answers:
answers.append(i)
answers.append(j)
for i in ra... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
n = int(input())
numbers = list(map(int , input().split()))
res = sum(numbers)// (n//2)
answers = []
for i in range(len(numbers)):
for j in range(len(numbers)):
if i != j and numbers[i] + numbers[j] == res and j not in answers:
answers.append(i)
answers.append(j)
f... | 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,483,451,898 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 4,608,000 | import sys
n, m = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
ans = 0
while a:
s = 0
for i in range(len(a)):
s += a[i]
if s > m:
ans += 1
a = a[i:]
break
else:
ans += 1
break
print(ans)
| 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 sys
n, m = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
ans = 0
while a:
s = 0
for i in range(len(a)):
s += a[i]
if s > m:
ans += 1
a = a[i:]
break
else:
ans += 1
break
print(ans)
``` | 3 | |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t... | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guarant... | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ... | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "3... | 1,488,546,752 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 4,608,000 | n=int(input())
a=[]
ans=0
for i in range(n):
x,y = list(map(int, input().split()))
ans+=y
a.append([x,y])
a.sort()
n=0
p=0
for j in a:
if j[0]<0:
n+=1
else:
p+=1
if abs(n-p)>2:
cnt=abs(n-p)-1
if n<p:
t=n-1
while cnt>0:
#if a[t][0]>0:
#break
ans... | Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree num... | ```python
n=int(input())
a=[]
ans=0
for i in range(n):
x,y = list(map(int, input().split()))
ans+=y
a.append([x,y])
a.sort()
n=0
p=0
for j in a:
if j[0]<0:
n+=1
else:
p+=1
if abs(n-p)>2:
cnt=abs(n-p)-1
if n<p:
t=n-1
while cnt>0:
#if a[t][0]>0:
#break
... | 0 | |
687 | C | The Values You Can Make | PROGRAMMING | 1,900 | [
"dp"
] | null | null | Pari wants to buy an expensive chocolate from Arya. She has *n* coins, the value of the *i*-th coin is *c**i*. The price of the chocolate is *k*, so Pari will take a subset of her coins with sum equal to *k* and give it to Arya.
Looking at her coins, a question came to her mind: after giving the coins to Arya, what va... | The first line contains two integers *n* and *k* (1<=<=≤<=<=*n*,<=*k*<=<=≤<=<=500) — the number of coins and the price of the chocolate, respectively.
Next line will contain *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=500) — the values of Pari's coins.
It's guaranteed that one can make value *k* using t... | First line of the output must contain a single integer *q*— the number of suitable values *x*. Then print *q* integers in ascending order — the values that Arya can make for some subset of coins of Pari that pays for the chocolate. | [
"6 18\n5 6 1 10 12 2\n",
"3 50\n25 25 50\n"
] | [
"16\n0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 \n",
"3\n0 25 50 \n"
] | none | 1,500 | [
{
"input": "6 18\n5 6 1 10 12 2",
"output": "16\n0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 "
},
{
"input": "3 50\n25 25 50",
"output": "3\n0 25 50 "
},
{
"input": "1 79\n79",
"output": "2\n0 79 "
},
{
"input": "1 114\n114",
"output": "2\n0 114 "
},
{
"input": "5 1\n... | 1,604,521,924 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<int>> d(m+1, vector<int>(m+1));
d[0][0] = 1;
vector<int> ans(m);
int a=0, b=0;
for (int i = 0; i < n; i++)
{
cin >> a;
for (int j = m; j >= a; j--)
{
fo... | Title: The Values You Can Make
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari wants to buy an expensive chocolate from Arya. She has *n* coins, the value of the *i*-th coin is *c**i*. The price of the chocolate is *k*, so Pari will take a subset of her coins with sum equal to *k* and... | ```python
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<int>> d(m+1, vector<int>(m+1));
d[0][0] = 1;
vector<int> ans(m);
int a=0, b=0;
for (int i = 0; i < n; i++)
{
cin >> a;
for (int j = m; j >= a; j--)
... | -1 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,655,052,063 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | import sys
input = sys.stdin.readline
def main():
s = input().strip()
hello = 'hello'
hi = 0
if 'h' not in s:
return "NO"
i = s.index('h')
hi +=1
while i < len(s) and hi < len(hello):
if hello[hi] not in s[i:]:
return "NO"
i = s.index(hello[hi], i+1)
... | 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
import sys
input = sys.stdin.readline
def main():
s = input().strip()
hello = 'hello'
hi = 0
if 'h' not in s:
return "NO"
i = s.index('h')
hi +=1
while i < len(s) and hi < len(hello):
if hello[hi] not in s[i:]:
return "NO"
i = s.index(hello[hi... | 0 |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,633,572,571 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,150,400 | n,d=map(int,input().split())
x=list(map(int,input().split()))
ans=[0]*n
for i,j in enumerate(x):
ans+=(i^j)
print(max(ans)) | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
n,d=map(int,input().split())
x=list(map(int,input().split()))
ans=[0]*n
for i,j in enumerate(x):
ans+=(i^j)
print(max(ans))
``` | -1 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,586,035,893 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n = int(input())
string = input()
flights = [char for char in string]
SE_TO_SF = 0
SF_TO_SE = 0
for i in range(len(flights)-1):
if flights[i] == 'S' and flights[i+1] == 'F':
SE_TO_SF+=1
elif flights[i] == 'F' and flights[i+1] == 'S':
SF_TO_SE+=1
else:
pass
if SE_TO_SF > SF_TO_SE:
... | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
n = int(input())
string = input()
flights = [char for char in string]
SE_TO_SF = 0
SF_TO_SE = 0
for i in range(len(flights)-1):
if flights[i] == 'S' and flights[i+1] == 'F':
SE_TO_SF+=1
elif flights[i] == 'F' and flights[i+1] == 'S':
SF_TO_SE+=1
else:
pass
if SE_TO_SF > SF_... | 3 | |
609 | C | Load Balancing | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the differe... | The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server. | Print the minimum number of seconds required to balance the load. | [
"2\n1 6\n",
"7\n10 11 10 11 10 11 11\n",
"5\n1 2 3 4 5\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
... | 0 | [
{
"input": "2\n1 6",
"output": "2"
},
{
"input": "7\n10 11 10 11 10 11 11",
"output": "0"
},
{
"input": "5\n1 2 3 4 5",
"output": "3"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n20000",
... | 1,683,901,888 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input()) # Read the number of servers
tasks = list(map(int, input().split())) # Read the task counts for each server
total_tasks = sum(tasks) # Calculate the total number of tasks
avg_tasks = total_tasks // n # Calculate the average number of tasks per server
min_moves = 0 # Initialize the minimum ... | Title: Load Balancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server... | ```python
n = int(input()) # Read the number of servers
tasks = list(map(int, input().split())) # Read the task counts for each server
total_tasks = sum(tasks) # Calculate the total number of tasks
avg_tasks = total_tasks // n # Calculate the average number of tasks per server
min_moves = 0 # Initialize th... | 0 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,691,036,948 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | n = int(input())
n+=1
while len(str(n)) != len(set(str(n))):
n+=1
print(n) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
n = int(input())
n+=1
while len(str(n)) != len(set(str(n))):
n+=1
print(n)
``` | 3 | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,695,994,805 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a = list(input())
b = len(a)
sum = 0
for i in range(b):
sum+=1
if sum%2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!") | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
a = list(input())
b = len(a)
sum = 0
for i in range(b):
sum+=1
if sum%2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!")
``` | 0 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,599,454,877 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 1,838 | 11,264,000 | n=int(input())
mat=[]
for i in range(n):
l=list(map(int,input().split()))
mat.append(l)
mini=10**10
maxi=0
for i in range(n):
mini=min(mini,mat[i][0])
maxi=max(maxi,mat[i][1])
flag=0
for i in range(n):
if(mat[i][0]==mini and mat[i][1]==maxi):
flag=1
p=i+1
break... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
n=int(input())
mat=[]
for i in range(n):
l=list(map(int,input().split()))
mat.append(l)
mini=10**10
maxi=0
for i in range(n):
mini=min(mini,mat[i][0])
maxi=max(maxi,mat[i][1])
flag=0
for i in range(n):
if(mat[i][0]==mini and mat[i][1]==maxi):
flag=1
p=i+1
... | 3 | |
1 | B | Spreadsheet | PROGRAMMING | 1,600 | [
"implementation",
"math"
] | B. Spreadsheets | 10 | 64 | In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . | Write *n* lines, each line should contain a cell coordinates in the other numeration system. | [
"2\nR23C55\nBC23\n"
] | [
"BC23\nR23C55\n"
] | none | 0 | [
{
"input": "2\nR23C55\nBC23",
"output": "BC23\nR23C55"
},
{
"input": "1\nA1",
"output": "R1C1"
},
{
"input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9",
"output": "C8\nR1C4\nB7\nI8\nI8"
},
{
"input": "4\nR4C25\nR90C35\nAP55\nX83",
"output": "Y4\nAI90\nR55C42\nR83C24"
},
{
"i... | 1,661,776,777 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 92 | 0 | vocablary = {"A": 1,"B": 2,"C": 3,"D": 4,
"E": 5,"F": 6,"G": 7,"H": 8,
"I": 9,"J": 10,"K": 11,"L": 12,
"M": 13,"N": 14,"O": 15,"P": 16,
"Q": 17,"R": 18,"S": 19,"T": 20,
"U": 21,"V": 22,"W": 23,"X": 24,
"Y": 25,"Z": 26
}
letters={
1:"A" ,2:"B" ,3:"C" ,4:"D" ,
5:"E" ,6:"F" ,7:"G" ,8:"H" ,
9:"I" ,10:"J... | Title: Spreadsheet
Time Limit: 10 seconds
Memory Limit: 64 megabytes
Problem Description:
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter n... | ```python
vocablary = {"A": 1,"B": 2,"C": 3,"D": 4,
"E": 5,"F": 6,"G": 7,"H": 8,
"I": 9,"J": 10,"K": 11,"L": 12,
"M": 13,"N": 14,"O": 15,"P": 16,
"Q": 17,"R": 18,"S": 19,"T": 20,
"U": 21,"V": 22,"W": 23,"X": 24,
"Y": 25,"Z": 26
}
letters={
1:"A" ,2:"B" ,3:"C" ,4:"D" ,
5:"E" ,6:"F" ,7:"G" ,8:"H" ,
9:... | -1 |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
}... | 1,599,530,897 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 307,200 | n=int(input())
n1=[]
rate=[]
for i in range(n):
e=list(map(int,input().split()))
n1.append(e[0])
rate.append(e[1])
rate_sort=sorted(rate)
c=0
for i in range(len(rate_sort)):
if(rate_sort[0]==rate[i]):
c+=(sum(n1[i:])*rate_sort[0])
break
else:
c+=(rate[i]*n1[i])
print(c)
... | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her ... | ```python
n=int(input())
n1=[]
rate=[]
for i in range(n):
e=list(map(int,input().split()))
n1.append(e[0])
rate.append(e[1])
rate_sort=sorted(rate)
c=0
for i in range(len(rate_sort)):
if(rate_sort[0]==rate[i]):
c+=(sum(n1[i:])*rate_sort[0])
break
else:
c+=(rate[i]*n1[i])
prin... | 0 | |
776 | G | Sherlock and the Encrypted Data | PROGRAMMING | 2,900 | [
"bitmasks",
"combinatorics",
"dp"
] | null | null | Sherlock found a piece of encrypted data which he thinks will be useful to catch Moriarty. The encrypted data consists of two integer *l* and *r*. He noticed that these integers were in hexadecimal form.
He takes each of the integers from *l* to *r*, and performs the following operations:
1. He lists the distinct dig... | First line contains the integer *q* (1<=≤<=*q*<=≤<=10000).
Each of the next *q* lines contain two hexadecimal integers *l* and *r* (0<=≤<=*l*<=≤<=*r*<=<<=1615).
The hexadecimal integers are written using digits from 0 to 9 and/or lowercase English letters a, b, c, d, e, f.
The hexadecimal integers do not contain ... | Output *q* lines, *i*-th line contains answer to the *i*-th query (in decimal notation). | [
"1\n1014 1014\n",
"2\n1 1e\n1 f\n",
"2\n1 abc\nd0e fe23\n"
] | [
"1\n",
"1\n0\n",
"412\n28464\n"
] | For the second input,
14<sub class="lower-index">16</sub> = 20<sub class="lower-index">10</sub>
*sum* = 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">4</sup> = 18
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fcc2edc423982d6c5d19cc2a89cc99c492aa2427.png" style="max-wid... | 3,250 | [] | 1,689,255,195 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1689255195.552973")# 1689255195.552994 | Title: Sherlock and the Encrypted Data
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock found a piece of encrypted data which he thinks will be useful to catch Moriarty. The encrypted data consists of two integer *l* and *r*. He noticed that these integers were in hexadecimal form.... | ```python
print("_RANDOM_GUESS_1689255195.552973")# 1689255195.552994
``` | 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,565,050,857 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | groups, capacity=map(int,input().split())
buses=1
members=list(map(int,input().split()))
new_capacity=capacity
i=0
while i<groups:
if members[i] <= new_capacity:
new_capacity = new_capacity-members[i]
i=i+1
else:
buses=buses+1
new_capacity=capacity
print(buses)
... | 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
groups, capacity=map(int,input().split())
buses=1
members=list(map(int,input().split()))
new_capacity=capacity
i=0
while i<groups:
if members[i] <= new_capacity:
new_capacity = new_capacity-members[i]
i=i+1
else:
buses=buses+1
new_capacity=capacity
print(buses)
... | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,624,223,951 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 216 | 0 | k=int(input())
s=input()
m={}
for i in s:
m.setdefault(i,0)
m[i]=m[i]+1
l=list(m.values())
r=list(m.keys())
flag=True
#print(l)
for e in l:
if(e%k!=0):
flag=False
break
else:
flag=True
if(flag):
newstring = ""
for j in r:
newstring+=j
str2=new... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k=int(input())
s=input()
m={}
for i in s:
m.setdefault(i,0)
m[i]=m[i]+1
l=list(m.values())
r=list(m.keys())
flag=True
#print(l)
for e in l:
if(e%k!=0):
flag=False
break
else:
flag=True
if(flag):
newstring = ""
for j in r:
newstring+=j
... | 0 | |
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,577,972,568 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 1,014 | 18,636,800 | from collections import deque as d
n, m = map(int, input().split())
col = set()
row = set()
res = d()
for _ in range(m):
x, y = map(int, input().split())
col.add(y)
row.add(x)
res.append(str((n-len(col))*(n-len(row))))
print(" ".join(res))
| 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
from collections import deque as d
n, m = map(int, input().split())
col = set()
row = set()
res = d()
for _ in range(m):
x, y = map(int, input().split())
col.add(y)
row.add(x)
res.append(str((n-len(col))*(n-len(row))))
print(" ".join(res))
``` | 3 | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,672,165,460 | 2,147,483,647 | Python 3 | OK | TESTS | 139 | 327 | 13,926,400 | n = int(input())
a = list(map(int, input().split()))
s = list(map(int, input()))
v = [a[i] for i in range(n)]
i = 0
while i<n-1:
if s[i]==0:
i += 1
continue
fi = i+1
while fi<n-1:
if s[fi]==0:
break
fi += 1
g = sorted(a[i:fi+1])
for j in ra... | Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
n = int(input())
a = list(map(int, input().split()))
s = list(map(int, input()))
v = [a[i] for i in range(n)]
i = 0
while i<n-1:
if s[i]==0:
i += 1
continue
fi = i+1
while fi<n-1:
if s[fi]==0:
break
fi += 1
g = sorted(a[i:fi+1])
f... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,696,436,345 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Wed Oct 4 21:48:50 2023
@author: pranto
"""
from math import ceil
n,m,k=map(int,input().split())
A=ceil(n/k)
B=ceil(m/k)
print(A*B) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 4 21:48:50 2023
@author: pranto
"""
from math import ceil
n,m,k=map(int,input().split())
A=ceil(n/k)
B=ceil(m/k)
print(A*B)
``` | 3.969 |
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,664,276,619 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | word=list(input())
hello=list("hello")
idx=0
last_char=""
for i in range(len(word)):
if (word[i]==hello[idx]):
idx+=1
if (idx==5):
break;
if(idx==5):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
word=list(input())
hello=list("hello")
idx=0
last_char=""
for i in range(len(word)):
if (word[i]==hello[idx]):
idx+=1
if (idx==5):
break;
if(idx==5):
print("YES")
else:
print("NO")
``` | 3.977 |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,684,684,484 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | a = list(map(str, input().split()))
stack = []
count1 = 0
count11 = 0
for i in a:
if i not in stack:
stack.append(i)
else:
count1 += 1
print(count1) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
a = list(map(str, input().split()))
stack = []
count1 = 0
count11 = 0
for i in a:
if i not in stack:
stack.append(i)
else:
count1 += 1
print(count1)
``` | 3 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,595,226,023 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 6,963,200 | n=int(input())
n1=list(map(int,input().split()))
lst=[]
for j in n1:
lst.append(j)
n1.sort()
n1.reverse()
for i in lst:
print(n1.index(i)+1,end=' ')
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n=int(input())
n1=list(map(int,input().split()))
lst=[]
for j in n1:
lst.append(j)
n1.sort()
n1.reverse()
for i in lst:
print(n1.index(i)+1,end=' ')
``` | 3 | |
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fast... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
}... | 1,664,985,876 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 46 | 0 | def solve():
m = int(input())
buttons = list(map(int, input().strip().split()))
countOpen = buttons.count(0)
if (countOpen == 1 and m > 1) or (countOpen == 0 and m == 1):
print("YES")
else:
print("NO")
solve() | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,... | ```python
def solve():
m = int(input())
buttons = list(map(int, input().strip().split()))
countOpen = buttons.count(0)
if (countOpen == 1 and m > 1) or (countOpen == 0 and m == 1):
print("YES")
else:
print("NO")
solve()
``` | 3 | |
76 | E | Points | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | E. Points | 1 | 256 | You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. | The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000<=≤<=*X*,<=*Y*<=≤<=10<=000) — the coordinates of points. Two or more points may coincide. | The only line of output should contain the required sum of squares of distances between all pairs of points. | [
"4\n1 1\n-1 -1\n1 -1\n-1 1\n"
] | [
"32\n"
] | none | 0 | [
{
"input": "4\n1 1\n-1 -1\n1 -1\n-1 1",
"output": "32"
},
{
"input": "1\n6 3",
"output": "0"
},
{
"input": "30\n-7 -12\n-2 5\n14 8\n9 17\n15 -18\n20 6\n20 8\n-13 12\n-4 -20\n-11 -16\n-6 16\n1 -9\n5 -12\n13 -17\n11 5\n8 -9\n-13 5\n19 -13\n-19 -8\n-14 10\n10 3\n-16 -8\n-17 16\n-14 -15\n5 1... | 1,641,819,495 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 9,216,000 | N = int(input())
X = []
Y = []
for i in range(N):
x,y = map(int,input().split())
X.append(x)
Y.append(y)
curr = 0
for i in range(N):
curr += N*(X[i]*X[i] + Y[i]*Y[i])
print(curr - sum(X)**2 - sum(Y)**2)
| Title: Points
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points.
Input Specification:
The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000)... | ```python
N = int(input())
X = []
Y = []
for i in range(N):
x,y = map(int,input().split())
X.append(x)
Y.append(y)
curr = 0
for i in range(N):
curr += N*(X[i]*X[i] + Y[i]*Y[i])
print(curr - sum(X)**2 - sum(Y)**2)
``` | 0 |
755 | C | PolandBall and Forest | PROGRAMMING | 1,300 | [
"dfs and similar",
"dsu",
"graphs",
"interactive",
"trees"
] | null | null | PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with *k* vertices and *k*<=-<=1 edges, where *k* is some integer. Note that one vertex is a valid tree.
There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=104) — the number of Balls living in the forest.
The second line contains a sequence *p*1,<=*p*2,<=...,<=*p**n* of length *n*, where (1<=≤<=*p**i*<=≤<=*n*) holds and *p**i* denotes the most distant from Ball *i* relative living on the same tree. If there are se... | You should output the number of trees in the forest where PolandBall lives. | [
"5\n2 1 5 3 3",
"1\n1\n"
] | [
"2",
"1"
] | In the first sample testcase, possible forest is: 1-2 3-4-5.
There are 2 trees overall.
In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree. | 1,500 | [
{
"input": "5 3\n1 2\n3 4\n4 5",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "5 1\n4 5",
"output": "4"
},
{
"input": "10 3\n2 8\n5 9\n6 10",
"output": "7"
},
{
"input": "18 2\n9 17\n1 18",
"output": "16"
},
{
"input": "1 0",
"out... | 1,598,845,915 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 140 | 22,937,600 | def main():
n = int(input())
relav = list(map(int,input().split()))
trees = dict.fromkeys(range(1,n+1),-1)
for i in range(n):
if trees[relav[i]] == -1:
trees[i+1]=relav[i]
else:
trees[i+1]=trees[relav[i]]
#print(trees)
count = 0
for i in range(1,n+1)... | Title: PolandBall and Forest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with *k* vertices and *k*<=-<=1 edges, where *k* is some integer. Note that one vertex is a val... | ```python
def main():
n = int(input())
relav = list(map(int,input().split()))
trees = dict.fromkeys(range(1,n+1),-1)
for i in range(n):
if trees[relav[i]] == -1:
trees[i+1]=relav[i]
else:
trees[i+1]=trees[relav[i]]
#print(trees)
count = 0
for i in ra... | 3 | |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,623,849,974 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | import math
t=int(input())
k2=[0]*t
s=0
s1=0
for i in range(t):
k=list(map(str,input()))
s=k.count("C")
if math.factorial(s)>1:
s1+=math.factorial(s)
for j in range(t):
if k[j]=="C":
k2[j]+=1
for i in range(t):
s1 += math.factorial(k2[i])
print(s1) | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
import math
t=int(input())
k2=[0]*t
s=0
s1=0
for i in range(t):
k=list(map(str,input()))
s=k.count("C")
if math.factorial(s)>1:
s1+=math.factorial(s)
for j in range(t):
if k[j]=="C":
k2[j]+=1
for i in range(t):
s1 += math.factorial(k2[i])
print(s1... | 0 | |
496 | C | Removing Columns | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table
we obtain the table:
A table is called... | The first line contains two integers — *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Next *n* lines contain *m* small English letters each — the characters of the table. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | [
"1 10\ncodeforces\n",
"4 4\ncase\ncare\ntest\ncode\n",
"5 4\ncode\nforc\nesco\ndefo\nrces\n"
] | [
"0\n",
"2\n",
"4\n"
] | In the first sample the table is already good.
In the second sample you may remove the first and third column.
In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).
Let strings *s* and *t* have equal length. Then, *s* is lexicographica... | 1,750 | [
{
"input": "1 10\ncodeforces",
"output": "0"
},
{
"input": "4 4\ncase\ncare\ntest\ncode",
"output": "2"
},
{
"input": "5 4\ncode\nforc\nesco\ndefo\nrces",
"output": "4"
},
{
"input": "2 2\nfb\nye",
"output": "0"
},
{
"input": "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrz... | 1,646,827,928 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 2,252,800 | n, m = map(int, input().split())
s = [input() for i in range(n)]
f = ['']*(n)
ans = 0
for i in range(m):
t = [f[j]+s[j][i] for j in range(n)]
if t == sorted(t):
f = t
else:
ans += 1
print(ans) | Title: Removing Columns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For e... | ```python
n, m = map(int, input().split())
s = [input() for i in range(n)]
f = ['']*(n)
ans = 0
for i in range(m):
t = [f[j]+s[j][i] for j in range(n)]
if t == sorted(t):
f = t
else:
ans += 1
print(ans)
``` | 3 | |
876 | B | Divisiblity of Differences | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number... | First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=... | If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them... | [
"3 2 3\n1 8 4\n",
"3 3 3\n1 8 4\n",
"4 3 5\n2 7 7 7\n"
] | [
"Yes\n1 4 ",
"No",
"Yes\n2 7 7 "
] | none | 1,000 | [
{
"input": "3 2 3\n1 8 4",
"output": "Yes\n1 4 "
},
{
"input": "3 3 3\n1 8 4",
"output": "No"
},
{
"input": "4 3 5\n2 7 7 7",
"output": "Yes\n2 7 7 "
},
{
"input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825",
"output":... | 1,508,267,464 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 4,608,000 | n,k,m=map(int , input().split())
l=list(map(int,input().split()))
l1=[i%m for i in l]
rem=[l1.count(i) for i in range(m)]
f=-1
for e in range(m):
if rem[e]>=k:
f=e
if f==-1:
print("NO")
else:
g,i=0,0
print("YES")
while(i<n and g<k):
if l1[i]==f:
print(l[i],end=' ')
g+=1
i+=1
| Title: Divisiblity of Differences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be re... | ```python
n,k,m=map(int , input().split())
l=list(map(int,input().split()))
l1=[i%m for i in l]
rem=[l1.count(i) for i in range(m)]
f=-1
for e in range(m):
if rem[e]>=k:
f=e
if f==-1:
print("NO")
else:
g,i=0,0
print("YES")
while(i<n and g<k):
if l1[i]==f:
print(l[i],end=' ')
g+=1
i+=1
``` | 0 | |
61 | D | Eternal Victory | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"greedy",
"shortest paths",
"trees"
] | D. Eternal Victory | 2 | 256 | Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!
He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too ... | First line contains a single natural number *n* (1<=≤<=*n*<=≤<=105) — the amount of cities.
Next *n*<=-<=1 lines contain 3 integer numbers each *x**i*, *y**i* and *w**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=0<=≤<=*w**i*<=≤<=2<=×<=104). *x**i* and *y**i* are two ends of a road and *w**i* is the length of that road. | A single integer number, the minimal length of Shapur's travel.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"3\n1 2 3\n2 3 4\n",
"3\n1 2 3\n1 3 3\n"
] | [
"7\n",
"9\n"
] | none | 2,000 | [
{
"input": "3\n1 2 3\n2 3 4",
"output": "7"
},
{
"input": "3\n1 2 3\n1 3 3",
"output": "9"
},
{
"input": "5\n5 3 60\n4 3 63\n2 1 97\n3 1 14",
"output": "371"
},
{
"input": "3\n2 1 63\n3 1 78",
"output": "204"
},
{
"input": "13\n8 2 58\n2 1 49\n13 10 41\n11 9 67\n6... | 1,685,332,116 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 405 | 40,243,200 | # LUOGU_RID: 111555286
from sys import stdin
input = stdin.readline
def get() :
return map(int,input().split())
def dfs(u, fa) :
f[u] = 0
for v in Map[u].keys() :
if v == fa : continue
dfs(v, u)
f[u] += f[v] + Map[u][v]
def find(u, fa, tot) :
global res
res = ma... | Title: Eternal Victory
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!
He decided to visit a... | ```python
# LUOGU_RID: 111555286
from sys import stdin
input = stdin.readline
def get() :
return map(int,input().split())
def dfs(u, fa) :
f[u] = 0
for v in Map[u].keys() :
if v == fa : continue
dfs(v, u)
f[u] += f[v] + Map[u][v]
def find(u, fa, tot) :
global res
... | 3.823791 |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,644,340,972 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | x = int(input())
s = input()
l = s.split()
l.sort()
r = []
for i in l:
if i not in r:
r.append(int(i))
r.sort()
if len(r) == 1:
print("NO")
else:
print(r[1]) | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
x = int(input())
s = input()
l = s.split()
l.sort()
r = []
for i in l:
if i not in r:
r.append(int(i))
r.sort()
if len(r) == 1:
print("NO")
else:
print(r[1])
``` | 0 |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,695,470,787 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 127,795,200 | number=input().split()
n=int(number[0])
k=int(number[1])
number_new=[]
for i in range(n-n//2):
number_new.append(str(2*i+1))
for ii in range(n//2):
number_new.append(str(2*(ii+1)))
print(number_new[k-1])
| Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
number=input().split()
n=int(number[0])
k=int(number[1])
number_new=[]
for i in range(n-n//2):
number_new.append(str(2*i+1))
for ii in range(n//2):
number_new.append(str(2*(ii+1)))
print(number_new[k-1])
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,696,418,134 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def(n,m,a):
if n>=a and m>=a :
return n%a+m%a
if n>=a and m<a :
return n%a+1
if n<a and m>=a :
return m%a+1
else :
return 1 | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
def(n,m,a):
if n>=a and m>=a :
return n%a+m%a
if n>=a and m<a :
return n%a+1
if n<a and m>=a :
return m%a+1
else :
return 1
``` | -1 |
452 | A | Eevee | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Syl... | First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). | Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). | [
"7\nj......\n",
"7\n...feon\n",
"7\n.l.r.o.\n"
] | [
"jolteon\n",
"leafeon\n",
"flareon\n"
] | Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | 500 | [
{
"input": "7\n...feon",
"output": "leafeon"
},
{
"input": "7\n.l.r.o.",
"output": "flareon"
},
{
"input": "6\n.s..o.",
"output": "espeon"
},
{
"input": "7\nglaceon",
"output": "glaceon"
},
{
"input": "8\n.a.o.e.n",
"output": "vaporeon"
},
{
"input": "... | 1,622,892,760 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 109 | 0 | ar=["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
n=int(input())
p=input()
ar1=[]
for t in ar:
if len(t)==n:
ar1.append(t)
#print(ar1)
s=list(p)
#print(s)
s1=[]
for j in ar1:
if len(j)==n:
c=0
for i in range(n):
if s[... | Title: Eevee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight... | ```python
ar=["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
n=int(input())
p=input()
ar1=[]
for t in ar:
if len(t)==n:
ar1.append(t)
#print(ar1)
s=list(p)
#print(s)
s1=[]
for j in ar1:
if len(j)==n:
c=0
for i in range(n):
... | 3 | |
7 | D | Palindrome Degree | PROGRAMMING | 2,200 | [
"hashing",
"strings"
] | D. Palindrome Degree | 1 | 256 | String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome.
Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For examp... | The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive. | Output the only number — the sum of the polindrome degrees of all the string's prefixes. | [
"a2A\n",
"abacaba\n"
] | [
"1",
"6"
] | none | 0 | [
{
"input": "a2A",
"output": "1"
},
{
"input": "abacaba",
"output": "6"
},
{
"input": "CCeCeCCCee",
"output": "4"
},
{
"input": "opooppppopppopoppopoooppopopooopopppooopppoppoppoppppoooppooooooopppoopoopooooppooooppppppppooopooop",
"output": "3"
},
{
"input": "odri... | 1,526,321,248 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 11 | 902 | 17,510,400 | myStr = input()
hash1 = [0 for i in range(200000)]
powers = [1 for i in range(200000)]
for i in range(1, 200000):
powers[i] = (powers[i - 1] * 127) % 1000000007
hashVal1 = 0
auxHashVal1 = 0
hashVal2 = 0
auxHashVal2 = 0
for i in range(len(myStr)):
hashVal1 = (((hashVal1 * 127) % 1000000007) + (ord(mySt... | Title: Palindrome Degree
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome.
Let's call the pa... | ```python
myStr = input()
hash1 = [0 for i in range(200000)]
powers = [1 for i in range(200000)]
for i in range(1, 200000):
powers[i] = (powers[i - 1] * 127) % 1000000007
hashVal1 = 0
auxHashVal1 = 0
hashVal2 = 0
auxHashVal2 = 0
for i in range(len(myStr)):
hashVal1 = (((hashVal1 * 127) % 1000000007) +... | -1 |
21 | C | Stripe 2 | PROGRAMMING | 2,000 | [
"binary search",
"dp",
"sortings"
] | C. Stripe 2 | 1 | 64 | Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"4\n1 2 3 3\n",
"5\n1 2 3 4 5\n"
] | [
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "1\n-3",
"output": "0"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "3\n0 0 0",
"output": "1"
},
{
"input": "4\n-2 3 3 2",
"output": "0"
},
{
"input": "5\n-6 3 -1 2 -7",
"output": "0"
},
{
"input": "6\n2 3 -3 0 -3 1",
"output": "0... | 1,693,937,546 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 307,200 | N = int(input())
arr = list(map(int, input().split()))
count = 0
prefix = [0] * (N + 1)
for i in range(1, N+1):
prefix[i] = prefix[i-1] + arr[i - 1]
for left in range(1, N-1):
for right in range(left + 1, N):
if prefix[left] - prefix[0] == prefix[right] - prefix[left] == prefix[N] - prefix[right]:
... | Title: Stripe 2
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so tha... | ```python
N = int(input())
arr = list(map(int, input().split()))
count = 0
prefix = [0] * (N + 1)
for i in range(1, N+1):
prefix[i] = prefix[i-1] + arr[i - 1]
for left in range(1, N-1):
for right in range(left + 1, N):
if prefix[left] - prefix[0] == prefix[right] - prefix[left] == prefix[N] - prefix[r... | 0 |
820 | B | Mister B and Angle in Polygon | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"math"
] | null | null | On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must... | First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. | Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. | [
"3 15\n",
"4 67\n",
"4 68\n"
] | [
"1 2 3\n",
"2 1 3\n",
"4 1 2\n"
] | In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: ... | 1,000 | [
{
"input": "3 15",
"output": "2 1 3"
},
{
"input": "4 67",
"output": "2 1 3"
},
{
"input": "4 68",
"output": "2 1 4"
},
{
"input": "3 1",
"output": "2 1 3"
},
{
"input": "3 180",
"output": "2 1 3"
},
{
"input": "100000 1",
"output": "2 1 558"
},
... | 1,584,362,043 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | n, theta = map(int, input().split())
phi = (n-2)*180/n
phi /= n-2
k = round(theta/phi)
k = max(k, 1)
print(f"1 2 {2+k}") | Title: Mister B and Angle in Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *... | ```python
n, theta = map(int, input().split())
phi = (n-2)*180/n
phi /= n-2
k = round(theta/phi)
k = max(k, 1)
print(f"1 2 {2+k}")
``` | 0 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,696,860,226 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | # -*- coding: utf-8 -*-
"""
Created on Mon Oct 9 22:01:50 2023
@author: 刘婉婷 2300012258
"""
x=int(input())
if x%5!=0:
a=(x//5)+1
else:
a=x//5 | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 9 22:01:50 2023
@author: 刘婉婷 2300012258
"""
x=int(input())
if x%5!=0:
a=(x//5)+1
else:
a=x//5
``` | 0 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,576,607,993 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,355,200 | a=input()
b=input()
c=input()
x=[0,0,0]
ans=""
for i in range(3):
if a[1]=="<":
x[ord(a[2])-65]+=1
x[ord(a[0])-65]-=1
else:
x[ord(a[0])-65]+=1
x[ord(a[2])-65]-=1
y=[]
for i in x:
y.append(i)
y.sort()
if y!=[-2,0,2]:
print("Ïmpossible")
else:
for i... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
a=input()
b=input()
c=input()
x=[0,0,0]
ans=""
for i in range(3):
if a[1]=="<":
x[ord(a[2])-65]+=1
x[ord(a[0])-65]-=1
else:
x[ord(a[0])-65]+=1
x[ord(a[2])-65]-=1
y=[]
for i in x:
y.append(i)
y.sort()
if y!=[-2,0,2]:
print("Ïmpossible")
else:
... | -1 |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,581,097,208 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def fun(n):
if n>=1:
for i in range (0 ,int(n/2)+2):
if(i*i==n):
return True
return False
numb=int(input())
if fun(8*numb+1):
print('Yes')
else:
print('No')
| Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
def fun(n):
if n>=1:
for i in range (0 ,int(n/2)+2):
if(i*i==n):
return True
return False
numb=int(input())
if fun(8*numb+1):
print('Yes')
else:
print('No')
... | -1 |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,588,615,218 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 280 | 0 | n, m = [int(_) for _ in input().split()]
tv_sets = [int(_) for _ in input().split()]
tv_sets.sort()
earnings = 0
for tv in tv_sets[:m]:
earnings = min(earnings, earnings + tv)
print(-earnings)
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n, m = [int(_) for _ in input().split()]
tv_sets = [int(_) for _ in input().split()]
tv_sets.sort()
earnings = 0
for tv in tv_sets[:m]:
earnings = min(earnings, earnings + tv)
print(-earnings)
``` | 3.93 |
572 | B | Order Book | PROGRAMMING | 1,300 | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | In this task you need to process a set of stock exchange orders and use them to create order book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready ... | The input starts with two positive integers *n* and *s* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*s*<=≤<=50), the number of orders and the book depth.
Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≤<=*p**i*<=≤<=105) and an integer *q**i* (1<=≤<=*q**i*<=≤<=104) — direction, price and volume resp... | Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input. | [
"6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n"
] | [
"S 50 8\nS 40 1\nB 25 10\nB 20 4\n"
] | Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.
You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders. | 1,000 | [
{
"input": "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10",
"output": "S 50 8\nS 40 1\nB 25 10\nB 20 4"
},
{
"input": "2 1\nB 7523 5589\nS 69799 1711",
"output": "S 69799 1711\nB 7523 5589"
},
{
"input": "1 1\nB 48259 991",
"output": "B 48259 991"
},
{
"input": "1 50\n... | 1,491,168,005 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 61 | 5,529,600 | a=input().split(' ')
lista=[]
lists=[]
for i in range(0,int(a[0])):
b=input()
if b[0]=="B":
lista.append(b.split(' '))
elif b[0]=="S":
lists.append(b.split(' '))
for k in range(0,len(lista)):
for j in range(k+1, len(lista)):
if lista[k][... | Title: Order Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this task you need to process a set of stock exchange orders and use them to create order book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i... | ```python
a=input().split(' ')
lista=[]
lists=[]
for i in range(0,int(a[0])):
b=input()
if b[0]=="B":
lista.append(b.split(' '))
elif b[0]=="S":
lists.append(b.split(' '))
for k in range(0,len(lista)):
for j in range(k+1, len(lista)):
if... | -1 | |
999 | C | Alphabetic Removals | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | 0 | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"i... | 1,653,174,309 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 409,600 | import re
n,k = input().split()
n,k=int(n),int(k)
word=input()
l=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
while k>0:
for i in l:
c=word.count(i)
if k-c>0:
word=word.replace(i,'',word.count(i))
el... | Title: Alphabetic Removals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is... | ```python
import re
n,k = input().split()
n,k=int(n),int(k)
word=input()
l=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
while k>0:
for i in l:
c=word.count(i)
if k-c>0:
word=word.replace(i,'',word.count(i))
... | 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,681,106,767 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 409,600 | #!/bin/python3
import math
import os
import random
import re
import sys
n = int(input())
visited = [0]*2001
for i in range(1, n):
t = int(input())
if t == -1:
visited[i] = 0
else:
visited[i] = visited[t]+1
# print(visited)
print(max(visited)+1)
| 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
#!/bin/python3
import math
import os
import random
import re
import sys
n = int(input())
visited = [0]*2001
for i in range(1, n):
t = int(input())
if t == -1:
visited[i] = 0
else:
visited[i] = visited[t]+1
# print(visited)
print(max(visited)+1)
``` | 0 | |
19 | A | World Football Cup | PROGRAMMING | 1,400 | [
"implementation"
] | A. World Football Cup | 2 | 64 | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features *n* teams (*n* is always even) - the first *n*<=/<=2 t... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=50) — amount of the teams, taking part in the final tournament of World Cup. The following *n* lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following *... | Output *n*<=/<=2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | [
"4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n",
"2\na\nA\na-A 2:1\n"
] | [
"A\nD\n",
"a\n"
] | none | 0 | [
{
"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3",
"output": "A\nD"
},
{
"input": "2\na\nA\na-A 2:1",
"output": "a"
},
{
"input": "2\nEULEUbCmfrmqxtzvg\nuHGRmKUhDcxcfqyruwzen\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92",
"output": "EULEUbCmfrmqxtzvg"... | 1,493,388,200 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 92 | 4,608,000 | n=int(input())
comm={}
for i in range(n):
comm[input()]=[0]*3
for i in range(n*(n-1)//2):
names,scores=input().split()
k=names.find('-')
name1=names[:k]
name2=names[k+1]
k=scores.find(':')
score1=int(scores[:k])
score2=int(scores[k+1:])
comm[name1][2]+=score1
comm[na... | Title: World Football Cup
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup reg... | ```python
n=int(input())
comm={}
for i in range(n):
comm[input()]=[0]*3
for i in range(n*(n-1)//2):
names,scores=input().split()
k=names.find('-')
name1=names[:k]
name2=names[k+1]
k=scores.find(':')
score1=int(scores[:k])
score2=int(scores[k+1:])
comm[name1][2]+=score1
... | -1 |
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,593,590,465 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 109 | 0 | n = int(input())
p = 1
su = 0
while n != 0:
x = n % 10
if x == 4:
su = su + p
else:
su = su + 2*p
p = 2*p
n = n // 10
print(su) | 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
n = int(input())
p = 1
su = 0
while n != 0:
x = n % 10
if x == 4:
su = su + p
else:
su = su + 2*p
p = 2*p
n = n // 10
print(su)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,577,211,331 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 108 | 0 | s = input()
h = 'hello'
r = sorted(h)
v = ''
for i in h:
if i in s:
v = v + i
if v == h :
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()
h = 'hello'
r = sorted(h)
v = ''
for i in h:
if i in s:
v = v + i
if v == h :
print('YES')
else:
print('NO')
``` | 0 |
56 | B | Spoilt Permutation | PROGRAMMING | 1,300 | [
"implementation"
] | B. Spoilt Permutation | 2 | 256 | Vasya collects coins: he has exactly one coin for every year from 1 to *n*. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from *l* to *r* inclusively and put them in the reverse... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000) which is the number of coins in Vasya's collection. The second line contains space-separated *n* integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to *n*, and every... | If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers *l* *r* (1<=≤<=*l*<=<<=*r*<=≤<=*n*) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... *n* the given one. | [
"8\n1 6 5 4 3 2 7 8\n",
"4\n2 3 4 1\n",
"4\n1 2 3 4\n"
] | [
"2 6\n",
"0 0\n",
"0 0\n"
] | none | 1,000 | [
{
"input": "8\n1 6 5 4 3 2 7 8",
"output": "2 6"
},
{
"input": "4\n2 3 4 1",
"output": "0 0"
},
{
"input": "4\n1 2 3 4",
"output": "0 0"
},
{
"input": "8\n1 3 2 4 6 5 7 8",
"output": "0 0"
},
{
"input": "8\n1 3 4 2 6 5 7 8",
"output": "0 0"
},
{
"input... | 1,623,566,847 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 184 | 0 | n = int(input())
A = list(map(int, input().split()))
T = list(range(1, n+1))
for i, a in enumerate(A):
if a != i+1:
break
else:
print(0, 0)
exit()
B = A[0:i]+list(reversed(A[i:a]))+A[a:]
if B == T:
print(i+1, a)
else:
print(0, 0)
| Title: Spoilt Permutation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya collects coins: he has exactly one coin for every year from 1 to *n*. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he... | ```python
n = int(input())
A = list(map(int, input().split()))
T = list(range(1, n+1))
for i, a in enumerate(A):
if a != i+1:
break
else:
print(0, 0)
exit()
B = A[0:i]+list(reversed(A[i:a]))+A[a:]
if B == T:
print(i+1, a)
else:
print(0, 0)
``` | 3.954 |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,695,218,005 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | a1 = input().lower()
a2 = input().lower()
if a1 > a2:
print(1)
elif a1 < a2:
print(-1)
else:
print(0) | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
a1 = input().lower()
a2 = input().lower()
if a1 > a2:
print(1)
elif a1 < a2:
print(-1)
else:
print(0)
``` | 3.977 |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,697,560,202 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | # # n = int(input())
# # m = int(input())
# #
# # # l = [str(i) for i in input().split(",")]
# # l = ['s1 error','s1 error','s1 error']
# #
# # d = {}
# # for i in range(n):
# # d[l[i].split()[0]] = 0
# # ans = 0
# # for i in l:
# # if i.split()[1] == 'error' and d[i.split()[0]] == 2 :
# # a... | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
# # n = int(input())
# # m = int(input())
# #
# # # l = [str(i) for i in input().split(",")]
# # l = ['s1 error','s1 error','s1 error']
# #
# # d = {}
# # for i in range(n):
# # d[l[i].split()[0]] = 0
# # ans = 0
# # for i in l:
# # if i.split()[1] == 'error' and d[i.split()[0]] == 2 :
# #... | -1 | |
638 | A | Home Numbers | PROGRAMMING | 1,100 | [
"*special",
"constructive algorithms",
"math"
] | null | null | The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the pictur... | The first line of the input contains two integers, *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100<=000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even. | Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house *a*. | [
"4 2\n",
"8 5\n"
] | [
"2\n",
"3\n"
] | In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.
The second sample corresponds to picture with *n* = 8. House 5 is the one before last at Vasya's left. | 500 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "8 5",
"output": "3"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "10 1",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "100000 100000",... | 1,689,350,914 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | print("_RANDOM_GUESS_1689350914.774529")# 1689350914.77457 | Title: Home Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are nu... | ```python
print("_RANDOM_GUESS_1689350914.774529")# 1689350914.77457
``` | 0 | |
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ... | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo... | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished... | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
... | 1,499,150,276 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 62 | 5,529,600 | c,v0,v1,a,l = map(int,input().split())
t = v0
k = 1
while t < c:
if v0 >= v1:
v0 = v1
else:
v0 = v0 + a
t = t - l + v0
k += 1
print(k) | Title: Mister B and Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ... | ```python
c,v0,v1,a,l = map(int,input().split())
t = v0
k = 1
while t < c:
if v0 >= v1:
v0 = v1
else:
v0 = v0 + a
t = t - l + v0
k += 1
print(k)
``` | 0 | |
659 | B | Qualifying Contest | PROGRAMMING | 1,300 | [
"constructive algorithms",
"sortings"
] | null | null | Very soon Berland will hold a School Team Programming Olympiad. From each of the *m* Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by *n* Berland students. There were at least two schoolboys participating from each of th... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=10<=000, *n*<=≥<=2*m*) — the number of participants of the qualifying contest and the number of regions in Berland.
Next *n* lines contain the description of the participants of the qualifying contest in the following ... | Print *m* lines. On the *i*-th line print the team of the *i*-th region — the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. | [
"5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503\n",
"5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503\n"
] | [
"Sidorov Ivanov\nAndreev Semenov\n",
"?\nAndreev Semenov\n"
] | In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. | 1,000 | [
{
"input": "5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503",
"output": "Sidorov Ivanov\nAndreev Semenov"
},
{
"input": "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503",
"output": "?\nAndreev Semenov"
},
{
"input": "10 2\nSHiBIEz... | 1,507,538,345 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 545 | 17,203,200 | import operator
class Participant:
def __init__(self,name,point):
self.name=name
self.point=point
n,m=map(int,input().split())
des=[None]*m
for i in range(m):
des[i]=[]
for i in range(n):
name,region,point=input().split()
des[int(region)-1].append(Participant(name,int(point)))
results=['?']*m
... | Title: Qualifying Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Very soon Berland will hold a School Team Programming Olympiad. From each of the *m* Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and i... | ```python
import operator
class Participant:
def __init__(self,name,point):
self.name=name
self.point=point
n,m=map(int,input().split())
des=[None]*m
for i in range(m):
des[i]=[]
for i in range(n):
name,region,point=input().split()
des[int(region)-1].append(Participant(name,int(point)))
result... | 3 | |
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t... | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"i... | 1,621,736,697 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | f = input()
s = input()
l = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday']
ind_f = l.index(f)
ind_s = l.index(s)
if ind_s - ind_f == 2 or 3:
print("YES")
else:
print("NO")
| Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the fir... | ```python
f = input()
s = input()
l = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday']
ind_f = l.index(f)
ind_s = l.index(s)
if ind_s - ind_f == 2 or 3:
print("YES")
else:
print("NO")
``` | 0 | |
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 1,515,626,666 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 5,632,000 | target = int(input())
c = 0
while True:
factor = c * (c + 1) * 0.5
if factor * -1 <= target <= factor:
temp = factor - target
if temp % 2 == 1:
c += 1
break
c += 1
print(c) | Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each ... | ```python
target = int(input())
c = 0
while True:
factor = c * (c + 1) * 0.5
if factor * -1 <= target <= factor:
temp = factor - target
if temp % 2 == 1:
c += 1
break
c += 1
print(c)
``` | 0 |
985 | D | Sand Fortress | PROGRAMMING | 2,100 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand o... | The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively. | Print the minimum number of spots you can occupy so the all the castle building conditions hold. | [
"5 2\n",
"6 8\n"
] | [
"3\n",
"3\n"
] | Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are ... | 0 | [
{
"input": "5 2",
"output": "3"
},
{
"input": "6 8",
"output": "3"
},
{
"input": "20 4",
"output": "7"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1414213562"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 10000000000000000... | 1,666,343,256 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 62 | 0 | n, H = map(int, input().split())
def is_ok(maxh):
k = min(H, maxh)
cnt = maxh*maxh-k*(k-1)//2
return cnt <= n
def get(maxh):
global n
k = min(H, maxh)
cnt = maxh*maxh-k*(k-1)//2
x = (2*maxh-1)-(k-1)
n = n-cnt
return x+(n+maxh-1)//maxh
l = 1
r = 10**18
while l+1 ... | Title: Sand Fortress
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars... | ```python
n, H = map(int, input().split())
def is_ok(maxh):
k = min(H, maxh)
cnt = maxh*maxh-k*(k-1)//2
return cnt <= n
def get(maxh):
global n
k = min(H, maxh)
cnt = maxh*maxh-k*(k-1)//2
x = (2*maxh-1)-(k-1)
n = n-cnt
return x+(n+maxh-1)//maxh
l = 1
r = 10**18
... | 3 | |
468 | C | Hack it! | PROGRAMMING | 2,500 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018). | Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=<<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. | [
"46\n",
"126444381000032\n"
] | [
"1 10\n",
"2333333 2333333333333\n"
] | none | 1,500 | [
{
"input": "46",
"output": "1 10"
},
{
"input": "126444381000032",
"output": "2333333 2333333333333"
},
{
"input": "69645082595",
"output": "613752823618441225798858488535 713259406474207764329704856394"
},
{
"input": "70602205995",
"output": "11 2492213340204320744986569... | 1,626,055,673 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 6,656,000 | import math
n = int(input())
x = 81000000000000000000
inf = 1e18
l = n - x % n
r = inf - l + 1
print(l, r)
| Title: Hack it!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X ... | ```python
import math
n = int(input())
x = 81000000000000000000
inf = 1e18
l = n - x % n
r = inf - l + 1
print(l, r)
``` | 0 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,672,601,536 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def get_x_count(n, x):
assert n in range(1, 106), "n should be an integer from [1, 105]"
assert x in range(1, 110), "x should be an integer from [1, 109]"
precomputed = {1: 1, 2: 2, 3: 2, 4: 3, 5: 2, 6: 4, 7: 2, 8: 4, 9: 3, 10: 4, 11: 2, 12: 6, 13: 2, 14: 4, 15: 4, 16: 5, 17: 2, 18: 6, 19: 2, 20: 6, 21:... | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
def get_x_count(n, x):
assert n in range(1, 106), "n should be an integer from [1, 105]"
assert x in range(1, 110), "x should be an integer from [1, 109]"
precomputed = {1: 1, 2: 2, 3: 2, 4: 3, 5: 2, 6: 4, 7: 2, 8: 4, 9: 3, 10: 4, 11: 2, 12: 6, 13: 2, 14: 4, 15: 4, 16: 5, 17: 2, 18: 6, 19: 2, ... | 0 | |
3 | C | Tic-tac-toe | PROGRAMMING | 1,800 | [
"brute force",
"games",
"implementation"
] | C. Tic-tac-toe | 1 | 64 | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the... | The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero). | Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw. | [
"X0X\n.0.\n.X.\n"
] | [
"second\n"
] | none | 0 | [
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
... | 1,681,980,722 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 29 | 280 | 0 |
s=""
for _ in range(3):
s+=input()
x=0
o=0
for i in s:
if i=="X":
x+=1
elif i=="0":
o+=1
# first, second, illegal, the first player won, the second player won or draw.
if x>o+1:
print("illegal")
elif o>x:
print("illegal")
elif x==0 and o==0:
prin... | Title: Tic-tac-toe
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds ... | ```python
s=""
for _ in range(3):
s+=input()
x=0
o=0
for i in s:
if i=="X":
x+=1
elif i=="0":
o+=1
# first, second, illegal, the first player won, the second player won or draw.
if x>o+1:
print("illegal")
elif o>x:
print("illegal")
elif x==0 and o==0:... | 0 |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,686,464,756 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
res = sys.maxsize
for i in range(m-n) :
res = min(res, f[i+n-1] - f[i])
print(res) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
res = sys.maxsize
for i in range(m-n) :
res = min(res, f[i+n-1] - f[i])
print(res)
``` | 0 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,691,088,575 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | num = int(input())
string = input()
if len(string) > 2:
if len(string) % 2 ==0:
print(string[-2::-2]+string[1::2])
else:
print(string[-2::-2]+string[0::2])
else:
print(string) | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
num = int(input())
string = input()
if len(string) > 2:
if len(string) % 2 ==0:
print(string[-2::-2]+string[1::2])
else:
print(string[-2::-2]+string[0::2])
else:
print(string)
``` | 3 | |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | 1,630,270,303 | 2,147,483,647 | PyPy 3 | OK | TESTS | 72 | 93 | 20,172,800 | n = int(input())
print(sum([abs(int(x)) for x in input().split()])) | Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
n = int(input())
print(sum([abs(int(x)) for x in input().split()]))
``` | 3 | |
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl... | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "... | 1,597,364,605 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 27 | 1,000 | 59,289,600 | import sys
a, b = map(int,input().split())
list = [a, b]
if a > 1000 and b > 1000:
if a < b:
print(">")
sys.exit()
elif a > b:
print("<")
sys.exit()
elif a == b:
print("=")
sys.exit()
wynik_a = a ** b
wynik_b = b ** a
if wynik_a > wyni... | Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out tha... | ```python
import sys
a, b = map(int,input().split())
list = [a, b]
if a > 1000 and b > 1000:
if a < b:
print(">")
sys.exit()
elif a > b:
print("<")
sys.exit()
elif a == b:
print("=")
sys.exit()
wynik_a = a ** b
wynik_b = b ** a
if wyni... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly *k* of the nodes should be exit-nodes, that means that each of them should... | The first line contains two integers *n* and *k* (3<=≤<=*n*<=≤<=2·105, 2<=≤<=*k*<=≤<=*n*<=-<=1) — the total number of nodes and the number of exit-nodes.
Note that it is always possible to build at least one network with *n* nodes and *k* exit-nodes within the given constraints. | In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next *n*<=-<=1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes ... | [
"3 2\n",
"5 3\n"
] | [
"2\n1 2\n2 3\n",
"3\n1 2\n2 3\n3 4\n3 5\n"
] | In the first example the only network is shown on the left picture.
In the second example one of optimal networks is shown on the right picture.
Exit-nodes are highlighted. | 0 | [
{
"input": "3 2",
"output": "2\n1 2\n2 3"
},
{
"input": "5 3",
"output": "3\n1 2\n2 3\n3 4\n3 5"
},
{
"input": "4 2",
"output": "3\n1 2\n2 3\n3 4"
},
{
"input": "4 3",
"output": "2\n1 2\n2 3\n2 4"
},
{
"input": "5 2",
"output": "4\n1 2\n2 3\n3 4\n4 5"
},
{... | 1,499,821,030 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 61 | 5,529,600 | n,k = map(int,input().split())
k -= 2
n-=k
sp = False
val = 0
if k==0:
val = n-1
elif n%2!=0 and k%2==0:
sp = True
val = (n-k+1)//2 + 1
elif n%2==0 and k%2!=0:
val = (n-k+1)//2 + 1
else:
val = (n-k)//2+1
print(max(val, n-1))
j = 1
for i in range(n-1):
print(j,j+1)
j+=1
if ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two ... | ```python
n,k = map(int,input().split())
k -= 2
n-=k
sp = False
val = 0
if k==0:
val = n-1
elif n%2!=0 and k%2==0:
sp = True
val = (n-k+1)//2 + 1
elif n%2==0 and k%2!=0:
val = (n-k+1)//2 + 1
else:
val = (n-k)//2+1
print(max(val, n-1))
j = 1
for i in range(n-1):
print(j,j+1)
... | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,687,713,045 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 61 | 0 | s=input()
if s=="{}":
print(0)
else:
s=s[1:-1].split(", ")
s=set(s)
print(len(s))
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
s=input()
if s=="{}":
print(0)
else:
s=s[1:-1].split(", ")
s=set(s)
print(len(s))
``` | 3 | |
346 | A | Alice and Bob | PROGRAMMING | 1,600 | [
"games",
"math",
"number theory"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | 500 | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
... | 1,695,144,143 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 122 | 0 | from math import *
n=int(input())
a=list(map(int,input().split()))
p=a[0]
for i in range(1,n):
p=gcd(p,a[i])
ans=(max(a)//p-n)%2
print("Alice") if ans else print("Bob") | Title: Alice and Bob
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following ... | ```python
from math import *
n=int(input())
a=list(map(int,input().split()))
p=a[0]
for i in range(1,n):
p=gcd(p,a[i])
ans=(max(a)//p-n)%2
print("Alice") if ans else print("Bob")
``` | 3 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,691,953,318 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | n,k=map(int, input(). split())
if n%2==0:
a=n/2
else:
a=(n+1)/2
if k<=a:
print( (2*k)-1 )
else:
a=k-a
print (int(2*a)) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
n,k=map(int, input(). split())
if n%2==0:
a=n/2
else:
a=(n+1)/2
if k<=a:
print( (2*k)-1 )
else:
a=k-a
print (int(2*a))
``` | 3 | |
508 | D | Tanya and Password | PROGRAMMING | 2,500 | [
"dfs and similar",
"graphs"
] | null | null | While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of *n*<=+<=2 characters. She has written all the possible *n* three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the pas... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105), the number of three-letter substrings Tanya got.
Next *n* lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit. | If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO".
If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option. | [
"5\naca\naba\naba\ncab\nbac\n",
"4\nabc\nbCb\ncb1\nb13\n",
"7\naaa\naaa\naaa\naaa\naaa\naaa\naaa\n"
] | [
"YES\nabacaba\n",
"NO\n",
"YES\naaaaaaaaa\n"
] | none | 2,000 | [
{
"input": "5\naca\naba\naba\ncab\nbac",
"output": "YES\nabacaba"
},
{
"input": "4\nabc\nbCb\ncb1\nb13",
"output": "NO"
},
{
"input": "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa",
"output": "YES\naaaaaaaaa"
},
{
"input": "1\nabc",
"output": "YES\nabc"
},
{
"input": "2\n... | 1,683,711,499 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 545 | 37,478,400 | from collections import defaultdict, deque
def find_eulerian_path(graph):
in_degree = defaultdict(int)
out_degree = defaultdict(int)
for u in graph:
for v in graph[u]:
out_degree[u] += 1
in_degree[v] += 1
start = None
end = None
for node in set(in_de... | Title: Tanya and Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of *n*<=+<=2 characters. She has written all the possible *n* three-letter ... | ```python
from collections import defaultdict, deque
def find_eulerian_path(graph):
in_degree = defaultdict(int)
out_degree = defaultdict(int)
for u in graph:
for v in graph[u]:
out_degree[u] += 1
in_degree[v] += 1
start = None
end = None
for node in... | 3 | |
165 | C | Another Problem on Strings | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math",
"strings",
"two pointers"
] | null | null | A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if th... | The first line contains the single integer *k* (0<=≤<=*k*<=≤<=106). The second line contains a non-empty binary string *s*. The length of *s* does not exceed 106 characters. | Print the single number — the number of substrings of the given string, containing exactly *k* characters "1".
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"1\n1010\n",
"2\n01010\n",
"100\n01010\n"
] | [
"6\n",
"4\n",
"0\n"
] | In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".
In the second sample the sought substrings are: "101", "0101", "1010", "01010". | 1,500 | [
{
"input": "1\n1010",
"output": "6"
},
{
"input": "2\n01010",
"output": "4"
},
{
"input": "100\n01010",
"output": "0"
},
{
"input": "0\n01010",
"output": "3"
},
{
"input": "0\n0010100011",
"output": "10"
},
{
"input": "0\n10000",
"output": "10"
}... | 1,629,582,001 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 216 | 22,220,800 | """
Author : Ashish Sasmal
Python3 / PyPy3
"""
from sys import stdin as sin
def aint():return int(input())
def amap():return map(int,sin.readline().split())
def alist():return list(map(int,sin.readline().split()))
def astr():return input()
k = aint()
s = input()
n = len(s)
p = []
ans = 0
last ... | Title: Another Problem on Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, ... | ```python
"""
Author : Ashish Sasmal
Python3 / PyPy3
"""
from sys import stdin as sin
def aint():return int(input())
def amap():return map(int,sin.readline().split())
def alist():return list(map(int,sin.readline().split()))
def astr():return input()
k = aint()
s = input()
n = len(s)
p = []
ans ... | -1 | |
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the p... | The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"i... | 1,677,159,986 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def check(s):
for i in range(len(s)//2):
if s[i]!=s[len(s)-1-i]:
return False
return True
def dfs(s):
if(len(s)==1 or check(s)):
return True
elif len(s)==0:
return False
for i in range(len(s)):
s1=s[:i]
s2=s[i+1:]
return not (dfs(s1) and dfs(s2))
s=input()
print(dfs(s))
... | Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The... | ```python
def check(s):
for i in range(len(s)//2):
if s[i]!=s[len(s)-1-i]:
return False
return True
def dfs(s):
if(len(s)==1 or check(s)):
return True
elif len(s)==0:
return False
for i in range(len(s)):
s1=s[:i]
s2=s[i+1:]
return not (dfs(s1) and dfs(s2))
s=input()
print(dfs(s))
... | 0 | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,655,279,190 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 109 | 8,806,400 | n = int(input())
x = [int(item) for item in input().split()]
a = [min(x), max(x)]
temp = []
if len(set(x)) > 2:
print(sum(1 for m in x if m not in a))
else:
print(0)
| Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
n = int(input())
x = [int(item) for item in input().split()]
a = [min(x), max(x)]
temp = []
if len(set(x)) > 2:
print(sum(1 for m in x if m not in a))
else:
print(0)
``` | 3 | |
978 | C | Letters | PROGRAMMING | 1,000 | [
"binary search",
"implementation",
"two pointers"
] | null | null | There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered from $1$ to $a_i$.
A postman delivers letters. Sometimes there is no specific dormitory and roo... | The first line contains two integers $n$ and $m$ $(1 \le n, m \le 2 \cdot 10^{5})$ — the number of dormitories and the number of letters.
The second line contains a sequence $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^{10})$, where $a_i$ equals to the number of rooms in the $i$-th dormitory. The third line contains a se... | Print $m$ lines. For each letter print two integers $f$ and $k$ — the dormitory number $f$ $(1 \le f \le n)$ and the room number $k$ in this dormitory $(1 \le k \le a_f)$ to deliver the letter. | [
"3 6\n10 15 12\n1 9 12 23 26 37\n",
"2 3\n5 10000000000\n5 6 9999999999\n"
] | [
"1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n",
"1 5\n2 1\n2 9999999994\n"
] | In the first example letters should be delivered in the following order:
- the first letter in room $1$ of the first dormitory - the second letter in room $9$ of the first dormitory - the third letter in room $2$ of the second dormitory - the fourth letter in room $13$ of the second dormitory - the fifth letter i... | 0 | [
{
"input": "3 6\n10 15 12\n1 9 12 23 26 37",
"output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12"
},
{
"input": "2 3\n5 10000000000\n5 6 9999999999",
"output": "1 5\n2 1\n2 9999999994"
},
{
"input": "1 1\n1\n1",
"output": "1 1"
},
{
"input": "5 15\n10 20 30 20 10\n1 6 10 11 15 30 31 54... | 1,655,452,916 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 2,432 | 45,670,400 | class Solution:
def findExactAddress(self, houseNumsList: list, roomNumsList: list) -> list:
houseNums = len(houseNumsList)
roomTotalIndex = [0] * houseNums
exactAddress = [[0 for i in range(2)] for j in range(len(roomNumsList))]
for i in range(houseNums):
if i == 0:
... | Title: Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered fro... | ```python
class Solution:
def findExactAddress(self, houseNumsList: list, roomNumsList: list) -> list:
houseNums = len(houseNumsList)
roomTotalIndex = [0] * houseNums
exactAddress = [[0 for i in range(2)] for j in range(len(roomNumsList))]
for i in range(houseNums):
if i ... | 3 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,603,405,235 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 280 | 1,433,600 |
n = int(input())
marks = [0] * n
abscissas = set()
ordenadas = set()
rest_abs = []
rest_ords = []
for i in range(n):
x, y = list(map(int, input().split()))
if len(abscissas) == 0 or x in abscissas or y in ordenadas:
abscissas.add(x)
ordenadas.add(y)
else:
rest_abs.append(x)
... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
n = int(input())
marks = [0] * n
abscissas = set()
ordenadas = set()
rest_abs = []
rest_ords = []
for i in range(n):
x, y = list(map(int, input().split()))
if len(abscissas) == 0 or x in abscissas or y in ordenadas:
abscissas.add(x)
ordenadas.add(y)
else:
rest_abs.append(... | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,641,479,978 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | n = int(input())
ans = 0
for i in range(1,n):
if((n-i)%i==0): ans+=1
print(ans)
# for example 10 is only divisible by 3 numbers 1,2,5 hence it should print 3 | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
n = int(input())
ans = 0
for i in range(1,n):
if((n-i)%i==0): ans+=1
print(ans)
# for example 10 is only divisible by 3 numbers 1,2,5 hence it should print 3
``` | 3 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,664,418,641 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 46 | 0 | [n, m] = [int(i) for i in input().split()]
seq = [int(i) for i in input().split()]
fing = [int(i) for i in input().split()]
ans = []
for i in seq:
if(i in fing):
ans.append(str(i))
print(' '.join(ans)) | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
[n, m] = [int(i) for i in input().split()]
seq = [int(i) for i in input().split()]
fing = [int(i) for i in input().split()]
ans = []
for i in seq:
if(i in fing):
ans.append(str(i))
print(' '.join(ans))
``` | 3 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,606,412,115 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 0 | def count(i):
c = 0
for j in str(i):
if(j == '4' or j == '7'):
c += 1
return c
n,k = map(int, input().split())
arr = list(map(int, input().split()))
c = 0
for i in arr:
if(count(i) <= k):
c+=1
print(c)
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
def count(i):
c = 0
for j in str(i):
if(j == '4' or j == '7'):
c += 1
return c
n,k = map(int, input().split())
arr = list(map(int, input().split()))
c = 0
for i in arr:
if(count(i) <= k):
c+=1
print(c)
``` | 3 | |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ... | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input":... | 1,587,317,555 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 108 | 307,200 | n,m ,s=input().split()
n = int(n)
m = int(m)
a = []
for i in range(n):
q = list(input())
a.append(q)
present = []
for i in range(n):
for j in range(m):
if a[i][j] == s:
if i != 0 and a[i-1][j] != s:
present.append(a[i-1][j])
if i != n-1 an... | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
n,m ,s=input().split()
n = int(n)
m = int(m)
a = []
for i in range(n):
q = list(input())
a.append(q)
present = []
for i in range(n):
for j in range(m):
if a[i][j] == s:
if i != 0 and a[i-1][j] != s:
present.append(a[i-1][j])
if i... | 3.970711 |
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.