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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
858 | E | Tests Renumeration | PROGRAMMING | 2,200 | [
"greedy",
"implementation"
] | null | null | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to re... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of files with tests.
*n* lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the *i*-th file contains an example test, and "0" if it contains a re... | In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6. | [
"5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n",
"2\n1 0\n2 1\n",
"5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n"
] | [
"4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3\n",
"3\nmove 1 3\nmove 2 1\nmove 3 2",
"5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3\n"
] | none | 2,500 | [
{
"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0",
"output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3"
},
{
"input": "2\n1 0\n2 1",
"output": "3\nmove 1 odt0m5\nmove 2 1\nmove odt0m5 2"
},
{
"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0",
"output": "5\nmove 1 5\nmove 11 1\nmov... | 1,656,626,451 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 2,252,800 | import sys
input = sys.stdin.buffer.readline
def process(n, G):
g = [[] for i in range(n+1)]
for a, b in G:
g[a].append(b)
g[b].append(a)
seen = [0 for i in range(n+1)]
trees = [[-1, [], []] for i in range(n+1)]
answer = []
for x in range(1, n+1):
if seen[x]... | Title: Tests Renumeration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data i... | ```python
import sys
input = sys.stdin.buffer.readline
def process(n, G):
g = [[] for i in range(n+1)]
for a, b in G:
g[a].append(b)
g[b].append(a)
seen = [0 for i in range(n+1)]
trees = [[-1, [], []] for i in range(n+1)]
answer = []
for x in range(1, n+1):
... | -1 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,621,005,923 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 62 | 6,963,200 | N,D = map(int,input().split())
l = input()
dp = [float('inf') for i in range(N)]
dp[0] = 0
for i in range(1,N):
if l[i] == '1':
for j in range(i,max(i-D,0)-1,-1):
if dp[j] != float('inf'):
dp[i] = min(dp[i],dp[j]) + 1
#print(dp)
print(dp[N-1] if dp[N-1] ... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
N,D = map(int,input().split())
l = input()
dp = [float('inf') for i in range(N)]
dp[0] = 0
for i in range(1,N):
if l[i] == '1':
for j in range(i,max(i-D,0)-1,-1):
if dp[j] != float('inf'):
dp[i] = min(dp[i],dp[j]) + 1
#print(dp)
print(dp[N-1] i... | 3 | |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th... | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5... | 1,377,876,815 | 215 | Python 3 | OK | TESTS | 35 | 218 | 5,120,000 | import fractions
x, y, a, b = map(int, input().split())
d = fractions.gcd(x, y)
d = x * y // d
print(b // d - (a - 1) // d)
| Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub ... | ```python
import fractions
x, y, a, b = map(int, input().split())
d = fractions.gcd(x, y)
d = x * y // d
print(b // d - (a - 1) // d)
``` | 3 | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,599,994,096 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 307,200 | n=int(input())
a=list(map(int, input().split()))
b=sorted(a)
f=0
for i in range(n-2):
for j in range(i+1,n-1):
if b[i]+b[j] in b[j+1:]:
x=a.index(b[i])
y=a.index(b[j])
z=a.index(b[j]+b[i])
f=1
print(z+1,y+1,x+1)
break
break
if f==0:... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
n=int(input())
a=list(map(int, input().split()))
b=sorted(a)
f=0
for i in range(n-2):
for j in range(i+1,n-1):
if b[i]+b[j] in b[j+1:]:
x=a.index(b[i])
y=a.index(b[j])
z=a.index(b[j]+b[i])
f=1
print(z+1,y+1,x+1)
break
brea... | 0 |
287 | B | Pipeline | PROGRAMMING | 1,700 | [
"binary search",
"math"
] | null | null | Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has onl... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1018, 2<=≤<=*k*<=≤<=109).
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. | Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1. | [
"4 3\n",
"5 5\n",
"8 4\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 1,500 | [
{
"input": "4 3",
"output": "2"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "1000000000000000000 1000000000",
"output": "-1"
},
{
"input": "499999998500000001 1000000000",
"output": "999955279"
},
{
"input": "49... | 1,691,601,110 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 400 | 0 | n,k=map(int,input().split())
sum,i=0,k
count=0
while i>2:
sum+=i
count+=1
if sum==n :
break
sum-=1
i-=1
else:
sum+=2
count+=1
print(count if sum==n else -1) | Title: Pipeline
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe c... | ```python
n,k=map(int,input().split())
sum,i=0,k
count=0
while i>2:
sum+=i
count+=1
if sum==n :
break
sum-=1
i-=1
else:
sum+=2
count+=1
print(count if sum==n else -1)
``` | 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,532,773,347 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 109 | 0 | nbHolds = int(input(""))
holds=input("").split(" ")
max_1 = 0
min_2 = 1001
for loop in range(nbHolds-1):
max_1 = max(max_1, int(holds[loop+1])-int(holds[loop]))
for loop in range(nbHolds-2):
min_2 = min(min_2, int(holds[loop+2])-int(holds[loop]))
print(max(max_1,min_2)) | 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
nbHolds = int(input(""))
holds=input("").split(" ")
max_1 = 0
min_2 = 1001
for loop in range(nbHolds-1):
max_1 = max(max_1, int(holds[loop+1])-int(holds[loop]))
for loop in range(nbHolds-2):
min_2 = min(min_2, int(holds[loop+2])-int(holds[loop]))
print(max(max_1,min_2))
``` | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,487,936,318 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 6,144,000 | '''input
6
'''
n = int(input())
l = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']
for _ in range(n-1):
l.append(l[0])
l.append(l[0])
l.remove(l[0])
print(l[0]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
'''input
6
'''
n = int(input())
l = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']
for _ in range(n-1):
l.append(l[0])
l.append(l[0])
l.remove(l[0])
print(l[0])
``` | 0 |
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas... | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBB... | 1,565,546,903 | 2,147,483,647 | PyPy 3 | OK | TESTS | 107 | 155 | 2,662,400 | # @author Matheus Alves dos Santos
letters = input()
counter = [0, 0, 0, 0, 0, 0, 0]
for c in letters:
if (c == 'B'):
counter[0] += 1
elif (c == 'u'):
counter[1] += 1
elif (c == 'l'):
counter[2] += 1
elif (c == 'b'):
counter[3] += 1
elif (c == 'a'):
counter[... | Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsess... | ```python
# @author Matheus Alves dos Santos
letters = input()
counter = [0, 0, 0, 0, 0, 0, 0]
for c in letters:
if (c == 'B'):
counter[0] += 1
elif (c == 'u'):
counter[1] += 1
elif (c == 'l'):
counter[2] += 1
elif (c == 'b'):
counter[3] += 1
elif (c == 'a'):
... | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,687,436,727 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 31 | 0 |
n , m , a , b = map(int , input().split())
def func():
if b/m > a :
return n*a
pr = ( n//m)*b
rem = n%m
if rem * a < b :
pr += (rem * a)
else :
pr += b
return pr
# print( b/m )
print(func()) | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
n , m , a , b = map(int , input().split())
def func():
if b/m > a :
return n*a
pr = ( n//m)*b
rem = n%m
if rem * a < b :
pr += (rem * a)
else :
pr += b
return pr
# print( b/m )
print(func())
``` | 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,618,226,971 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 124 | 0 | def euclid_algo(a, b):
if a < b:
a, b = b, a
if b == 0:
return a
return euclid_algo(b, a % b)
def main_function():
n, m = [int(i) for i in input().split(" ")]
a_n = [int(i) for i in input().split(" ")]
b_m = [int(i) for i in input().split(" ")]
output_list = [... | 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
def euclid_algo(a, b):
if a < b:
a, b = b, a
if b == 0:
return a
return euclid_algo(b, a % b)
def main_function():
n, m = [int(i) for i in input().split(" ")]
a_n = [int(i) for i in input().split(" ")]
b_m = [int(i) for i in input().split(" ")]
outpu... | 3 | |
883 | E | Field of Wonders | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length *n*, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already reveale... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | [
"4\na**d\n2\nabcd\nacbd\n",
"5\nlo*er\n2\nlover\nloser\n",
"3\na*a\n2\naaa\naba\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | 0 | [
{
"input": "4\na**d\n2\nabcd\nacbd",
"output": "2"
},
{
"input": "5\nlo*er\n2\nlover\nloser",
"output": "0"
},
{
"input": "3\na*a\n2\naaa\naba",
"output": "1"
},
{
"input": "1\n*\n1\na",
"output": "1"
},
{
"input": "1\n*\n1\nz",
"output": "1"
},
{
"inp... | 1,601,453,460 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,662,400 | import string
n=int(input())
s=input()
p=set(i for i in s if i != '*')
r=set('abcdefghijklmnopqrstuvwxyz')
for i in range(n):
t=input()
if all((s[j] not in p) ^ (t[j] in p) for j in range(n)):
r&=set(t)-p
print(len(r)) | Title: Field of Wonders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several tur... | ```python
import string
n=int(input())
s=input()
p=set(i for i in s if i != '*')
r=set('abcdefghijklmnopqrstuvwxyz')
for i in range(n):
t=input()
if all((s[j] not in p) ^ (t[j] in p) for j in range(n)):
r&=set(t)-p
print(len(r))
``` | -1 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,693,583,579 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | A = list(input())
R = 0
C = 'a'
for c in A:
k = abs(ord(c) - ord(C))
R += min(k, 26 - k)
C = c
print(R)
| Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
A = list(input())
R = 0
C = 'a'
for c in A:
k = abs(ord(c) - ord(C))
R += min(k, 26 - k)
C = c
print(R)
``` | 3 | |
79 | B | Colorful Field | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | B. Colorful Field | 2 | 256 | Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in f... | In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in ... | For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. | [
"4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n"
] | [
"Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n"
] | The sample corresponds to the figure in the statement. | 1,000 | [
{
"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1",
"output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"
},
{
"input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2",
"output": "Grapes\nWaste"
},
{
"input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8... | 1,610,020,812 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 186 | 307,200 | n, m, k, t = list(map(int, input().split()))
waste_psum = [0] * (n*m)
for i in range(k):
row, col = list(map(int, input().split()))
which_cell = (m * (row-1)) + col
waste_psum[which_cell-1] = 1
for i in range(1, n*m):
waste_psum[i] = waste_psum[i] + waste_psum[i-1]
crop = {
1: 'Ca... | Title: Colorful Field
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
... | ```python
n, m, k, t = list(map(int, input().split()))
waste_psum = [0] * (n*m)
for i in range(k):
row, col = list(map(int, input().split()))
which_cell = (m * (row-1)) + col
waste_psum[which_cell-1] = 1
for i in range(1, n*m):
waste_psum[i] = waste_psum[i] + waste_psum[i-1]
crop = {
... | -1 |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,522,258,429 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 154 | 7,372,800 | a=sorted(list(map(int,input().split())))
b=[]
for i in range(3):
b.append(a[i]%3)
mi=min(max(b),a[0])
print(mi+(a[0]-mi)//3+(a[1]-mi)//3+(a[2]-mi)//3)
| Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
a=sorted(list(map(int,input().split())))
b=[]
for i in range(3):
b.append(a[i]%3)
mi=min(max(b),a[0])
print(mi+(a[0]-mi)//3+(a[1]-mi)//3+(a[2]-mi)//3)
``` | 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,601,458,004 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | s = input()
h,c = 'hello',0
for i in s:
if i==h[c]: c+=1
if c==5: print('YES');break
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,c = 'hello',0
for i in s:
if i==h[c]: c+=1
if c==5: print('YES');break
else: print('NO')
``` | 3.9455 |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,512,679,770 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 15 | 1,247 | 67,072,000 | N = int(input())
im = []
for i in range(N):
for s in str.split(input()):
im.append(int(s))
m2 = [0] * N ** 2
m5 = [0] * N ** 2
n0 = -1
for i in range(N * N):
x = im[i]
if x == 0:
n0 = i
m2[i] = -1
m5[i] = -1
while x >= 1:
if x % 2 == 0:
... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
N = int(input())
im = []
for i in range(N):
for s in str.split(input()):
im.append(int(s))
m2 = [0] * N ** 2
m5 = [0] * N ** 2
n0 = -1
for i in range(N * N):
x = im[i]
if x == 0:
n0 = i
m2[i] = -1
m5[i] = -1
while x >= 1:
if x % 2 == 0... | 0 |
515 | A | Drazil and Date | PROGRAMMING | 1,000 | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to ... | You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 9983201... | 1,644,606,824 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | a, b ,s = map(int, input().split())
def calculation(a, b, s):
if s % 2 == 0:
if a + b < s:
return "Yes"
if a + b == s:
return "Yes"
else:
return "No"
print(calculation(a, b, s)) | Title: Drazil and Date
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit ... | ```python
a, b ,s = map(int, input().split())
def calculation(a, b, s):
if s % 2 == 0:
if a + b < s:
return "Yes"
if a + b == s:
return "Yes"
else:
return "No"
print(calculation(a, b, s))
``` | 0 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,627,965,770 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 22,220,800 | for i in range(30):
r,g,b=map(int,input().split())
if min(r,g,b)==0:
print(r//3 +g//3 +b//3)
else:
print((r+g+b)//3 - 1 if min(r%3,g%3,b%3)==0 and max(r%3,g%3,b%3)==2 and (r%3+g%3+b%3)==3 else (r+g+b)//3) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
for i in range(30):
r,g,b=map(int,input().split())
if min(r,g,b)==0:
print(r//3 +g//3 +b//3)
else:
print((r+g+b)//3 - 1 if min(r%3,g%3,b%3)==0 and max(r%3,g%3,b%3)==2 and (r%3+g%3+b%3)==3 else (r+g+b)//3)
``` | -1 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,458,140,100 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 3,000 | 9,216,000 | count = int(input())
array = []
for i in range(count):
array.append(str(input()))
array.reverse()
for key in range(len(array)):
if array.index(array[key]) == key:
print(array[key])
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
count = int(input())
array = []
for i in range(count):
array.append(str(input()))
array.reverse()
for key in range(len(array)):
if array.index(array[key]) == key:
print(array[key])
``` | 0 | |
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"in... | 1,643,711,328 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | input1 = input()
yes = ""
no = ""
a = len(input1)
for i in range(1,a,2):
if input1[i] == "a" or input1[i] == "e" or input1[i] == "i" or input1[i] == "o" or input1[i] == "u" or input1[i-1] == "n":
yes += "yes"
else:
no += "no"
if "no" in no:
print("NO")
else:
print("YES") | Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after eve... | ```python
input1 = input()
yes = ""
no = ""
a = len(input1)
for i in range(1,a,2):
if input1[i] == "a" or input1[i] == "e" or input1[i] == "i" or input1[i] == "o" or input1[i] == "u" or input1[i-1] == "n":
yes += "yes"
else:
no += "no"
if "no" in no:
print("NO")
else:
print("... | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,694,610,507 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n=int(input())
words=[]
for _ in range(n):
add_word=str(input())
words.append(add_word)
for word in words:
if len(word)>10:
word=f"{word[0]}{len(word)-2}{word[-1]}"
print(word) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n=int(input())
words=[]
for _ in range(n):
add_word=str(input())
words.append(add_word)
for word in words:
if len(word)>10:
word=f"{word[0]}{len(word)-2}{word[-1]}"
print(word)
``` | 3.977 |
760 | B | Frodo and pillows | PROGRAMMING | 1,500 | [
"binary search",
"greedy"
] | null | null | *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge... | The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. | Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n"
] | [
"2\n",
"4\n",
"3\n"
] | In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third exa... | 1,000 | [
{
"input": "4 6 2",
"output": "2"
},
{
"input": "3 10 3",
"output": "4"
},
{
"input": "3 6 1",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000 1",
"output": "1000000000"
},
{
... | 1,521,174,408 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public For... | Title: Frodo and pillows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma... | ```python
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
... | -1 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,694,027,031 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 93 | 16,281,600 | n=int(input())
l=list(map(int,input().split()))
cnt_array = [0 for i in range(10**5+1)]
for i in l:
cnt_array[i]+=1
dp=[0,0]
for i in range(1,10**5):
dp.append(max(dp[i],dp[i-1] + cnt_array[i]*i))
print(dp[-1]) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n=int(input())
l=list(map(int,input().split()))
cnt_array = [0 for i in range(10**5+1)]
for i in l:
cnt_array[i]+=1
dp=[0,0]
for i in range(1,10**5):
dp.append(max(dp[i],dp[i-1] + cnt_array[i]*i))
print(dp[-1])
``` | 0 | |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,523,117,835 | 735 | Python 3 | OK | TESTS | 55 | 93 | 7,065,600 | def f(s):
ia = ib = ic = False
ac = bc = cc = 0
for c in s:
if c == 'a':
ac += 1
ia = True
if ib or ic:
return False
if c == 'b':
bc += 1
ib = True
if ic:
return... | Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
def f(s):
ia = ib = ic = False
ac = bc = cc = 0
for c in s:
if c == 'a':
ac += 1
ia = True
if ib or ic:
return False
if c == 'b':
bc += 1
ib = True
if ic:
... | 3 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,657,347,738 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 31 | 0 | n, m = map(int, input().split())
arr = []
clr, bnw = 0,0
for i in range(n):
x = list(map(str, input().split()))
if ( ('C' in x) or ('M' in x) or ('Y'in x) or ('G'in x ) ):
clr+=1
else:
bnw +=1
if(clr > 0):
print('#Color')
else:
print('#Black&White') | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n, m = map(int, input().split())
arr = []
clr, bnw = 0,0
for i in range(n):
x = list(map(str, input().split()))
if ( ('C' in x) or ('M' in x) or ('Y'in x) or ('G'in x ) ):
clr+=1
else:
bnw +=1
if(clr > 0):
print('#Color')
else:
print('#Black&White')
``... | 0 | |
281 | B | Nearest Fraction | PROGRAMMING | 1,700 | [
"brute force",
"implementation",
"two pointers"
] | null | null | You are given three positive integers *x*,<=*y*,<=*n*. Your task is to find the nearest fraction to fraction whose denominator is no more than *n*.
Formally, you should find such pair of integers *a*,<=*b* (1<=≤<=*b*<=≤<=*n*; 0<=≤<=*a*) that the value is as minimal as possible.
If there are multiple "nearest" frac... | A single line contains three integers *x*,<=*y*,<=*n* (1<=≤<=*x*,<=*y*,<=*n*<=≤<=105). | Print the required fraction in the format "*a*/*b*" (without quotes). | [
"3 7 6\n",
"7 2 4\n"
] | [
"2/5\n",
"7/2\n"
] | none | 1,000 | [] | 1,697,215,389 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def solve(x, y, n):
min = 1e5
for b in range(1, n):
for a in range(0, x*x+b*b):
temp = abs(x/y - a/b)
if temp < min:
den = b
num = a
min = temp
elif temp == min:
if b < den:
den = b... | Title: Nearest Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given three positive integers *x*,<=*y*,<=*n*. Your task is to find the nearest fraction to fraction whose denominator is no more than *n*.
Formally, you should find such pair of integers *a*,<=*b* (1<=≤<=*b... | ```python
def solve(x, y, n):
min = 1e5
for b in range(1, n):
for a in range(0, x*x+b*b):
temp = abs(x/y - a/b)
if temp < min:
den = b
num = a
min = temp
elif temp == min:
if b < den:
... | 0 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,574,947,265 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 | print(sum([1 for x in input() if x in ['a', 'e', 'i', 'o', 'u', 'y']]))
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
print(sum([1 for x in input() if x in ['a', 'e', 'i', 'o', 'u', 'y']]))
``` | 0 | |
327 | B | Hungry Sequence | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in i... | The input contains a single integer: *n* (1<=≤<=*n*<=≤<=105). | Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one. | [
"3\n",
"5\n"
] | [
"2 9 15\n",
"11 14 20 27 31\n"
] | none | 500 | [
{
"input": "3",
"output": "2 9 15"
},
{
"input": "5",
"output": "11 14 20 27 31"
},
{
"input": "1",
"output": "3"
},
{
"input": "1000",
"output": "3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 ... | 1,690,727,022 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 560 | 51,712,000 | def sieve_of_eratosthenes(limit):
primes = set(range(2, limit + 1))
p = 2
while p * p <= limit:
if p in primes:
for i in range(p * p, limit + 1, p):
primes.discard(i)
p += 1
return primes
def hungry_sequence(n):
primes = sieve_of_eratosthen... | Title: Hungry Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1... | ```python
def sieve_of_eratosthenes(limit):
primes = set(range(2, limit + 1))
p = 2
while p * p <= limit:
if p in primes:
for i in range(p * p, limit + 1, p):
primes.discard(i)
p += 1
return primes
def hungry_sequence(n):
primes = sieve_of_... | -1 | |
995 | B | Suit and Tie | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"math"
] | null | null | Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the pic... | The first line contains a single integer $n$ ($1 \le n \le 100$), the number of pairs of people.
The second line contains $2n$ integers $a_1, a_2, \dots, a_{2n}$. For each $i$ with $1 \le i \le n$, $i$ appears exactly twice. If $a_j = a_k = i$, that means that the $j$-th and $k$-th people in the line form a couple. | Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions. | [
"4\n1 1 2 3 3 2 4 4\n",
"3\n1 1 2 2 3 3\n",
"3\n3 1 2 3 1 2\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first sample case, we can transform $1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$ in two steps. Note that the sequence $1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$ also works in the same number of steps.
The second sample case already satisfies the constr... | 750 | [
{
"input": "4\n1 1 2 3 3 2 4 4",
"output": "2"
},
{
"input": "3\n1 1 2 2 3 3",
"output": "0"
},
{
"input": "3\n3 1 2 3 1 2",
"output": "3"
},
{
"input": "8\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4",
"output": "27"
},
{
"input": "2\n1 2 1 2",
"output": "1"
},
{
... | 1,659,251,259 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 22 | 93 | 2,560,000 | from collections import defaultdict as dc
n=int(input())
arr=list(map(int,input().split()))
mp=dc(lambda:list())
for i in range(2*n):
mp[arr[i]].append(i)
ans=0
st=set()
for i in arr:
if i in st:continue
tmp=mp[i][1]
ans+=tmp-mp[i][0]-1
for j in mp:
if j in st:continue
... | Title: Suit and Tie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the o... | ```python
from collections import defaultdict as dc
n=int(input())
arr=list(map(int,input().split()))
mp=dc(lambda:list())
for i in range(2*n):
mp[arr[i]].append(i)
ans=0
st=set()
for i in arr:
if i in st:continue
tmp=mp[i][1]
ans+=tmp-mp[i][0]-1
for j in mp:
if j in st:continue... | 3 | |
5 | A | Chat Servers Outgoing Traffic | PROGRAMMING | 1,000 | [
"implementation"
] | A. Chat Server's Outgoing Traffic | 1 | 64 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <s... | Print a single number — answer to the problem. | [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] | [
"9\n",
"14\n"
] | none | 0 | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO... | 1,615,885,868 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | l=[]
for i in range(7):
try:
l.append(input())
except:
break
c=0
le=0
for i in l:
if(i[0]=='+'):
c=c+1
elif(i[0]=='-'):
c=c-1
else:
le=le+c*len(i[i.index(":")+1:])
print(le)
| Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr... | ```python
l=[]
for i in range(7):
try:
l.append(input())
except:
break
c=0
le=0
for i in l:
if(i[0]=='+'):
c=c+1
elif(i[0]=='-'):
c=c-1
else:
le=le+c*len(i[i.index(":")+1:])
print(le)
``` | 0 |
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he... | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i... | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0... | 1,671,547,875 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n,a = map(int ,input().split())
a-=1
ar = list(map(int,input().split()))
cnt = 0
for i in range(n):
try:
if ar[a-i-1] == 1 and ar[a+i+1] == 1:
cnt+=2
ar[a-i-1] = 0
ar[a+i+1] = 0
except:...
for i in range(a,n):cnt+=ar[i] == 1
print(cnt)
"""
6 3
1 1 1 0 1... | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city... | ```python
n,a = map(int ,input().split())
a-=1
ar = list(map(int,input().split()))
cnt = 0
for i in range(n):
try:
if ar[a-i-1] == 1 and ar[a+i+1] == 1:
cnt+=2
ar[a-i-1] = 0
ar[a+i+1] = 0
except:...
for i in range(a,n):cnt+=ar[i] == 1
print(cnt)
"""
6 3
... | 0 | |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,564,079,466 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | # import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
m,d=map(int,input().split())
if(m==2):
if(d==1):
print(5)
else:
print(6)
else:
l=[1,3,5,7,8,10,12]
s=[2,4,6,9,11]
if(m in l):
if(d==6 or d==7):
print(6)
else:
print(5)
else:
if(d==7):
pri... | Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
m,d=map(int,input().split())
if(m==2):
if(d==1):
print(5)
else:
print(6)
else:
l=[1,3,5,7,8,10,12]
s=[2,4,6,9,11]
if(m in l):
if(d==6 or d==7):
print(6)
else:
print(5)
else:
if(d==7... | 0 | |
733 | B | Parade | PROGRAMMING | 1,100 | [
"math"
] | null | null | Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns.
The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively. | Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to *n* in the order they are given in the input data.
If there are several answers, print any of them. | [
"3\n5 6\n8 9\n10 3\n",
"2\n6 5\n5 6\n",
"6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n"
] | [
"3\n",
"1\n",
"0\n"
] | In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third co... | 1,000 | [
{
"input": "3\n5 6\n8 9\n10 3",
"output": "3"
},
{
"input": "2\n6 5\n5 6",
"output": "1"
},
{
"input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32",
"output": "0"
},
{
"input": "2\n500 499\n500 500",
"output": "0"
},
{
"input": "1\n139 252",
"output": "0"
},
{
... | 1,666,386,333 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 514 | 14,643,200 | n=int(input())
rl=[]
columna=0
for i in range(n):
string=input()
rl.append(string)
for i in range(n):
dividio=rl[i].split(" ")
rl[i]=dividio
for i in range(n):
for j in range(len(rl[i])):
rl[i][j]=int(rl[i][j])
l=0
r=0
for i in range(n):
l+=rl[i][1]
r+=rl[i][0]
beauty=abs(r-l)
l_n=0
r_n=0
beau... | Title: Parade
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should... | ```python
n=int(input())
rl=[]
columna=0
for i in range(n):
string=input()
rl.append(string)
for i in range(n):
dividio=rl[i].split(" ")
rl[i]=dividio
for i in range(n):
for j in range(len(rl[i])):
rl[i][j]=int(rl[i][j])
l=0
r=0
for i in range(n):
l+=rl[i][1]
r+=rl[i][0]
beauty=abs(r-l)
l_n=0
... | 3 | |
552 | A | Vanya and Table | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of rectangles.
Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1<=≤<=*x*2<=≤<=100, 1<=≤<=*y*1<=≤<=*y*2<=≤<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *... | In a single line print the sum of all values in the cells of the table. | [
"2\n1 1 2 3\n2 2 3 3\n",
"2\n1 1 3 3\n1 1 3 3\n"
] | [
"10\n",
"18\n"
] | Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110
So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will ... | 500 | [
{
"input": "2\n1 1 2 3\n2 2 3 3",
"output": "10"
},
{
"input": "2\n1 1 3 3\n1 1 3 3",
"output": "18"
},
{
"input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13",
"output": "510"
},
{
"input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11",
"o... | 1,595,511,457 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 140 | 21,811,200 | n = int(input())
l = []
for i in range(100): l.append([0] * 100)
for i in range(n):
x1, y1, x2, y2 = map(int, input().split())
x1 += -1
x2 += -1
y1 += -1
y2 += -1
for i in range(x1, x2 + 1):
for j in range(y1, y2 + 1):
l[i][j] -= -1
ans = 0
for i in range(100):
... | Title: Vanya and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vany... | ```python
n = int(input())
l = []
for i in range(100): l.append([0] * 100)
for i in range(n):
x1, y1, x2, y2 = map(int, input().split())
x1 += -1
x2 += -1
y1 += -1
y2 += -1
for i in range(x1, x2 + 1):
for j in range(y1, y2 + 1):
l[i][j] -= -1
ans = 0
for i in ran... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense of direction is impaired, during the $i$-th move he will either move in th... | The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of moves.
Each of the following lines contains two space-separated integers $x_i$ and $y_i$, meaning that $\vec{v_i} = (x_i, y_i)$. We have that $|v_i| \le 10^6$ for all $i$. | Output a single line containing $n$ integers $c_1, c_2, \cdots, c_n$, each of which is either $1$ or $-1$. Your solution is correct if the value of $p = \sum_{i = 1}^n c_i \vec{v_i}$, satisfies $|p| \le 1.5 \cdot 10^6$.
It can be shown that a solution always exists under the given constraints. | [
"3\n999999 0\n0 999999\n999999 0\n",
"1\n-824590 246031\n",
"8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n"
] | [
"1 1 -1 \n",
"1 \n",
"1 1 1 1 1 1 1 -1 \n"
] | none | 0 | [
{
"input": "3\n999999 0\n0 999999\n999999 0",
"output": "1 1 -1 "
},
{
"input": "1\n-824590 246031",
"output": "1 "
},
{
"input": "8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899",
"output": "1 1 1 1 1 1 1 -1 "
... | 1,690,913,106 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690913106.4199023")# 1690913106.419922 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. A... | ```python
print("_RANDOM_GUESS_1690913106.4199023")# 1690913106.419922
``` | 0 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,608,287,918 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | # 2x + 2y = n and x!=y
n = int(input())
if(n%2==1):
ans = 0
else:
l = n//2 # (x + y = l)
if(l%2==0):
ans = l//2 - 1
else:
ans = l//2
print(ans) | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
# 2x + 2y = n and x!=y
n = int(input())
if(n%2==1):
ans = 0
else:
l = n//2 # (x + y = l)
if(l%2==0):
ans = l//2 - 1
else:
ans = l//2
print(ans)
``` | 0 | |
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for... | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhe... | 1,511,787,207 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 77 | 5,632,000 | s = list(input())
a = set(s)
k = int(input())
if len(s) < k:
print('impossible')
else:
x = k - len(a)
print(x) | Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it... | ```python
s = list(input())
a = set(s)
k = int(input())
if len(s) < k:
print('impossible')
else:
x = k - len(a)
print(x)
``` | 0 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,689,462,434 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | y = int(input())
w = int(input())
highest = max(w, y)
if highest == 0:
print('0/1')
elif highest == 1:
print('1/1')
else:
numo = 6 - highest + 1
print(f'{numo}/6') | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
y = int(input())
w = int(input())
highest = max(w, y)
if highest == 0:
print('0/1')
elif highest == 1:
print('1/1')
else:
numo = 6 - highest + 1
print(f'{numo}/6')
``` | -1 |
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de... | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ... | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low... | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n????????... | 1,690,902,001 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 46 | 0 | def factorial(n):
if n == 0 :
return 1;
return factorial(n-1)*n;
def fact(plus,minus,length):
ans= factorial(length)//(factorial(minus)*factorial(plus));
return ans;
def solve():
string = list(input());
x = list(input());
plus=0;
minus=0;
for i in string:
... | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go... | ```python
def factorial(n):
if n == 0 :
return 1;
return factorial(n-1)*n;
def fact(plus,minus,length):
ans= factorial(length)//(factorial(minus)*factorial(plus));
return ans;
def solve():
string = list(input());
x = list(input());
plus=0;
minus=0;
for i i... | 0 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,695,289,158 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | klh = input().strip(" ?").lower()
if klh[-1] in "aeiouy":
print("YES")
else:
print("NO") | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
klh = input().strip(" ?").lower()
if klh[-1] in "aeiouy":
print("YES")
else:
print("NO")
``` | 3.9845 |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,544,089,826 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 22,425,600 | I=input
s=list(I())
S=len(s)
n=int(I())
*l,=sorted(map(int,I().split()))
for i in range(S//2+1):
if sum([j<=i for j in l])%2:s[i-1],s[S-i]=s[S-i],s[i-1]
print(''.join(s)) | Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
I=input
s=list(I())
S=len(s)
n=int(I())
*l,=sorted(map(int,I().split()))
for i in range(S//2+1):
if sum([j<=i for j in l])%2:s[i-1],s[S-i]=s[S-i],s[i-1]
print(''.join(s))
``` | 0 | |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,601,208,354 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 342 | 1,740,800 | def check(x, y, z, w):
if x + y == r1 and z + w == r2 and x + z == c1 and y + w == c2 and x + w == d1 and y + z == d2:
return True
else:
return False
def equal(x, y, z, w):
if x != y and x != z and x != w and y != z and y != w and z != w:
return True
else:
retu... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
def check(x, y, z, w):
if x + y == r1 and z + w == r2 and x + z == c1 and y + w == c2 and x + w == d1 and y + z == d2:
return True
else:
return False
def equal(x, y, z, w):
if x != y and x != z and x != w and y != z and y != w and z != w:
return True
else:
... | 3 | |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pie... | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
... | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,582,193,242 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 280 | 1,126,400 | n = int(input())
C = [1]*n
for i in range(2, 1+int((n+1)**.5)):
for j in range(i*i, n+2, i):
C[j-2] = 2
print(2 - (n<3))
print(*C) | Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ... | ```python
n = int(input())
C = [1]*n
for i in range(2, 1+int((n+1)**.5)):
for j in range(i*i, n+2, i):
C[j-2] = 2
print(2 - (n<3))
print(*C)
``` | 3 | |
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 4... | 1,595,933,231 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 202 | 6,656,000 | a=int(input())
b=list(map(int,input().split()))*2
pizza=360
for i in range(2*a):
t=0
for j in range(i,min(i+a,2*a)):
t+=b[j]
pizza=min(pizza,abs(2*t-360))
print(pizza) | Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut in... | ```python
a=int(input())
b=list(map(int,input().split()))*2
pizza=360
for i in range(2*a):
t=0
for j in range(i,min(i+a,2*a)):
t+=b[j]
pizza=min(pizza,abs(2*t-360))
print(pizza)
``` | 3 | |
864 | B | Polycarp and Letters | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowerc... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters. | Print maximum number of elements in pretty set of positions for string *s*. | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n"
] | [
"2\n",
"3\n",
"0\n"
] | In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There... | 1,000 | [
{
"input": "11\naaaaBaabAbA",
"output": "2"
},
{
"input": "12\nzACaAbbaazzC",
"output": "3"
},
{
"input": "3\nABC",
"output": "0"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\naz",
"output": "2"
},
{
"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLr... | 1,587,378,391 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 155 | 0 | n=int(input())
s=list(input())
s1=set()
m=0
for i in range(n):
if(ord(s[i])>=97 and ord(s[i])<=122):
if(s[i] not in s1):
s1.add(s[i])
m=max(m,len(s1))
else:
s1.clear()
print(m)
| Title: Polycarp and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if... | ```python
n=int(input())
s=list(input())
s1=set()
m=0
for i in range(n):
if(ord(s[i])>=97 and ord(s[i])<=122):
if(s[i] not in s1):
s1.add(s[i])
m=max(m,len(s1))
else:
s1.clear()
print(m)
``` | 3 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,535,266,586 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 248 | 0 | n = int(input())
arr = list(map(int, input().split()[:n]))
d = {}
max = 1
for i in arr:
if i in d:
d[i] += 1
if max < d[i]:
max = d[i]
else:
d[i] = 1
print('{0} {1}'.format(max, len(d))) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = int(input())
arr = list(map(int, input().split()[:n]))
d = {}
max = 1
for i in arr:
if i in d:
d[i] += 1
if max < d[i]:
max = d[i]
else:
d[i] = 1
print('{0} {1}'.format(max, len(d)))
``` | 3.938 |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,679,670,563 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 62 | 0 | # author: birsnot - Nardos Wehabe
from sys import stdin
def input(): return stdin.readline()[:-1]
def I(): return int(input())
def II(): return map(int, input().split())
def IL(): return list(map(int, input().split()))
def SIL(): return sorted(map(int, input().split()))
def solve():
s = input()
N... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
# author: birsnot - Nardos Wehabe
from sys import stdin
def input(): return stdin.readline()[:-1]
def I(): return int(input())
def II(): return map(int, input().split())
def IL(): return list(map(int, input().split()))
def SIL(): return sorted(map(int, input().split()))
def solve():
s = inpu... | 3 | |
36 | A | Extra-terrestrial Intelligence | PROGRAMMING | 1,300 | [
"implementation"
] | A. Extra-terrestrial Intelligence | 2 | 64 | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | [
"8\n00111000\n",
"7\n1001011\n",
"7\n1010100\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "8\n00111000",
"output": "YES"
},
{
"input": "7\n1001011",
"output": "NO"
},
{
"input": "7\n1010100",
"output": "YES"
},
{
"input": "5\n10101",
"output": "YES"
},
{
"input": "3\n111",
"output": "YES"
},
{
"input": "10\n0011111011",
"outp... | 1,606,078,772 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 218 | 307,200 | f1=open("input.txt","r")
f2=open("output.txt","w")
n = int(f1.readline())
pala = f1.readline()
pala = pala[pala.index('1')+1:].split('1')
freq = []
for j in range(len(pala)-1):
freq.append(len(pala[j]))
print(freq)
if len(freq) == freq.count(freq[0]):
f2.write("YES")
else:
f2.write("NO")
... | Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* da... | ```python
f1=open("input.txt","r")
f2=open("output.txt","w")
n = int(f1.readline())
pala = f1.readline()
pala = pala[pala.index('1')+1:].split('1')
freq = []
for j in range(len(pala)-1):
freq.append(len(pala[j]))
print(freq)
if len(freq) == freq.count(freq[0]):
f2.write("YES")
else:
f2.write("NO")
... | 3.943211 |
225 | C | Barcode | PROGRAMMING | 1,700 | [
"dp",
"matrices"
] | null | null | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome ... | The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The pictur... | In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists. | [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
] | [
"11\n",
"5\n"
] | In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | 1,500 | [
{
"input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..",
"output": "11"
},
{
"input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#",
"output": "24"
},
{
"input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#",
"output": "6"
},
{
"input": "5 ... | 1,626,776,101 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993... | Title: Barcode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulf... | ```python
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.141592653589793238462643383279502884... | -1 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,665,428,974 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | n_students, k_times = map(int, input().split())
students = list(map(int, input().split()))
students.sort()
students = [student for student in students if student <= 5 - k_times]
print(len(students) // 3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n_students, k_times = map(int, input().split())
students = list(map(int, input().split()))
students.sort()
students = [student for student in students if student <= 5 - k_times]
print(len(students) // 3)
``` | 3 | |
7 | A | Kalevitch and Chess | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms"
] | A. Kalevitch and Chess | 2 | 64 | A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, th... | The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/c... | Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. | [
"WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n",
"WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n"
] | [
"3\n",
"1\n"
] | none | 0 | [
{
"input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW",
"output": "3"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "1"
},
{
"input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWW... | 1,601,403,941 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 310 | 0 | e=0
s1=''
s2=''
s3=''
s4=''
s5=''
s6=''
s7=''
s8=''
for i in range(8):
s=str(input())
if(s==('B'*8)):
e=e+1
s1=s1+s[0]
s2=s2+s[1]
s3=s3+s[2]
s4=s4+s[3]
s5=s5+s[4]
s6=s6+s[5]
s7=s7+s[6]
s8=s8+s[7]
if(s1==('B'*8)):
e=e+1
if(s2==('B'*8)):
e=e+... | Title: Kalevitch and Chess
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch de... | ```python
e=0
s1=''
s2=''
s3=''
s4=''
s5=''
s6=''
s7=''
s8=''
for i in range(8):
s=str(input())
if(s==('B'*8)):
e=e+1
s1=s1+s[0]
s2=s2+s[1]
s3=s3+s[2]
s4=s4+s[3]
s5=s5+s[4]
s6=s6+s[5]
s7=s7+s[6]
s8=s8+s[7]
if(s1==('B'*8)):
e=e+1
if(s2==('B'*8)):... | 3.9225 |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,675,064,479 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n , m = map(int,input().split())
l = list(map(int,input().split()))
x = sum(l[:m])
ans = 1
s = x
for i in range(m,n):
s = s + l[i] - l[i-m]
if(s<x):
x = s
ans = i - m + 1
print(ans) | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n , m = map(int,input().split())
l = list(map(int,input().split()))
x = sum(l[:m])
ans = 1
s = x
for i in range(m,n):
s = s + l[i] - l[i-m]
if(s<x):
x = s
ans = i - m + 1
print(ans)
``` | 0 | |
439 | D | Devu and his Brother | PROGRAMMING | 1,700 | [
"binary search",
"sortings",
"ternary search",
"two pointers"
] | null | null | Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays *a* and *b* by their father. The array *a* is given to Devu and *b* to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array *a* should be at least as much... | The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line will contain *n* space-separated integers representing content of the array *a* (1<=≤<=*a**i*<=≤<=109). The third line will contain *m* space-separated integers representing content of the array *b* (1<=≤<=*b**i*<=≤... | You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition. | [
"2 2\n2 3\n3 5\n",
"3 2\n1 2 3\n3 4\n",
"3 2\n4 5 6\n1 2\n"
] | [
"3\n",
"4\n",
"0\n"
] | In example 1, you can increase *a*<sub class="lower-index">1</sub> by 1 and decrease *b*<sub class="lower-index">2</sub> by 1 and then again decrease *b*<sub class="lower-index">2</sub> by 1. Now array *a* will be [3; 3] and array *b* will also be [3; 3]. Here minimum element of *a* is at least as large as maximum elem... | 2,000 | [
{
"input": "2 2\n2 3\n3 5",
"output": "3"
},
{
"input": "3 2\n1 2 3\n3 4",
"output": "4"
},
{
"input": "3 2\n4 5 6\n1 2",
"output": "0"
},
{
"input": "10 10\n23 100 38 38 73 54 59 69 44 86\n100 100 100 100 100 100 100 100 100 100",
"output": "416"
},
{
"input": "1... | 1,645,090,629 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 77 | 0 |
lengthOfArrays = input()
arrayA = input()
arrayB = input()
minA = min([int(value) for value in arrayA.split(" ")])
arrayB = [int(value) for value in arrayB.split(" ")]
value = 0
maxB = max(arrayB)
while maxB > minA and arrayB != []:
maxB = max(arrayB)
value += maxB-minA
arrayB.remove... | Title: Devu and his Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays *a* and *b* by their father. The array *a* is given to Devu and *b* to his brother.... | ```python
lengthOfArrays = input()
arrayA = input()
arrayB = input()
minA = min([int(value) for value in arrayA.split(" ")])
arrayB = [int(value) for value in arrayB.split(" ")]
value = 0
maxB = max(arrayB)
while maxB > minA and arrayB != []:
maxB = max(arrayB)
value += maxB-minA
arr... | 0 | |
177 | A1 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which ha... | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 po... | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 30 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
... | 1,607,009,491 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS1 | 2 | 248 | 0 | x = int(input())
ans = 0
mid = ((x-1)//2) - 1
lst = []
for k in range(0, x):
lst.append(list(map(int, input().split())))
for k in range(0, x):
ans = ans + lst[k][mid] + lst[mid][k] + lst[k][k] + lst[x-k-1][k]
print(ans-3) | Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the ... | ```python
x = int(input())
ans = 0
mid = ((x-1)//2) - 1
lst = []
for k in range(0, x):
lst.append(list(map(int, input().split())))
for k in range(0, x):
ans = ans + lst[k][mid] + lst[mid][k] + lst[k][k] + lst[x-k-1][k]
print(ans-3)
``` | 0 | |
620 | C | Pearls in a Row | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of pearls in a row.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) – the type of the *i*-th pearl. | On the first line print integer *k* — the maximal number of segments in a partition of the row.
Each of the next *k* lines should contain two integers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the number of the leftmost and the rightmost pearls in the *j*-th segment.
Note you should print the correct partit... | [
"5\n1 2 3 4 1\n",
"5\n1 2 3 4 5\n",
"7\n1 2 1 3 1 2 1\n"
] | [
"1\n1 5\n",
"-1\n",
"2\n1 3\n4 7\n"
] | none | 0 | [
{
"input": "5\n1 2 3 4 1",
"output": "1\n1 5"
},
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "7\n1 2 1 3 1 2 1",
"output": "2\n1 3\n4 7"
},
{
"input": "9\n1 2 1 2 1 2 1 2 1",
"output": "3\n1 3\n4 6\n7 9"
},
{
"input": "11\n1 1 2 1 2 1 2 1 2 1 1",
"... | 1,592,283,270 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 307,200 | import sys
inputNum=input()
inputTypes=input().split(' ')
stack1=[]
stack2=[]
stack3=[]
for i in range(len(inputTypes)):
if len(stack1)==0:
stack1.append(inputTypes[i])
stack2.append(str(i+1))
else:
if inputTypes[i] in stack1:
stack2.append(str(i+1))
... | Title: Pearls in a Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*.
Let's call a sequence of consecutive pearls a segment. Let's call a ... | ```python
import sys
inputNum=input()
inputTypes=input().split(' ')
stack1=[]
stack2=[]
stack3=[]
for i in range(len(inputTypes)):
if len(stack1)==0:
stack1.append(inputTypes[i])
stack2.append(str(i+1))
else:
if inputTypes[i] in stack1:
stack2.append(str(i+1))
... | 0 | |
306 | D | Polygon | PROGRAMMING | 2,300 | [
"constructive algorithms",
"geometry"
] | null | null | Polycarpus loves convex polygons, especially if all their angles are the same and all their sides are different. Draw for him any such polygon with the given number of vertexes. | The input contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of the polygon vertexes. | Print *n* lines, containing the coordinates of the vertexes of the *n*-gon "*x**i* *y**i*" in the counter clockwise order. The coordinates of the vertexes shouldn't exceed 106 in their absolute value. The side lengths should fit within limits [1,<=1000] (not necessarily integer). Mutual comparing sides and angles of yo... | [
"8\n"
] | [
"1.000 0.000\n7.000 0.000\n9.000 2.000\n9.000 3.000\n5.000 7.000\n3.000 7.000\n0.000 4.000\n0.000 1.000\n"
] | none | 2,000 | [] | 1,692,091,811 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1692091811.556827")# 1692091811.5568433 | Title: Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves convex polygons, especially if all their angles are the same and all their sides are different. Draw for him any such polygon with the given number of vertexes.
Input Specification:
The input contains a single... | ```python
print("_RANDOM_GUESS_1692091811.556827")# 1692091811.5568433
``` | 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,692,081,549 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n , m,a = input().split(' ')
result = int(n)*int(m)/int(a)
final = int(n)*int(m) / result
print('{:.0f}'.format(final))
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n , m,a = input().split(' ')
result = int(n)*int(m)/int(a)
final = int(n)*int(m) / result
print('{:.0f}'.format(final))
``` | 0 |
915 | B | Browser | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong ... | The only line of input contains four integer numbers *n*, *pos*, *l*, *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*pos*<=≤<=*n*, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened. | Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [*l*,<=*r*]. | [
"6 3 2 4\n",
"6 3 1 3\n",
"5 2 1 5\n"
] | [
"5\n",
"1\n",
"0\n"
] | In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.
In the second test she only needs to close all the tabs to the right of the current ... | 0 | [
{
"input": "6 3 2 4",
"output": "5"
},
{
"input": "6 3 1 3",
"output": "1"
},
{
"input": "5 2 1 5",
"output": "0"
},
{
"input": "100 1 1 99",
"output": "99"
},
{
"input": "100 50 1 99",
"output": "50"
},
{
"input": "100 99 1 99",
"output": "1"
},... | 1,559,220,228 | 828 | Python 3 | OK | TESTS | 229 | 124 | 0 | n, p, l, r = map(int, input().split())
res = 0
if p <= l:
res += l - p
if l > 1: res += 1
if r < n:
res += r - l
res += 1
elif p >= r:
res += p - r
if r < n: res += 1
if l > 1:
res += r - l
res += 1
elif l != 1 or r != n:
if l == 1:
re... | Title: Browser
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *... | ```python
n, p, l, r = map(int, input().split())
res = 0
if p <= l:
res += l - p
if l > 1: res += 1
if r < n:
res += r - l
res += 1
elif p >= r:
res += p - r
if r < n: res += 1
if l > 1:
res += r - l
res += 1
elif l != 1 or r != n:
if l == 1:
... | 3 | |
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,545,342,227 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 14,131,200 | n = int( input() )
a = []
for i in range(n):
x = int( input() )
a.append( x )
a = sorted(a)
used = [False] * n
mid = (n//2)
ans = 0
for i in range( n ):
if i > mid:
break
while True:
if a[i]+a[i] <= a[mid]:
if used[i] == False and used[mid] == False:... | Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ... | ```python
n = int( input() )
a = []
for i in range(n):
x = int( input() )
a.append( x )
a = sorted(a)
used = [False] * n
mid = (n//2)
ans = 0
for i in range( n ):
if i > mid:
break
while True:
if a[i]+a[i] <= a[mid]:
if used[i] == False and used[mid]... | 0 | |
926 | D | Choose Place | PROGRAMMING | 1,600 | [] | null | null | A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the p... | The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' — the description of the left desk in the current row; a character '-' — the aisle; two characters, each is '*' or '.' — the de... | Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input.
If there are multiple answers, print a... | [
"..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..\n",
"**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..\n",
"**-**-*.\n*.-*.-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..\n"
] | [
"..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-..\n",
"**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-..\n",
"**-**-*.\n*.-*P-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..\n"
] | In the first example the maximum convenience is 3.
In the second example the maximum convenience is 2.
In the third example the maximum convenience is 4. | 0 | [
{
"input": "..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..",
"output": "..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-.."
},
{
"input": "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..",
"output": "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-.."
},
... | 1,521,307,017 | 6,117 | Python 3 | OK | TESTS | 32 | 77 | 7,065,600 | l = [[],[],[],[],[],[]];
y = [[3, 3, 4, 4, 3, 3],
[3, 3, 4, 4, 3, 3],
[2, 2, 3, 3, 2, 2],
[2, 2, 3, 3, 2, 2],
[1, 1, 2, 2, 1, 1],
[1, 1, 2, 2, 1, 1]]
for i in range(6):
s = input()
for j in s:
if (j != '-'):
l[i].append(j)
maxm = 0
maxi = 0
maxj = 0
fo... | Title: Choose Place
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right.
Some places are already occupied, and some places are vacant. Petya h... | ```python
l = [[],[],[],[],[],[]];
y = [[3, 3, 4, 4, 3, 3],
[3, 3, 4, 4, 3, 3],
[2, 2, 3, 3, 2, 2],
[2, 2, 3, 3, 2, 2],
[1, 1, 2, 2, 1, 1],
[1, 1, 2, 2, 1, 1]]
for i in range(6):
s = input()
for j in s:
if (j != '-'):
l[i].append(j)
maxm = 0
maxi = 0
ma... | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,629,282,440 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 154 | 6,758,400 | n=int(input())
s1=1
s2=0
t1=input().strip()
t2=""
for _ in range(n-1):
name=input().strip()
if name==t1:
s1+=1
else:
if t2=="":
t2=name
s2+=1
if s1>s2:
print(t1)
else:
print(t2)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n=int(input())
s1=1
s2=0
t1=input().strip()
t2=""
for _ in range(n-1):
name=input().strip()
if name==t1:
s1+=1
else:
if t2=="":
t2=name
s2+=1
if s1>s2:
print(t1)
else:
print(t2)
``` | 3.948911 |
285 | C | Building Permutation | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print a single number — the minimum number of moves.
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. | [
"2\n3 0\n",
"3\n-1 -1 2\n"
] | [
"2\n",
"6\n"
] | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | 1,500 | [
{
"input": "2\n3 0",
"output": "2"
},
{
"input": "3\n-1 -1 2",
"output": "6"
},
{
"input": "5\n-3 5 -3 3 3",
"output": "10"
},
{
"input": "10\n9 6 -2 4 1 1 1 9 6 2",
"output": "18"
},
{
"input": "9\n2 0 0 6 5 4 1 9 3",
"output": "15"
},
{
"input": "100... | 1,562,600,882 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 467 | 25,395,200 | n = int(input())
a = list(map(int,input().split()))
a.sort()
count = 0
for i in range(n):
count += abs(i+1-a[i])
print(count)
| Title: Building Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *... | ```python
n = int(input())
a = list(map(int,input().split()))
a.sort()
count = 0
for i in range(n):
count += abs(i+1-a[i])
print(count)
``` | 3 | |
567 | C | Geometric Progression | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"dp"
] | null | null | Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers.
He wants to know how many subsequences of length three can be selected from *a*, so that they form a geo... | The first line of the input contains two integers, *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of the sequence. | Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*. | [
"5 2\n1 1 2 2 4\n",
"3 1\n1 1 1\n",
"10 3\n1 2 6 2 3 6 9 18 3 9\n"
] | [
"4",
"1",
"6"
] | In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4. | 1,500 | [
{
"input": "5 2\n1 1 2 2 4",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "1"
},
{
"input": "10 3\n1 2 6 2 3 6 9 18 3 9",
"output": "6"
},
{
"input": "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "5 3\n5 15 15 15 45... | 1,666,115,095 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n, k, *_ = list(map(int, input().split()))
a = list(map(int, input().split()))
rights = dict()
lefts = dict()
for i in a:
rights[i] = rights.get(i, 0)+1
k1 = 0
k2 = 0
ans = 0
for i in a:
if i%k==0:
k1=lefts.get(i/k, 0)
rights[i] -= 1
k2= rights.get(i*k, 0);
ans+= k1*k2
lefts[i] = lefts.get(i,0... | Title: Geometric Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers... | ```python
n, k, *_ = list(map(int, input().split()))
a = list(map(int, input().split()))
rights = dict()
lefts = dict()
for i in a:
rights[i] = rights.get(i, 0)+1
k1 = 0
k2 = 0
ans = 0
for i in a:
if i%k==0:
k1=lefts.get(i/k, 0)
rights[i] -= 1
k2= rights.get(i*k, 0);
ans+= k1*k2
lefts[i] = lef... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 0 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,593,849,298 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 218 | 716,800 | import sys
flag = True
bin_num = input()
bin_num = list(bin_num)
try:
idx = bin_num.index('1')
except ValueError:
print(0)
sys.exit()
while bin_num[0] == '0':
bin_num.remove('0')
flag = False
try:
if flag:
bin_num.remove(bin_num[bin_num.index('0')])
except ValueError:
if... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly o... | ```python
import sys
flag = True
bin_num = input()
bin_num = list(bin_num)
try:
idx = bin_num.index('1')
except ValueError:
print(0)
sys.exit()
while bin_num[0] == '0':
bin_num.remove('0')
flag = False
try:
if flag:
bin_num.remove(bin_num[bin_num.index('0')])
except ValueErr... | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,658,698,228 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | word = input()
uppercase=0
lowercase=0
for i in range(len(word)):
if word[i] == word[i].capitalize():
uppercase+=1
else:
lowercase+=1
if lowercase >= uppercase:
print(word.lower())
elif uppercase > lowercase:
print(word.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word = input()
uppercase=0
lowercase=0
for i in range(len(word)):
if word[i] == word[i].capitalize():
uppercase+=1
else:
lowercase+=1
if lowercase >= uppercase:
print(word.lower())
elif uppercase > lowercase:
print(word.upper())
``` | 3.969 |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,695,231,947 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 5,222,400 | n = int(input())
ans = 1
for i in range(n):
x = input()
if i > 0 and y[1] == x[0]:
ans += 1
y = x
print(ans) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input())
ans = 1
for i in range(n):
x = input()
if i > 0 and y[1] == x[0]:
ans += 1
y = x
print(ans)
``` | 0 | |
607 | A | Chain Reaction | PROGRAMMING | 1,600 | [
"binary search",
"dp"
] | null | null | There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however.... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons.
The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beac... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | [
"4\n1 9\n3 1\n6 1\n7 4\n",
"7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n"
] | [
"1\n",
"3\n"
] | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | 500 | [
{
"input": "4\n1 9\n3 1\n6 1\n7 4",
"output": "1"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1",
"output": "3"
},
{
"input": "1\n0 1",
"output": "0"
},
{
"input": "1\n0 1000000",
"output": "0"
},
{
"input": "1\n1000000 1000000",
"output": "0"
},
{
... | 1,551,673,916 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 307,200 | n=int(input())
dish=[]
ju=[]
while(n):
m=[int(x) for x in input().split()]
dish.append(m)
ju.append(m[0])
n=n-1
des=[]
for a in range(len(dish)):
low=dish[a][0]-dish[a][1]
high=dish[a][0]
count=0
for t in range(low,high):
if t in ju:
count=count+1
des.append(count)
p=max(des)
des.reverse()
d... | Title: Chain Reaction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of d... | ```python
n=int(input())
dish=[]
ju=[]
while(n):
m=[int(x) for x in input().split()]
dish.append(m)
ju.append(m[0])
n=n-1
des=[]
for a in range(len(dish)):
low=dish[a][0]-dish[a][1]
high=dish[a][0]
count=0
for t in range(low,high):
if t in ju:
count=count+1
des.append(count)
p=max(des)
des.re... | 0 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,695,247,637 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=input()
k=input().split()
s=1
l=[]
for i in range(len(k)-1):
if int(k[i])<=int(k[i+1]):
s+=1
else:
l.append(s)
s-=s-1
if len(l)>1:
print(max(l))
else:
print(s) | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n=input()
k=input().split()
s=1
l=[]
for i in range(len(k)-1):
if int(k[i])<=int(k[i+1]):
s+=1
else:
l.append(s)
s-=s-1
if len(l)>1:
print(max(l))
else:
print(s)
``` | 0 | |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,697,622,500 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 11 | 46 | 0 | x,y=map(int,input().split())
c=0
while c<y:
if x%10!=0:
x-=1
elif x%10==0:
x=x//10
c+=1
print(x) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
x,y=map(int,input().split())
c=0
while c<y:
if x%10!=0:
x-=1
elif x%10==0:
x=x//10
c+=1
print(x)
``` | 3 | |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
... | 1,689,687,691 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 156 | 0 | n = int(input())
bottles = [0] * 1001
li = set()
di = {}
for i in range(n):
a,b = map(int, input().split())
if b in di:
di[b] += 1
else:
di[b] = 1
if a != b:
if a in di:
di[a] -= 1
else:
di[a] = -1
cnt = 0
for key,val in di.items():
if ... | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th... | ```python
n = int(input())
bottles = [0] * 1001
li = set()
di = {}
for i in range(n):
a,b = map(int, input().split())
if b in di:
di[b] += 1
else:
di[b] = 1
if a != b:
if a in di:
di[a] -= 1
else:
di[a] = -1
cnt = 0
for key,val in di.items(... | 0 | |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh... | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"... | 1,644,388,259 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | n,m=map(int,input().split())
L=[list(map(int,input().split()))for i in range(n)]
M=[0]*m
S=0
for i in range(n):
ll=sum(L[i])
S+=(1<<ll)-1+(1<<(m-ll))-1
for j in range(m):M[j]+=L[i][j]
for x in M:
S+=max(0,(1<<x)-1-x)+max(0,(1<<(n-x))-1-(n-x))
print(S) | Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or ... | ```python
n,m=map(int,input().split())
L=[list(map(int,input().split()))for i in range(n)]
M=[0]*m
S=0
for i in range(n):
ll=sum(L[i])
S+=(1<<ll)-1+(1<<(m-ll))-1
for j in range(m):M[j]+=L[i][j]
for x in M:
S+=max(0,(1<<x)-1-x)+max(0,(1<<(n-x))-1-(n-x))
print(S)
``` | 3 | |
828 | B | Black Square | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum pos... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | [
"5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n",
"1 2\nBB\n",
"3 3\nWWW\nWWW\nWWW\n"
] | [
"5\n",
"-1\n",
"1\n"
] | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | 750 | [
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW",
"output": "5"
},
{
"input": "1 2\nBB",
"output": "-1"
},
{
"input": "3 3\nWWW\nWWW\nWWW",
"output": "1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n... | 1,500,780,380 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 46 | 4,915,200 | # http://codeforces.com/problemset/problem/828/B
def solve(n, m, arr):
b_cells = []
for row in range(n):
for col in range(m):
if arr[row][col] == 'B':
b_cells.append((row, col))
if len(b_cells) < 2:
return 1
top = b_cells[0][0]
right = b_ce... | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of w... | ```python
# http://codeforces.com/problemset/problem/828/B
def solve(n, m, arr):
b_cells = []
for row in range(n):
for col in range(m):
if arr[row][col] == 'B':
b_cells.append((row, col))
if len(b_cells) < 2:
return 1
top = b_cells[0][0]
ri... | -1 | |
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,517,971,903 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,632,000 | n,k=map(int,input().split())
if n==3:print("1 2 3")
else:
ans=3
t=180/n
for i in range(4,n+1):
if abs(k-(i-2)*t)<abs(k-(ans-2)*t):
ans=i
print(*[1,2,ans])
| 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,k=map(int,input().split())
if n==3:print("1 2 3")
else:
ans=3
t=180/n
for i in range(4,n+1):
if abs(k-(i-2)*t)<abs(k-(ans-2)*t):
ans=i
print(*[1,2,ans])
``` | 0 | |
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},... | 1,633,096,707 | 2,607 | PyPy 3 | OK | TESTS | 157 | 295 | 31,129,600 | a = str(input())
b = str(input())
from collections import defaultdict
A = [c for c in a]
B = [c for c in b]
A.sort(reverse=True)
if int(''.join(A)) < int(''.join(B)):
print(int(''.join(A)))
exit()
n = len(B)
A = [int(c) for c in A]
B = [int(c) for c in B]
dp = [[defaultdict(lambda: 0) for i in... | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allow... | ```python
a = str(input())
b = str(input())
from collections import defaultdict
A = [c for c in a]
B = [c for c in b]
A.sort(reverse=True)
if int(''.join(A)) < int(''.join(B)):
print(int(''.join(A)))
exit()
n = len(B)
A = [int(c) for c in A]
B = [int(c) for c in B]
dp = [[defaultdict(lambda: 0... | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,670,327,037 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a = int(input())
b = list(map(int,input().split()))
b.sort()
ix = b.index(b[-1])
sumax = 0
sumin = 0
if a%2==0:
for i in range(ix,-1,-1):
if i%2==1:
sumax += b[i]
else:
sumin += b[i]
print(sumax, sumin)
else:
for i in range(ix,-1,-1):
if i%2==0:... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
a = int(input())
b = list(map(int,input().split()))
b.sort()
ix = b.index(b[-1])
sumax = 0
sumin = 0
if a%2==0:
for i in range(ix,-1,-1):
if i%2==1:
sumax += b[i]
else:
sumin += b[i]
print(sumax, sumin)
else:
for i in range(ix,-1,-1):
... | 0 | |
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes... | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n14... | 1,587,587,021 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 140 | 0 | s=input().split(":")
a=int(input())
s[1] = int(s[1]) + a
x = s[1]//60
s[0]=(int(s[0]) + x)%24
s[1] %= 60
res=''
if s[0]<10:
res+='0' + str(s[0])
if s[1]<10:
res+=':0' + str(s[1])
else:
res+=':'+str(s[1])
else:
res+=str(s[0])
if s[1]<10:
res+=':0' + str(s[1])
... | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read mo... | ```python
s=input().split(":")
a=int(input())
s[1] = int(s[1]) + a
x = s[1]//60
s[0]=(int(s[0]) + x)%24
s[1] %= 60
res=''
if s[0]<10:
res+='0' + str(s[0])
if s[1]<10:
res+=':0' + str(s[1])
else:
res+=':'+str(s[1])
else:
res+=str(s[0])
if s[1]<10:
res+=':0' + s... | 3 | |
164 | D | Minimum Diameter | PROGRAMMING | 3,100 | [
"binary search",
"brute force"
] | null | null | You are given *n* points on the plane. You need to delete exactly *k* of them (*k*<=<<=*n*) so that the diameter of the set of the remaining *n*<=-<=*k* points were as small as possible. The diameter of a set of points is the maximum pairwise distance between the points of the set. The diameter of a one point set eq... | The first input line contains a pair of integers *n*,<=*k* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=30, *k*<=<<=*n*) — the numbers of points on the plane and the number of points to delete, correspondingly.
Next *n* lines describe the points, one per line. Each description consists of a pair of integers *x**i*,<=*y**i* (... | Print *k* different space-separated integers from 1 to *n* — the numbers of points to delete. The points are numbered in the order, in which they are given in the input from 1 to *n*. You can print the numbers in any order. If there are multiple solutions, print any of them. | [
"5 2\n1 2\n0 0\n2 2\n1 1\n3 3\n",
"4 1\n0 0\n0 0\n1 1\n1 1\n"
] | [
"5 2",
"3"
] | none | 2,500 | [] | 1,692,704,666 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1692704666.3079367")# 1692704666.30795 | Title: Minimum Diameter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on the plane. You need to delete exactly *k* of them (*k*<=<<=*n*) so that the diameter of the set of the remaining *n*<=-<=*k* points were as small as possible. The diameter of a set of poi... | ```python
print("_RANDOM_GUESS_1692704666.3079367")# 1692704666.30795
``` | 0 | |
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F... | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input... | 1,658,146,005 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 2 | 1,964 | 268,390,400 | n=int(input())
if(n==1):
print(0,0,1)
if(n==2):
print(0,1,1)
arr=[0,1]
i=1
while(i!=n):
i=arr[-1]+arr[-2]
arr.append(i)
# print(arr[n],arr[n-2],arr[n-3])
print(arr[-2],arr[-4],arr[-5]) | Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let'... | ```python
n=int(input())
if(n==1):
print(0,0,1)
if(n==2):
print(0,1,1)
arr=[0,1]
i=1
while(i!=n):
i=arr[-1]+arr[-2]
arr.append(i)
# print(arr[n],arr[n-2],arr[n-3])
print(arr[-2],arr[-4],arr[-5])
``` | 0 | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,696,664,091 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 265 | 14,540,800 | n = int(input())
l = []
for i in range(n):
l.append(tuple(map(int,input().split())))
l.sort(reverse=True)
check = False
for i in range(0,n-1):
if l[i][1] < l[i+1][1]:
print('Happy Alex')
check = True
break
if not check:
print("Poor Alex") | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n = int(input())
l = []
for i in range(n):
l.append(tuple(map(int,input().split())))
l.sort(reverse=True)
check = False
for i in range(0,n-1):
if l[i][1] < l[i+1][1]:
print('Happy Alex')
check = True
break
if not check:
print("Poor Alex")
``` | 3 | |
24 | B | F1 Champions | PROGRAMMING | 1,500 | [
"implementation"
] | B. F1 Champions | 2 | 256 | Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the cha... | The first line contain integer *t* (1<=≤<=*t*<=≤<=20), where *t* is the number of races. After that all races are described one by one. Every race description start with an integer *n* (1<=≤<=*n*<=≤<=50) on a line of itself, where *n* is the number of clasified drivers in the given race. After that *n* lines follow wit... | Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule. | [
"3\n3\nHamilton\nVettel\nWebber\n2\nWebber\nVettel\n2\nHamilton\nVettel\n",
"2\n7\nProst\nSurtees\nNakajima\nSchumacher\nButton\nDeLaRosa\nBuemi\n8\nAlonso\nProst\nNinoFarina\nJimClark\nDeLaRosa\nNakajima\nPatrese\nSurtees\n"
] | [
"Vettel\nHamilton\n",
"Prost\nProst\n"
] | It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50. | 0 | [
{
"input": "3\n3\nHamilton\nVettel\nWebber\n2\nWebber\nVettel\n2\nHamilton\nVettel",
"output": "Vettel\nHamilton"
},
{
"input": "2\n7\nProst\nSurtees\nNakajima\nSchumacher\nButton\nDeLaRosa\nBuemi\n8\nAlonso\nProst\nNinoFarina\nJimClark\nDeLaRosa\nNakajima\nPatrese\nSurtees",
"output": "Prost\nP... | 1,638,519,841 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 154 | 2,252,800 | points = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
racers = {}
# [total_points, [places]]
t = int(input())
for i in range(t):
n = int(input())
for j in range(n):
name = str(input())
if name not in racers:
racers[name] = [0, []]
if j <= 10:
racers[name... | Title: F1 Champions
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 1... | ```python
points = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
racers = {}
# [total_points, [places]]
t = int(input())
for i in range(t):
n = int(input())
for j in range(n):
name = str(input())
if name not in racers:
racers[name] = [0, []]
if j <= 10:
r... | -1 |
659 | E | New Reform | PROGRAMMING | 1,600 | [
"data structures",
"dfs and similar",
"dsu",
"graphs",
"greedy"
] | null | null | Berland has *n* cities connected by *m* bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads.
The President of Berland decided to make changes to the roa... | The first line of the input contains two positive integers, *n* and *m* — the number of the cities and the number of roads in Berland (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000).
Next *m* lines contain the descriptions of the roads: the *i*-th road is determined by two distinct integers *x**i*,<=*y**i* (1<=≤<=*x... | Print a single integer — the minimum number of separated cities after the reform. | [
"4 3\n2 1\n1 3\n4 3\n",
"5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n",
"6 5\n1 2\n2 3\n4 5\n4 6\n5 6\n"
] | [
"1\n",
"0\n",
"1\n"
] | In the first sample the following road orientation is allowed: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e5b18c46402af724bd3841d549d5d6f52fc16253.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/04481ace... | 1,500 | [
{
"input": "4 3\n2 1\n1 3\n4 3",
"output": "1"
},
{
"input": "5 5\n2 1\n1 3\n2 3\n2 5\n4 3",
"output": "0"
},
{
"input": "6 5\n1 2\n2 3\n4 5\n4 6\n5 6",
"output": "1"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "10 45\n3 5\n2 3\n4 8\n2 5\n... | 1,631,883,940 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 93 | 20,275,200 | from sys import stdin
input=stdin.readline
from collections import defaultdict
class dsu():
def __init__(self,n):
self.parent=[0]*(n)
self.sz=[0]*(n)
def make_set(self,v):
self.parent[v]=v
self.sz[v]=1
def find_set(self,v):
if v==self.parent[v]:
... | Title: New Reform
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland has *n* cities connected by *m* bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other ... | ```python
from sys import stdin
input=stdin.readline
from collections import defaultdict
class dsu():
def __init__(self,n):
self.parent=[0]*(n)
self.sz=[0]*(n)
def make_set(self,v):
self.parent[v]=v
self.sz[v]=1
def find_set(self,v):
if v==self.par... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,613,838,096 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,k=map(int,input().split())
if((n%2==0 and k%2==0) or (k%2!=0 and n%2!=0)):
print(f"{int((n+k)/2 +1)}")
elif(k%2!=0 and n%2=0):
print(f"{int((k-1)+(n/2))}")
elif(n%2!=0 and k%2==0):
print(f"{int((n-1) + (k/2))}") | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n,k=map(int,input().split())
if((n%2==0 and k%2==0) or (k%2!=0 and n%2!=0)):
print(f"{int((n+k)/2 +1)}")
elif(k%2!=0 and n%2=0):
print(f"{int((k-1)+(n/2))}")
elif(n%2!=0 and k%2==0):
print(f"{int((n-1) + (k/2))}")
``` | -1 |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,685,462,140 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 78 | 13,209,600 | x=int(input())
y=list(map(int,input().split()))
mx=max(y)
mn=min(y)
con=0
size=len(y)
for i in range(size):
if y[i] >mn and y[i]<mx:
con+=1
print(con) | 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
x=int(input())
y=list(map(int,input().split()))
mx=max(y)
mn=min(y)
con=0
size=len(y)
for i in range(size):
if y[i] >mn and y[i]<mx:
con+=1
print(con)
``` | 3 | |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,600,065,978 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | a, b, c, d = [int(i) for i in input().split(' ')]
m = a / b
n = 1 - (1 - a / b) * (a - c / d)
print(m / n)
| Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a, b, c, d = [int(i) for i in input().split(' ')]
m = a / b
n = 1 - (1 - a / b) * (a - c / d)
print(m / n)
``` | 0 | |
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,647,533,446 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 16 | 404 | 5,120,000 | import sys
import random
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
#sys.setrecursionlimit(10**8)
from queue import PriorityQueue as pq
from math import gcd
#import math
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : int(input_()... | 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
import sys
import random
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
#sys.setrecursionlimit(10**8)
from queue import PriorityQueue as pq
from math import gcd
#import math
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : in... | 0 | |
430 | A | Points and Segments (easy) | PROGRAMMING | 1,600 | [
"constructive algorithms",
"sortings"
] | null | null | Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following.
Iahub wants to draw *n* distinct points and *m* s... | The first line of input contains two integers: *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=100). The next line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100) — the coordinates of the points. The following *m* lines contain the descriptions of the *m* segments. Each line conta... | If there is no good drawing for a given test, output a single integer -1. Otherwise output *n* integers, each integer must be 0 or 1. The *i*-th number denotes the color of the *i*-th point (0 is red, and 1 is blue).
If there are multiple good drawings you can output any of them. | [
"3 3\n3 7 14\n1 5\n6 10\n11 15\n",
"3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2\n"
] | [
"0 0 0",
"1 0 1 "
] | none | 500 | [
{
"input": "3 3\n3 7 14\n1 5\n6 10\n11 15",
"output": "0 0 0"
},
{
"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2",
"output": "1 0 1 "
},
{
"input": "10 10\n3 4 2 6 1 9 0 5 8 7\n5 7\n2 6\n0 1\n5 6\n3 4\n2 5\n2 10\n4 6\n3 6\n3 7",
"output": "0 1 1 1 0 0 1 0 1 0 "
},
{
"input": "3 3\... | 1,400,564,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n, m = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(range(n))
ys.sort(key=xs.__getitem__)
zs = [i % 2 for i in range(n)]
zs.sort(key=ys.__getitem__)
print(*zs) | Title: Points and Segments (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinkin... | ```python
n, m = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(range(n))
ys.sort(key=xs.__getitem__)
zs = [i % 2 for i in range(n)]
zs.sort(key=ys.__getitem__)
print(*zs)
``` | 0 | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,641,277,080 | 2,147,483,647 | Python 3 | OK | TESTS | 75 | 46 | 0 | x1,y1 = map(int,input().split())
x2,y2 = map(int,input().split())
ans1 = abs(x1-x2)
ans2 = abs(y1-y2)
print(max(ans1,ans2))
| Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
x1,y1 = map(int,input().split())
x2,y2 = map(int,input().split())
ans1 = abs(x1-x2)
ans2 = abs(y1-y2)
print(max(ans1,ans2))
``` | 3 | |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,598,853,784 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 78 | 6,758,400 | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(0,n):
if a[i]>b[i]:
c=c+1
break
if c==0:
print("YES")
else:
print("NO")
| Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(0,n):
if a[i]>b[i]:
c=c+1
break
if c==0:
print("YES")
else:
print("NO")
``` | 0 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,694,699,894 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | matrix=[['']*5]*5
for i in range(0,5):
matrix[i]=list(map(int, input().split()))
flag=0
for i in range(0,5):
if(flag==0):
for a in range(0,5):
if(matrix[i][a]==1):
row=i
col=a
flag=1
break
moves=0
if(col==0 or col==4):
mov... | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
matrix=[['']*5]*5
for i in range(0,5):
matrix[i]=list(map(int, input().split()))
flag=0
for i in range(0,5):
if(flag==0):
for a in range(0,5):
if(matrix[i][a]==1):
row=i
col=a
flag=1
break
moves=0
if(col==0 or col==4... | 3 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,669,804,389 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 3,379,200 | n,k=map(int,input().split())
l=[int(x) for x in input().split()]
m=0
pos=1
for i in range(k):
m+=l[i]
for i in range(n-k):
s=0
for j in range(i,k):
s+=l[j]
if s<m:
m=s
pos=i
print(pos) | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
m=0
pos=1
for i in range(k):
m+=l[i]
for i in range(n-k):
s=0
for j in range(i,k):
s+=l[j]
if s<m:
m=s
pos=i
print(pos)
``` | 0 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,656,512,824 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 186 | 307,200 | from collections import Counter
n=int(input())
*a,=map(int,input().split())
print(max(Counter(a).values()),len(set(a))) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
from collections import Counter
n=int(input())
*a,=map(int,input().split())
print(max(Counter(a).values()),len(set(a)))
``` | 3.952928 |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,697,090,476 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | using namespace std;
int main()
{
short n,i;
cin >> n;
i=0;
while (i<n) {
if (i>0) {cout << "that ";}
if (i%2==0) {cout << "I hate ";} else {cout << "I love ";}
i++;
}
cout << "it";
return 0;
}
| Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
using namespace std;
int main()
{
short n,i;
cin >> n;
i=0;
while (i<n) {
if (i>0) {cout << "that ";}
if (i%2==0) {cout << "I hate ";} else {cout << "I love ";}
i++;
}
cout << "it";
return 0;
}
``` | -1 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,582,024,132 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 0 | # coding: utf - 8
r,t = input().split()
r = int(r)
t = int(t)
f = True
while f:
rt = 2
while rt < r+1:
if (r + 1)%rt == 0:
break
rt+=rt
if rt == r +1:
jn = r +1
f = False
rt+=rt
if t == jn:
print ('YES')
else:
... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
# coding: utf - 8
r,t = input().split()
r = int(r)
t = int(t)
f = True
while f:
rt = 2
while rt < r+1:
if (r + 1)%rt == 0:
break
rt+=rt
if rt == r +1:
jn = r +1
f = False
rt+=rt
if t == jn:
print ('YES'... | 0 |
739 | A | Alyona and mex | PROGRAMMING | 1,700 | [
"constructive algorithms",
"greedy"
] | null | null | Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,... | In the first line print single integer — the maximum possible minimum mex.
In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109.
If there are multiple solutio... | [
"5 3\n1 3\n2 5\n4 5\n",
"4 2\n1 4\n2 4\n"
] | [
"2\n1 0 2 1 0\n",
"3\n5 2 0 1"
] | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | 500 | [
{
"input": "5 3\n1 3\n2 5\n4 5",
"output": "2\n0 1 0 1 0"
},
{
"input": "4 2\n1 4\n2 4",
"output": "3\n0 1 2 0"
},
{
"input": "1 1\n1 1",
"output": "1\n0"
},
{
"input": "2 1\n2 2",
"output": "1\n0 0"
},
{
"input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3",
"output":... | 1,658,331,446 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 436 | 25,088,000 | def main():
n, m = map(int, input().split())
arr = [map(int, input().split()) for _ in range(m)]
val = min([y - x + 1 for x, y in arr])
print(val)
print(("{}" + " {}" * (n - 1)).format(*(i % val for i in range(n))))
main()
| Title: Alyona and mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a s... | ```python
def main():
n, m = map(int, input().split())
arr = [map(int, input().split()) for _ in range(m)]
val = min([y - x + 1 for x, y in arr])
print(val)
print(("{}" + " {}" * (n - 1)).format(*(i % val for i in range(n))))
main()
``` | 3 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,643,382,683 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | l, r = map(int, input().split())
if l % 2 != 0:
l+=1
if l+2 > r:
print(-1)
else:
print(str(l)+' '+ str(l+1)+' '+str(l+2)) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
l, r = map(int, input().split())
if l % 2 != 0:
l+=1
if l+2 > r:
print(-1)
else:
print(str(l)+' '+ str(l+1)+' '+str(l+2))
``` | 3 | |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,582,403,901 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 307,200 | #Codeforces Pages
inp = input()
x = list(inp.split(" "))
n = int(x[0])
p = int(x[1])
k = int(x[2])
b = 1 if p-k<1 else p-k
e = n if p+k>n else p+k
if b !=1:
print("<<",end=" ")
for i in range(b,e+1):
if i==p:
print("("+str(i)+")",end=" ")
else:
print(i,end=" ")
if ... | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
#Codeforces Pages
inp = input()
x = list(inp.split(" "))
n = int(x[0])
p = int(x[1])
k = int(x[2])
b = 1 if p-k<1 else p-k
e = n if p+k>n else p+k
if b !=1:
print("<<",end=" ")
for i in range(b,e+1):
if i==p:
print("("+str(i)+")",end=" ")
else:
print(i,end... | 3 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,610,468,749 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 13,824,000 | n = int(input())
a = list(map(int, input().split()))
b = a[:]
count = 0
for k in range(len(a)):
n1 = a[k]
c = 0
for m in range(k):
if a[m] != 0:
c += 1
for m in range(k):
n2 = b[m]
if n1 == n2:
a[m] = 0
a[k] = 0
... | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n = int(input())
a = list(map(int, input().split()))
b = a[:]
count = 0
for k in range(len(a)):
n1 = a[k]
c = 0
for m in range(k):
if a[m] != 0:
c += 1
for m in range(k):
n2 = b[m]
if n1 == n2:
a[m] = 0
a[k] = 0
... | 0 | |
375 | A | Divisible by Seven | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resu... | The first line contains positive integer *a* in the decimal record. It is guaranteed that the record of number *a* contains digits: 1, 6, 8, 9. Number *a* doesn't contain any leading zeroes. The decimal representation of number *a* contains at least 4 and at most 106 characters. | Print a number in the decimal notation without leading zeroes — the result of the permutation.
If it is impossible to rearrange the digits of the number *a* in the required manner, print 0. | [
"1689\n",
"18906\n"
] | [
"1869\n",
"18690\n"
] | none | 500 | [
{
"input": "1689",
"output": "1869"
},
{
"input": "18906",
"output": "18690"
},
{
"input": "2419323689",
"output": "2432391689"
},
{
"input": "8589157262",
"output": "5857221986"
},
{
"input": "2717172350336955863014903670481525170997949309274087058935108848979319... | 1,693,320,599 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | # print(1869 % 7)
# print(1896 % 7)
# print(1689 % 7)
# print(1698 % 7)
# print(1986 % 7)
# print(1968 % 7)
# print(6891 % 7)
cnt_array =[0 for _ in range(10)]
s = input()
for i in range(len(s)) :
cnt_array[int(s[i])]+=1
rem = 0
l=[]
for i in range(1,10) :
if (i!=1 and i!=6 and i!=8 and i!=9)... | Title: Divisible by Seven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number *a* doesn't ... | ```python
# print(1869 % 7)
# print(1896 % 7)
# print(1689 % 7)
# print(1698 % 7)
# print(1986 % 7)
# print(1968 % 7)
# print(6891 % 7)
cnt_array =[0 for _ in range(10)]
s = input()
for i in range(len(s)) :
cnt_array[int(s[i])]+=1
rem = 0
l=[]
for i in range(1,10) :
if (i!=1 and i!=6 and i!=8... | 0 | |
702 | C | Cellular Network | PROGRAMMING | 1,500 | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than ... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number... | Print minimal *r* so that each city will be covered by cellular network. | [
"3 2\n-2 2 4\n-3 0\n",
"5 3\n1 5 10 14 17\n4 11 15\n"
] | [
"4\n",
"3\n"
] | none | 0 | [
{
"input": "3 2\n-2 2 4\n-3 0",
"output": "4"
},
{
"input": "5 3\n1 5 10 14 17\n4 11 15",
"output": "3"
},
{
"input": "1 1\n-1000000000\n1000000000",
"output": "2000000000"
},
{
"input": "1 1\n1000000000\n-1000000000",
"output": "2000000000"
},
{
"input": "10 10\n... | 1,677,970,051 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 171 | 20,275,200 | import sys
read = sys.stdin.readline
write = sys.stdout.write
n, m = map(int, read().split(" "))
cities = list(map(int, read().split(" ")))
cities.sort()
towers = list(map(int, read().split(" ")))
towers.sort()
ans = 0
l, r = 0, 2 * 10 ** 9
while l <= r:
m = l + (r - l) // 2
covered = 0
i, j = 0, 0
... | Title: Cellular Network
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — ... | ```python
import sys
read = sys.stdin.readline
write = sys.stdout.write
n, m = map(int, read().split(" "))
cities = list(map(int, read().split(" ")))
cities.sort()
towers = list(map(int, read().split(" ")))
towers.sort()
ans = 0
l, r = 0, 2 * 10 ** 9
while l <= r:
m = l + (r - l) // 2
covered = 0
i,... | 3 | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,552,560,117 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 482 | 20,377,600 | #le bsdk
n = int(input())
x = input().split()
x= [int (y) for y in x]
x.sort()
score =0
for i in range(len(x)):
if(i != len(x)-1):
score =score + x[i]*(i+2)
else :
score = score +x[i]*(i+1)
print(score) | Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
#le bsdk
n = int(input())
x = input().split()
x= [int (y) for y in x]
x.sort()
score =0
for i in range(len(x)):
if(i != len(x)-1):
score =score + x[i]*(i+2)
else :
score = score +x[i]*(i+1)
print(score)
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.