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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,595,236,604 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 6,656,000 | word = input()
l=[]
r=[]
if len(word)<=5:
print('NO')
else:
for i in word:
if i in 'heo' or i in 'heo' or i in 'heo' or i in 'heo':
r.append(i)
elif i in 'l':
l.append(i)
else:
continue
if len(r)>3 and len(l)>2:
print('YES')
... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
word = input()
l=[]
r=[]
if len(word)<=5:
print('NO')
else:
for i in word:
if i in 'heo' or i in 'heo' or i in 'heo' or i in 'heo':
r.append(i)
elif i in 'l':
l.append(i)
else:
continue
if len(r)>3 and len(l)>2:
prin... | 0 |
442 | A | Borya and Hanabi | PROGRAMMING | 1,700 | [
"bitmasks",
"brute force",
"implementation"
] | null | null | Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.
Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding *n* cards. The game is somewhat complicated by the fact that everybody sees Borya's cards exc... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Borya's cards. The next line contains the descriptions of *n* cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The... | Print a single integer — the minimum number of hints that the other players should make. | [
"2\nG3 G3\n",
"4\nG4 R4 R3 B3\n",
"5\nB1 Y1 W1 G1 R1\n"
] | [
"0\n",
"2\n",
"4\n"
] | In the first sample Borya already knows for each card that it is a green three.
In the second sample we can show all fours and all red cards.
In the third sample you need to make hints about any four colors. | 500 | [
{
"input": "2\nG3 G3",
"output": "0"
},
{
"input": "4\nG4 R4 R3 B3",
"output": "2"
},
{
"input": "5\nB1 Y1 W1 G1 R1",
"output": "4"
},
{
"input": "10\nY4 B1 R3 G5 R5 W3 W5 W2 R1 Y1",
"output": "6"
},
{
"input": "3\nG4 G3 B4",
"output": "2"
},
{
"input"... | 1,403,193,982 | 2,182 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 62 | 0 | n = int(input())
l = input().split()
assert len(l) == n
colors = "RGBYW"
l2 = [(colors.index(x[0]),int(x[1])-1) for x in l]
#print(l2)
tot = 0
for coord in range(2):
best = 4
for i in range(32):
good = True
for a in range(5):
b = [x[coord] for x in l2 if x[1-coord] == a... | Title: Borya and Hanabi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.
Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is... | ```python
n = int(input())
l = input().split()
assert len(l) == n
colors = "RGBYW"
l2 = [(colors.index(x[0]),int(x[1])-1) for x in l]
#print(l2)
tot = 0
for coord in range(2):
best = 4
for i in range(32):
good = True
for a in range(5):
b = [x[coord] for x in l2 if x[1-c... | 0 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,673,635,408 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | t=int(input())
mishka,chris=0 ,0
for i in range(t):
m,c=map(int,input().split())
if(m>c):
mishka+=1
elif(c>m):
chris+=1
else:
mishka+=1
chris+=1
if(mishka>chris):
print("Mishka")
elif(mishka<chris):
print("Chris")
else:
print("Friendship is mag... | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
t=int(input())
mishka,chris=0 ,0
for i in range(t):
m,c=map(int,input().split())
if(m>c):
mishka+=1
elif(c>m):
chris+=1
else:
mishka+=1
chris+=1
if(mishka>chris):
print("Mishka")
elif(mishka<chris):
print("Chris")
else:
print("Friends... | 3 | |
682 | B | Alyona and Mex | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | [
"5\n1 3 3 3 6\n",
"2\n2 1\n"
] | [
"5\n",
"3\n"
] | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | 1,000 | [
{
"input": "5\n1 3 3 3 6",
"output": "5"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "1\n1000000000",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"... | 1,554,867,562 | 2,147,483,647 | Python 3 | OK | TESTS | 127 | 187 | 9,216,000 | import sys
def minp():
return sys.stdin.readline().strip()
n = int(minp())
k = 0
for i in sorted(map(int,minp().split())):
if i >= k+1:
k += 1
print(k+1) | Title: Alyona and Mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is small... | ```python
import sys
def minp():
return sys.stdin.readline().strip()
n = int(minp())
k = 0
for i in sorted(map(int,minp().split())):
if i >= k+1:
k += 1
print(k+1)
``` | 3 | |
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,670,532,133 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 77 | 0 | n,k=map(int,input().split())
nums=list(map(int,input().split()))
ok=5-k
count=0
from math import ceil
for item in nums:
if item<=ok:
count+=1
if count<3:
print(0)
else:
print(ceil(count/3))
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n,k=map(int,input().split())
nums=list(map(int,input().split()))
ok=5-k
count=0
from math import ceil
for item in nums:
if item<=ok:
count+=1
if count<3:
print(0)
else:
print(ceil(count/3))
``` | 0 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,639,420,602 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n=int(input())
k=input()
k=k.split(sep=' ')
for i in range (len(k)):
k[i]=int(k[i])
k=sorted(k)
ind=len(k)//2
print(k[ind]) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n=int(input())
k=input()
k=k.split(sep=' ')
for i in range (len(k)):
k[i]=int(k[i])
k=sorted(k)
ind=len(k)//2
print(k[ind])
``` | 0 | |
275 | B | Convex Shape | PROGRAMMING | 1,700 | [
"constructive algorithms",
"implementation"
] | null | null | Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the size of the grid. Each of the next *n* lines contains *m* characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.
It's guaranteed that the grid has at least one black cel... | On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. | [
"3 4\nWWBW\nBWWW\nWWWB\n",
"3 1\nB\nB\nW\n"
] | [
"NO\n",
"YES\n"
] | none | 1,000 | [
{
"input": "3 4\nWWBW\nBWWW\nWWWB",
"output": "NO"
},
{
"input": "3 1\nB\nB\nW",
"output": "YES"
},
{
"input": "1 1\nB",
"output": "YES"
},
{
"input": "1 2\nBB",
"output": "YES"
},
{
"input": "2 1\nB\nB",
"output": "YES"
},
{
"input": "1 2\nBW",
"o... | 1,585,707,243 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 15 | 248 | 0 | n, m = map(int, input().split())
a = []
for i in range(n):
a.append(input())
convex = True
b, w = False, False
l, r = 0, m - 1
for i in range(n):
t_l, t_r = -1, m
for j in range(m):
if a[i][j] == 'B':
b = True
if t_l == -1:
t_l = j
r ... | Title: Convex Shape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any anothe... | ```python
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(input())
convex = True
b, w = False, False
l, r = 0, m - 1
for i in range(n):
t_l, t_r = -1, m
for j in range(m):
if a[i][j] == 'B':
b = True
if t_l == -1:
t_l = j
... | 0 | |
570 | A | Elections | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ... | The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes ... | Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm... | 500 | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{... | 1,587,944,847 | 447 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 218 | 2,048,000 | from sys import stdin
n,m=map(int,stdin.readline().strip().split())
cnt=[0 for i in range(m+1)]
wins=[]
for i in range(n):
s=list(map(int,stdin.readline().strip().split()))
mn=-10**20
x=1
y=-1
for i in s:
cnt[x]+=i
if i>mn:
mn=i
y=x
... | Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusu... | ```python
from sys import stdin
n,m=map(int,stdin.readline().strip().split())
cnt=[0 for i in range(m+1)]
wins=[]
for i in range(n):
s=list(map(int,stdin.readline().strip().split()))
mn=-10**20
x=1
y=-1
for i in s:
cnt[x]+=i
if i>mn:
mn=i
y=... | -1 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,689,796,307 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x=int(input())
c=0
for i in range(x):
x=input()
if(x=="Tetrahedron"):
c+=4
if(x=="Cube"):
c+=6
if(x=="Octahedron"):
c+=8
if(x=="Dodecahedron"):
c=+12
if(x=="Icosahedron"):
c+=20
print(c) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
x=int(input())
c=0
for i in range(x):
x=input()
if(x=="Tetrahedron"):
c+=4
if(x=="Cube"):
c+=6
if(x=="Octahedron"):
c+=8
if(x=="Dodecahedron"):
c=+12
if(x=="Icosahedron"):
c+=20
print(c)
``` | 0 | |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,593,863,838 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 280 | 0 |
n , m = map(int , input().split())
r = m % ((n * (n + 1)) // 2)
if r == 0:
print(0)
else:
for i in range(1 , n + 1):
if i <= r:
r -= i
else:
print(r)
break | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
n , m = map(int , input().split())
r = m % ((n * (n + 1)) // 2)
if r == 0:
print(0)
else:
for i in range(1 , n + 1):
if i <= r:
r -= i
else:
print(r)
break
``` | 3.93 |
625 | B | War of the Corporations | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine... | The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. | Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. | [
"intellect\ntell\n",
"google\napple\n",
"sirisiri\nsir\n"
] | [
"1",
"0",
"2"
] | In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri". | 750 | [
{
"input": "intellect\ntell",
"output": "1"
},
{
"input": "google\napple",
"output": "0"
},
{
"input": "sirisiri\nsir",
"output": "2"
},
{
"input": "sirisiri\nsiri",
"output": "2"
},
{
"input": "aaaaaaa\naaaa",
"output": "1"
},
{
"input": "bbbbbb\nbb",... | 1,617,648,069 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | st=input()
l=len(st)
st1=input()
l1=len(st1)
i=0
c=0
while(i<l-l1):
st2=st[i:i+l1]
if(st1==st2):
c=c+1
i=i+l1
else:
i=i+1
print(c)
| Title: War of the Corporations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Last... | ```python
st=input()
l=len(st)
st1=input()
l1=len(st1)
i=0
c=0
while(i<l-l1):
st2=st[i:i+l1]
if(st1==st2):
c=c+1
i=i+l1
else:
i=i+1
print(c)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 0 | [] | 1,689,444,651 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | print("_RANDOM_GUESS_1689444651.6870654")# 1689444651.6870875 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,... | ```python
print("_RANDOM_GUESS_1689444651.6870654")# 1689444651.6870875
``` | 0 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,586,968,519 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 156 | 1,638,400 | n,m=map(int,input().split())
k=int(0)
for _ in range(n):
a=list(map(int,input().split()))
x=int(0)
while x<2*m:
if a[x]==1 or a[x+1]==1:
k=k+1
x=x+2
print(k) | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
n,m=map(int,input().split())
k=int(0)
for _ in range(n):
a=list(map(int,input().split()))
x=int(0)
while x<2*m:
if a[x]==1 or a[x+1]==1:
k=k+1
x=x+2
print(k)
``` | 3 | |
962 | B | Students in Railway Carriage | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carri... | The first line contain three integers $n$, $a$ and $b$ ($1 \le n \le 2\cdot10^{5}$, $0 \le a, b \le 2\cdot10^{5}$, $a + b > 0$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with length $n$, consisting o... | Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete. | [
"5 1 1\n*...*\n",
"6 2 3\n*...*.\n",
"11 3 10\n.*....**.*.\n",
"3 2 3\n***\n"
] | [
"2\n",
"4\n",
"7\n",
"0\n"
] | In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, an... | 0 | [
{
"input": "5 1 1\n*...*",
"output": "2"
},
{
"input": "6 2 3\n*...*.",
"output": "4"
},
{
"input": "11 3 10\n.*....**.*.",
"output": "7"
},
{
"input": "3 2 3\n***",
"output": "0"
},
{
"input": "9 5 3\n*...*...*",
"output": "6"
},
{
"input": "9 2 4\n*.... | 1,618,264,972 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 93 | 2,457,600 | n,a,b=map(int,input().split())
s=input()
sum=0;
ans=0;
k=max(a,b)
for i in range(len(s)):
if(s[i]=='*'):
if(a>b): k=a
else: k=b
if(s[i]=='.'):
if(k==a and a>0):
a-=1
ans+=1
k=b
elif(k==b and b>0):
b-=1
ans+=1
... | Title: Students in Railway Carriage
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-... | ```python
n,a,b=map(int,input().split())
s=input()
sum=0;
ans=0;
k=max(a,b)
for i in range(len(s)):
if(s[i]=='*'):
if(a>b): k=a
else: k=b
if(s[i]=='.'):
if(k==a and a>0):
a-=1
ans+=1
k=b
elif(k==b and b>0):
b-=1
... | 0 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,615,979,302 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 77 | 409,600 | n,m=map(int,input().split())
arr=[]
for i in range(n):
s=input()
arr.append([str(z) for z in s])
c=0
for i in range(n):
for j in range(m):
if arr[i][j]==".":
if i%2==1 and j%2==1:
arr[i][j] = "B"
elif i % 2 == 1 and j % 2 == 0:
arr[... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
n,m=map(int,input().split())
arr=[]
for i in range(n):
s=input()
arr.append([str(z) for z in s])
c=0
for i in range(n):
for j in range(m):
if arr[i][j]==".":
if i%2==1 and j%2==1:
arr[i][j] = "B"
elif i % 2 == 1 and j % 2 == 0:
... | 3 | |
362 | D | Fools and Foolproof Roads | PROGRAMMING | 2,100 | [
"data structures",
"dfs and similar",
"dsu",
"graphs",
"greedy"
] | null | null | You must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country consists of *n* cities, some pairs of cities are connected by bidirectional roads, each road is described by its length *l**i*.
The ... | The first line contains four integers *n* (1<=≤<=*n*<=≤<=105), *m* (0<=≤<=*m*<=≤<=105), *p* (0<=≤<=*p*<=≤<=105), *q* (1<=≤<=*q*<=≤<=*n*) — the number of cities in the Foolland, the number of existing roads, the number of roads that are planned to construct and the required number of regions.
Next *m* lines describe th... | If constructing the roads in the required way is impossible, print a single string "NO" (without the quotes). Otherwise, in the first line print word "YES" (without the quotes), and in the next *p* lines print the road construction plan. Each line of the plan must consist of two distinct integers, giving the numbers of... | [
"9 6 2 2\n1 2 2\n3 2 1\n4 6 20\n1 3 8\n7 8 3\n5 7 2\n",
"2 0 1 2\n",
"2 0 0 2\n"
] | [
"YES\n9 5\n1 9\n",
"NO\n",
"YES\n"
] | Consider the first sample. Before the reform the Foolland consists of four regions. The first region includes cities 1, 2, 3, the second region has cities 4 and 6, the third region has cities 5, 7, 8, the fourth region has city 9. The total length of the roads in these cities is 11, 20, 5 and 0, correspondingly. Accord... | 3,000 | [] | 1,477,824,217 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 61 | 819,200 | import queue as Q
q = Q.PriorityQueue()
q.put((10,'ten'))
q.put((1,'one'))
q.put((5,'five'))
while not q.empty():
print(q.get())
| Title: Fools and Foolproof Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country consists of *n* cities... | ```python
import queue as Q
q = Q.PriorityQueue()
q.put((10,'ten'))
q.put((1,'one'))
q.put((5,'five'))
while not q.empty():
print(q.get())
``` | 0 | |
518 | E | Arthur and Questions | PROGRAMMING | 2,200 | [
"greedy",
"implementation",
"math",
"ternary search"
] | null | null | After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length *n* (*a*1,<=*a*2,<=...,<=*a**n*), consisting of integers and integer *k*, not exceeding *n*.
This sequence had the following property: if you write out the sums of all its segments consisting of *k* consecutive elements ... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105), showing how many numbers are in Arthur's sequence and the lengths of segments respectively.
The next line contains *n* space-separated elements *a**i* (1<=≤<=*i*<=≤<=*n*).
If *a**i* <==<= ?, then the *i*-th element of Arthur's sequence was ... | If Arthur is wrong at some point and there is no sequence that could fit the given information, print a single string "Incorrect sequence" (without the quotes).
Otherwise, print *n* integers — Arthur's favorite sequence. If there are multiple such sequences, print the sequence with the minimum sum |*a**i*|, where |*a*... | [
"3 2\n? 1 2\n",
"5 1\n-10 -9 ? -7 -6\n",
"5 3\n4 6 7 2 9\n"
] | [
"0 1 2 \n",
"-10 -9 -8 -7 -6 \n",
"Incorrect sequence\n"
] | none | 2,500 | [
{
"input": "3 2\n? 1 2",
"output": "0 1 2 "
},
{
"input": "5 1\n-10 -9 ? -7 -6",
"output": "-10 -9 -8 -7 -6 "
},
{
"input": "5 3\n4 6 7 2 9",
"output": "Incorrect sequence"
},
{
"input": "9 3\n? ? ? ? ? ? ? ? ?",
"output": "-1 -1 -1 0 0 0 1 1 1 "
},
{
"input": "5 ... | 1,698,959,127 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 405 | 21,401,600 | INF = 10000000001
def fill(s):
s.insert(0, -INF)
s.append(INF)
i = 0
for j in filter(lambda x: s[x] != '?', range(1, len(s))):
d = i - j
s[j] = int(s[j])
if s[i] > s[j]+d:
raise
a = max(min(d//2, s[j]+d), s[i])
for t in range(i+1, j):
s[t] = a + t - i
i = j
re... | Title: Arthur and Questions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length *n* (*a*1,<=*a*2,<=...,<=*a**n*), consisting of integers and integer *k*, not exceeding *n*.
This sequence had the... | ```python
INF = 10000000001
def fill(s):
s.insert(0, -INF)
s.append(INF)
i = 0
for j in filter(lambda x: s[x] != '?', range(1, len(s))):
d = i - j
s[j] = int(s[j])
if s[i] > s[j]+d:
raise
a = max(min(d//2, s[j]+d), s[i])
for t in range(i+1, j):
s[t] = a + t - i
i... | 3 | |
25 | D | Roads not only in Berland | PROGRAMMING | 1,900 | [
"dsu",
"graphs",
"trees"
] | D. Roads not only in Berland | 2 | 256 | Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are *n* cities in Berland and neighboring countries in total and exactly *n*<=-<=1 two... | The first line contains integer *n* (2<=≤<=*n*<=≤<=1000) — amount of cities in Berland and neighboring countries. Next *n*<=-<=1 lines contain the description of roads. Each road is described by two space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — pair of cities, which the r... | Output the answer, number *t* — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output *t* lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road betw... | [
"2\n1 2\n",
"7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n"
] | [
"0\n",
"1\n3 1 3 7\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7",
"output": "1\n3 1 3 7"
},
{
"input": "3\n3 2\n1 2",
"output": "0"
},
{
"input": "3\n3 1\n3 2",
"output": "0"
},
{
"input": "4\n1 4\n3 1\n3 4",
"output": "1\n3 4 2 4"
},
{
... | 1,620,744,627 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 280 | 22,937,600 | def find_set(v):
if (v == parent[v]):
return v
parent[v] = find_set(parent[v])
return parent[v]
def union_sets(a,b):
a=find_set(a)
b=find_set(b)
if (a!=b):
if (size[a]<size[b]):
a,b = b,a
parent[b] = a
size[a] += size[b]
return True
retur... | Title: Roads not only in Berland
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach a... | ```python
def find_set(v):
if (v == parent[v]):
return v
parent[v] = find_set(parent[v])
return parent[v]
def union_sets(a,b):
a=find_set(a)
b=find_set(b)
if (a!=b):
if (size[a]<size[b]):
a,b = b,a
parent[b] = a
size[a] += size[b]
return True... | 3.887275 |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,621,232,166 | 306 | PyPy 3 | OK | TESTS | 49 | 295 | 12,595,200 |
n = int(input())
l = [int(x) for x in input().split()]
f = [0]*n
f[-1] = l[-1]
for k in range(n-1):
i = n-k-2
# print(i, k)
f[i] = l[i]+l[i+1]
print(*f) | Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
n = int(input())
l = [int(x) for x in input().split()]
f = [0]*n
f[-1] = l[-1]
for k in range(n-1):
i = n-k-2
# print(i, k)
f[i] = l[i]+l[i+1]
print(*f)
``` | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,604,636,516 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 312 | 0 | str=input()
n=len(str)
i=0
while i<n:
if str[i]=='.':
print(0,end="")
i+=1
elif str[i]=='-' and str[i+1]=='.':
print(1,end="")
i+=2
elif str[i]=='-' and str[i+1]=='-':
print(2,end="")
i+=2 | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
str=input()
n=len(str)
i=0
while i<n:
if str[i]=='.':
print(0,end="")
i+=1
elif str[i]=='-' and str[i+1]=='.':
print(1,end="")
i+=2
elif str[i]=='-' and str[i+1]=='-':
print(2,end="")
i+=2
``` | 3.922 |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,543,219,099 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 109 | 0 | def main():
l, r, k = map(int, input().split())
ans = []
x = 1
while x <= r:
if x >= l:
ans.append(x)
x *= k
if ans:
print(' '.join(map(str, ans)))
else:
print(-1)
if __name__ == '__main__':
main() | Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
def main():
l, r, k = map(int, input().split())
ans = []
x = 1
while x <= r:
if x >= l:
ans.append(x)
x *= k
if ans:
print(' '.join(map(str, ans)))
else:
print(-1)
if __name__ == '__main__':
main()
``` | 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,646,079,335 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 122 | 0 | n=int(input())
s=[]
k=[]
a=list(map(int,input().split()))
for i in a:
if i not in s:
s.append(i)
k.append(a.count(i))
l=max(k)
print(l,len(s)) | 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())
s=[]
k=[]
a=list(map(int,input().split()))
for i in a:
if i not in s:
s.append(i)
k.append(a.count(i))
l=max(k)
print(l,len(s))
``` | 3.9695 |
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,682,216,805 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
counts = [0] * 1001
for x in a:
counts[x] += 1
max_count = 0
max_length = 0
for length, count in enumerate(counts):
if count > max_count:
max_count = count
max_length = length
print(max_length, max_count)
| Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = int(input())
a = list(map(int, input().split()))
counts = [0] * 1001
for x in a:
counts[x] += 1
max_count = 0
max_length = 0
for length, count in enumerate(counts):
if count > max_count:
max_count = count
max_length = length
print(max_length, max_count)
... | 0 |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,688,960,175 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 88 | 62 | 0 | from math import inf
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
a = list(map(int, input().split()))
f = [[inf]*3 for _ in range(n+1)] #第i天休息、比赛、健身的最少休息天数
f[0] = [0, 0, 0]
for i, x in enumerate(a):
f[i+1][0] = min(f[i])+1
if x == 1 or x == 3:
f[i+1][1] = min(f[... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
from math import inf
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
a = list(map(int, input().split()))
f = [[inf]*3 for _ in range(n+1)] #第i天休息、比赛、健身的最少休息天数
f[0] = [0, 0, 0]
for i, x in enumerate(a):
f[i+1][0] = min(f[i])+1
if x == 1 or x == 3:
f[i+1][1... | 3 | |
912 | A | Tricky Alchemy | PROGRAMMING | 800 | [
"implementation"
] | null | null | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ... | The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. | Print a single integer — the minimum number of crystals that Grisha should acquire in addition. | [
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] | [
"2\n",
"1\n",
"2147483648\n"
] | In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output"... | 1,598,432,041 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 108 | 0 | a,b=map(int,input().split())
x,y,z=map(int,input().split())
yellow=(x*2)+y
blue=y+(z*3)
sum1=0
if a>=yellow:
sum1=0
else:
sum1+=yellow-a
if b>=blue:
sum1+=0
else:
sum1+=blue-b
print(sum1) | Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obta... | ```python
a,b=map(int,input().split())
x,y,z=map(int,input().split())
yellow=(x*2)+y
blue=y+(z*3)
sum1=0
if a>=yellow:
sum1=0
else:
sum1+=yellow-a
if b>=blue:
sum1+=0
else:
sum1+=blue-b
print(sum1)
``` | 3 | |
602 | B | Approximating a Constant Range | PROGRAMMING | 1,400 | [
"dp",
"implementation",
"two pointers"
] | null | null | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000). | Print a single number — the maximum length of an almost constant range of the given sequence. | [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] | [
"4\n",
"5\n"
] | In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10]. | 1,000 | [
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 ... | 1,614,320,856 | 2,147,483,647 | PyPy 3 | OK | TESTS | 107 | 171 | 10,649,600 | n = int(input())
a = list(map(int,input().split()))
l = 0
latest_diff = 0
p = 0
ans = 1
for i in range(1,n):
if a[i]!=a[i-1]:
if a[i]-a[i-1]==latest_diff:
l = p+1
latest_diff = a[i]-a[i-1]
p = i-1
ans = max(ans,i-l+1)
print(ans)
| Title: Approximating a Constant Range
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo... | ```python
n = int(input())
a = list(map(int,input().split()))
l = 0
latest_diff = 0
p = 0
ans = 1
for i in range(1,n):
if a[i]!=a[i-1]:
if a[i]-a[i-1]==latest_diff:
l = p+1
latest_diff = a[i]-a[i-1]
p = i-1
ans = max(ans,i-l+1)
print(ans)
``` | 3 | |
862 | B | Mahmoud and Ehab and the bipartiteness | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *... | The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105).
The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree.
It's guaranteed that the given graph is a tree. | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | [
"3\n1 2\n1 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n"
] | [
"0\n",
"2\n"
] | Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))
Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph)
In the first test case the only edge that can be added in such a way, that ... | 1,000 | [
{
"input": "3\n1 2\n1 3",
"output": "0"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6",
"output": "16"
},
{
"input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4",
"output": "16"
},
{
"in... | 1,652,272,179 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | import math
def main_function():
n = int(input())
set_a = [0 for i in range(n + 1)]
set_b = [0 for i in range(n + 1)]
for i in range(n - 1):
a, b = [int(i) for i in input().split(" ")]
if set_a[a] == 1:
set_b[b] = 1
elif set_b[a] == 1:
set_a[... | Title: Mahmoud and Ehab and the bipartiteness
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a gra... | ```python
import math
def main_function():
n = int(input())
set_a = [0 for i in range(n + 1)]
set_b = [0 for i in range(n + 1)]
for i in range(n - 1):
a, b = [int(i) for i in input().split(" ")]
if set_a[a] == 1:
set_b[b] = 1
elif set_b[a] == 1:
... | 0 | |
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤... | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sam... | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"inp... | 1,597,776,007 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 404 | 11,264,000 | [n, k]=list(map(int, input().split()))
arr=list(map(int, input().split()))
dct={}
l ,r = 0, 0
while(l<=r and r<n):
while(r<n):
val=dct.get(arr[r], 0)
if(val):
dct[arr[r]]=val+1
else:
dct[arr[r]]=1
if(len(dct)==k):
break
... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<... | ```python
[n, k]=list(map(int, input().split()))
arr=list(map(int, input().split()))
dct={}
l ,r = 0, 0
while(l<=r and r<n):
while(r<n):
val=dct.get(arr[r], 0)
if(val):
dct[arr[r]]=val+1
else:
dct[arr[r]]=1
if(len(dct)==k):
brea... | 3 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,691,161,594 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | n = int(input()) + 1
while True:
a = n // 1000
b = (n % 1000) // 100
c = (n % 100) // 10
d = (n % 10)
if (a != b and a != c and a != d and b != c and b != d and c != d):
break
else:
n += 1
print(n) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
n = int(input()) + 1
while True:
a = n // 1000
b = (n % 1000) // 100
c = (n % 100) // 10
d = (n % 10)
if (a != b and a != c and a != d and b != c and b != d and c != d):
break
else:
n += 1
print(n)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,615,450,247 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 78 | 0 | a,b = input(), input()
print(format(int(a,2)^int(b,2),'0'+str(len(a))+'b')) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a,b = input(), input()
print(format(int(a,2)^int(b,2),'0'+str(len(a))+'b'))
``` | 3.9805 |
928 | B | Chat | PROGRAMMING | 1,400 | [
"*special",
"dp"
] | null | null | There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the total amount of messages and the number of previous and next messages visible.
The second line features a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*i*), where *a**i* denotes the *i*-th message link... | Print *n* integers with *i*-th denoting the number of distinct messages you can read starting from message *i* and traversing the links while possible. | [
"6 0\n0 1 1 2 3 2\n",
"10 1\n0 1 0 3 4 5 2 3 7 0\n",
"2 2\n0 1\n"
] | [
"1 2 2 3 3 3 \n",
"2 3 3 4 5 6 6 6 8 2 \n",
"2 2 \n"
] | Consider *i* = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go.
In the second sample case *i* = 6 gives you messages 5, 6, 7 since *k* = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6. | 1,250 | [
{
"input": "6 0\n0 1 1 2 3 2",
"output": "1 2 2 3 3 3 "
},
{
"input": "10 1\n0 1 0 3 4 5 2 3 7 0",
"output": "2 3 3 4 5 6 6 6 8 2 "
},
{
"input": "2 2\n0 1",
"output": "2 2 "
},
{
"input": "1 1\n0",
"output": "1 "
},
{
"input": "5 2\n0 1 2 3 1",
"output": "3 4... | 1,519,552,513 | 66,013 | Python 3 | OK | TESTS | 118 | 482 | 12,697,600 | n, k = (int(s) for s in input().split())
a = [0] + [int(s) for s in input().split()]
ans = [0,]
for i in range(1, n + 1):
if not a[i]:
ans.append( min(i - 1, k) + 1 + min(n - i, k) )
else:
if a[i] + k < i - k:
ans.append( min(i - 1, k) + 1 + min(n - i, k) + ans[a[i]] )
... | Title: Chat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More form... | ```python
n, k = (int(s) for s in input().split())
a = [0] + [int(s) for s in input().split()]
ans = [0,]
for i in range(1, n + 1):
if not a[i]:
ans.append( min(i - 1, k) + 1 + min(n - i, k) )
else:
if a[i] + k < i - k:
ans.append( min(i - 1, k) + 1 + min(n - i, k) + ans[a[... | 3 | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,526,477,948 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 7,065,600 | #!/usr/bin/python
import sys
a,b= map(int,input().split())
lisn = []
lism = []
lenw = []
i=1
j=1
opt=[]
ar=[1]
while i<=b:
x,y,z=map(int,input().split())
lisn.append(x)
lism.append(y)
lenw.append(z)
i=i+1
#mark the length with the number of the island
for j in rang... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
#!/usr/bin/python
import sys
a,b= map(int,input().split())
lisn = []
lism = []
lenw = []
i=1
j=1
opt=[]
ar=[1]
while i<=b:
x,y,z=map(int,input().split())
lisn.append(x)
lism.append(y)
lenw.append(z)
i=i+1
#mark the length with the number of the island
for... | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | Drazil created a following problem about putting 1<=×<=2 tiles into an *n*<=×<=*m* grid:
"There is a grid with some cells that are empty and some cells that are occupied. You should use 1<=×<=2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000).
The following *n* lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | If there is no solution or the solution is not unique, you should print the string "Not unique".
Otherwise you should print how to cover all empty cells with 1<=×<=2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format ... | [
"3 3\n...\n.*.\n...\n",
"4 4\n..**\n*...\n*.**\n....\n",
"2 4\n*..*\n....\n",
"1 1\n.\n",
"1 1\n*\n"
] | [
"Not unique\n",
"<>**\n*^<>\n*v**\n<><>\n",
"*<>*\n<><>\n",
"Not unique\n",
"*\n"
] | In the first case, there are indeed two solutions:
and
so the answer is "Not unique". | 0 | [] | 1,533,203,018 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define N 2020
#define ll long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return f?x:-x;
}
char ch[N];
int mp[N][N];
int solution... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil created a following problem about putting 1<=×<=2 tiles into an *n*<=×<=*m* grid:
"There is a grid with some cells that are empty and some cells that are occupied. You should use 1<=×<=2 tiles to cover all empty cells and ... | ```python
#include <bits/stdc++.h>
#define N 2020
#define ll long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return f?x:-x;
}
char ch[N];
int mp[N][N];
in... | -1 | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,686,624,554 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 187 | 2,560,000 | from collections import Counter, deque
s, bank = input(), dict(Counter(input()))
pending = deque()
yay = woops = 0
for letter in s:
if letter in bank:
bank[letter] -= 1
if not bank[letter]: bank.pop(letter)
yay += 1
else:
pending.append(letter)
while pending:
letter = pending.popleft()
lower,... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
from collections import Counter, deque
s, bank = input(), dict(Counter(input()))
pending = deque()
yay = woops = 0
for letter in s:
if letter in bank:
bank[letter] -= 1
if not bank[letter]: bank.pop(letter)
yay += 1
else:
pending.append(letter)
while pending:
letter = pending.popleft(... | 3 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,680,953,305 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 156 | 0 | cnt = 0
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
for i in range(1,d+1):
if i % k == 0 or i%l == 0 or i%m == 0 or i%n==0:
cnt +=1
print(cnt)
| Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
cnt = 0
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
for i in range(1,d+1):
if i % k == 0 or i%l == 0 or i%m == 0 or i%n==0:
cnt +=1
print(cnt)
``` | 3 | |
748 | B | Santa Claus and Keyboard Check | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
... | The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k... | [
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] | [
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] | none | 1,000 | [
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "... | 1,482,661,206 | 4,506 | Python 3 | CHALLENGED | CHALLENGES | 8 | 46 | 4,608,000 | s = input()
c = input()
wrong={}
WR=False
for i in range(len(s)):
if (s[i]!=c[i]):
a=c[i]
b=s[i]
if (b>a):
b,a=a,b
if(a in wrong.keys()):
if(b != wrong[a]):
WR=True
break
wrong[a]=b
if(WR):print(-1)
else:
if(wron... | Title: Santa Claus and Keyboard Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each ke... | ```python
s = input()
c = input()
wrong={}
WR=False
for i in range(len(s)):
if (s[i]!=c[i]):
a=c[i]
b=s[i]
if (b>a):
b,a=a,b
if(a in wrong.keys()):
if(b != wrong[a]):
WR=True
break
wrong[a]=b
if(WR):print(-1)
else:
... | -1 | |
858 | D | Polycarp's phone book | PROGRAMMING | 1,600 | [
"data structures",
"implementation",
"sortings"
] | null | null | There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.
There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for w... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=70000) — the total number of phone contacts in Polycarp's contacts.
The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. | Print exactly *n* lines: the *i*-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the *i*-th number from the contacts. If there are several such sequences, print any of them. | [
"3\n123456789\n100000000\n100123456\n",
"4\n123456789\n193456789\n134567819\n934567891\n"
] | [
"9\n000\n01\n",
"2\n193\n81\n91\n"
] | none | 2,000 | [
{
"input": "3\n123456789\n100000000\n100123456",
"output": "9\n000\n01"
},
{
"input": "4\n123456789\n193456789\n134567819\n934567891",
"output": "2\n193\n81\n91"
},
{
"input": "1\n167038488",
"output": "4"
},
{
"input": "5\n115830748\n403459907\n556271610\n430358099\n41396141... | 1,679,053,411 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 1,606 | 148,684,800 | n = int(input())
dta = dict()
ans = ['0' * 10 for i in range(n)]
bad = set()
for i in range(n):
s = input()
for ln in range(1, 10):
for j in range(0, 9 - ln + 1):
key = s[j:j + ln]
if key in bad:
continue
if dta.get(key, i) != i:
... | Title: Polycarp's phone book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.
There is the latest version of Berdroid OS ... | ```python
n = int(input())
dta = dict()
ans = ['0' * 10 for i in range(n)]
bad = set()
for i in range(n):
s = input()
for ln in range(1, 10):
for j in range(0, 9 - ln + 1):
key = s[j:j + ln]
if key in bad:
continue
if dta.get(key, i) !... | 3 | |
535 | A | Tavas and Nafas | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
He ate coffee mix without... | The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score. | In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. | [
"6\n",
"99\n",
"20\n"
] | [
"six\n",
"ninety-nine\n",
"twenty\n"
] | You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) . | 500 | [
{
"input": "6",
"output": "six"
},
{
"input": "99",
"output": "ninety-nine"
},
{
"input": "20",
"output": "twenty"
},
{
"input": "10",
"output": "ten"
},
{
"input": "15",
"output": "fifteen"
},
{
"input": "27",
"output": "twenty-seven"
},
{
... | 1,429,861,894 | 2,734 | Python 3 | OK | TESTS | 100 | 62 | 4,710,400 | def numToWords(num,join=True):
'''words = {} convert an integer number into words'''
units = ['','one','two','three','four','five','six','seven','eight','nine']
teens = ['','eleven','twelve','thirteen','fourteen','fifteen','sixteen', \
'seventeen','eighteen','nineteen']
tens = ['','ten... | Title: Tavas and Nafas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score wit... | ```python
def numToWords(num,join=True):
'''words = {} convert an integer number into words'''
units = ['','one','two','three','four','five','six','seven','eight','nine']
teens = ['','eleven','twelve','thirteen','fourteen','fifteen','sixteen', \
'seventeen','eighteen','nineteen']
tens ... | 3 | |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
}... | 1,606,856,689 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | n = int(input())
meat = []
for i in range(n):
meat.append(list(map(int, input().split())))
cost = 0
i = 0
accept = 0
while i < n:
buy = 0
j = i
while j < n and meat[j][1] >= meat[i][1]:
buy += meat[j][0]
j += 1
print(buy)
cost += buy * meat[i][1]
i = j
if accept == 1:
break
print(cost) | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her ... | ```python
n = int(input())
meat = []
for i in range(n):
meat.append(list(map(int, input().split())))
cost = 0
i = 0
accept = 0
while i < n:
buy = 0
j = i
while j < n and meat[j][1] >= meat[i][1]:
buy += meat[j][0]
j += 1
print(buy)
cost += buy * meat[i][1]
i = j
if accept == 1:
break
pr... | 0 | |
44 | E | Anfisa the Monkey | PROGRAMMING | 1,400 | [
"dp"
] | E. Anfisa the Monkey | 2 | 256 | Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into *k* lines not shorter than *a* and not longer than *b*, for the text to resemble h... | The first line contains three integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=200, 1<=≤<=*a*<=≤<=*b*<=≤<=200). The second line contains a sequence of lowercase Latin letters — the text typed by Anfisa. It is guaranteed that the given line is not empty and its length does not exceed 200 symbols. | Print *k* lines, each of which contains no less than *a* and no more than *b* symbols — Anfisa's text divided into lines. It is not allowed to perform any changes in the text, such as: deleting or adding symbols, changing their order, etc. If the solution is not unique, print any of them. If there is no solution, print... | [
"3 2 5\nabrakadabra\n",
"4 1 2\nabrakadabra\n"
] | [
"ab\nrakad\nabra\n",
"No solution\n"
] | none | 0 | [
{
"input": "3 2 5\nabrakadabra",
"output": "abra\nkada\nbra"
},
{
"input": "4 1 2\nabrakadabra",
"output": "No solution"
},
{
"input": "3 1 2\nvgnfpo",
"output": "vg\nnf\npo"
},
{
"input": "5 3 4\nvrrdnhazvexzjfv",
"output": "vrr\ndnh\nazv\nexz\njfv"
},
{
"input":... | 1,603,669,151 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 280 | 0 | k, a, b = map(int, input().split())
s = input()
l = len(s)
if l < k * a or l > k * b:
print("No solution")
elif l == k * a:
for i in range(k):
print(s[:a])
s = s[a:]
elif l == k * b:
for i in range(k):
print(s[:b])
s = s[b:]
else:
arr = [a] * k
x = l - k * a
i = 0
while x != 0:
arr[i]... | Title: Anfisa the Monkey
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she ... | ```python
k, a, b = map(int, input().split())
s = input()
l = len(s)
if l < k * a or l > k * b:
print("No solution")
elif l == k * a:
for i in range(k):
print(s[:a])
s = s[a:]
elif l == k * b:
for i in range(k):
print(s[:b])
s = s[b:]
else:
arr = [a] * k
x = l - k * a
i = 0
while x != 0:... | 3.93 |
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
... | 1,656,899,572 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int ( input ( ) )
if n % 10 <= 5:
p = n // 10
if n % 10 > 5:
p = ( n // 10 ) + 1
print ( p )
| Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5... | ```python
n = int ( input ( ) )
if n % 10 <= 5:
p = n // 10
if n % 10 > 5:
p = ( n // 10 ) + 1
print ( p )
``` | 0 | |
291 | A | Spyke Talks | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is t... | Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. | [
"6\n0 1 7 1 7 10\n",
"3\n1 1 1\n",
"1\n0\n"
] | [
"2\n",
"-1\n",
"0\n"
] | In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.
In the second test sample the described situation is impossible as conferences aren't allowed. | 500 | [
{
"input": "6\n0 1 7 1 7 10",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n2 2 1 1 3",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n4 21 3 21 21 1 1 2 2 3",
"ou... | 1,631,928,710 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 124 | 6,963,200 | import sys
input = sys.stdin.readline
def inp():
return int(input())
def invr():
return list(map(int, input().split()))
n = inp()
ids = invr()
ids.sort()
v = [0] * (ids[n - 1] + 1)
for x in ids:
v[x] += 1
c = 0
for x in v:
if x == 2:
c += 1
elif x > 2:
... | Title: Spyke Talks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each othe... | ```python
import sys
input = sys.stdin.readline
def inp():
return int(input())
def invr():
return list(map(int, input().split()))
n = inp()
ids = invr()
ids.sort()
v = [0] * (ids[n - 1] + 1)
for x in ids:
v[x] += 1
c = 0
for x in v:
if x == 2:
c += 1
eli... | 0 | |
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,657,174,908 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | def minRotations(text):
rotations = 0
text = text.lower()
prev = 'a'
for ch in text:
rotations += minRotation(ch, prev)
prev = ch
return rotations
def minRotation(ch1, ch2):
v1 = ord(ch1)-ord('a')+1; v2 = ord(ch2)-ord('a')+1
s = min(v1, v2); l = max(v1, v2)
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
def minRotations(text):
rotations = 0
text = text.lower()
prev = 'a'
for ch in text:
rotations += minRotation(ch, prev)
prev = ch
return rotations
def minRotation(ch1, ch2):
v1 = ord(ch1)-ord('a')+1; v2 = ord(ch2)-ord('a')+1
s = min(v1, v2); l = max(v1, ... | 3 | |
1,003 | C | Intense Heat | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"math"
] | null | null | The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually cal... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 5000$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 5000$) — the ... | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $k$ consecutive days.
Your answer will be considered correct if the following condition holds: $|res - res_0| < 10^{-6}$, where $res$ is your answer, and $res_0$ is the answer given by the... | [
"4 3\n3 4 1 2\n"
] | [
"2.666666666666667\n"
] | none | 0 | [
{
"input": "4 3\n3 4 1 2",
"output": "2.666666666666667"
},
{
"input": "5 1\n3 10 9 10 6",
"output": "10.000000000000000"
},
{
"input": "5 2\n7 3 3 1 8",
"output": "5.000000000000000"
},
{
"input": "5 3\n1 7 6 9 1",
"output": "7.333333333333333"
},
{
"input": "5 4... | 1,593,093,549 | 2,349 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 9 | 530 | 268,390,400 | n,k=map(int,input().split())
a=list(map(int,input().split()))
c=[]
for j in range(k,n+1):
c.extend([a[i:i+j] for i in range(n-j+1)])
arr=[]
for i in c:
arr.append(sum(i)/len(i))
print(max(arr)) | Title: Intense Heat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sou... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=[]
for j in range(k,n+1):
c.extend([a[i:i+j] for i in range(n-j+1)])
arr=[]
for i in c:
arr.append(sum(i)/len(i))
print(max(arr))
``` | 0 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,682,179,994 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 122 | 0 | n = int(input())
if n<11:
s=0
elif n<20 or n==21:
s=4
elif n==20:
s=15
else:
s=0
print(s)
| Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
n = int(input())
if n<11:
s=0
elif n<20 or n==21:
s=4
elif n==20:
s=15
else:
s=0
print(s)
``` | 3.9695 |
569 | B | Inventory | PROGRAMMING | 1,200 | [
"greedy",
"math"
] | null | null | Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the... | The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items. | Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. | [
"3\n1 3 2\n",
"4\n2 2 3 3\n",
"1\n2\n"
] | [
"1 3 2 \n",
"2 1 3 4 \n",
"1 \n"
] | In the first test the numeration is already a permutation, so there is no need to change anything.
In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
In the third test you need to replace 2 by 1, as the numbering should start from one. | 1,000 | [
{
"input": "3\n1 3 2",
"output": "1 3 2 "
},
{
"input": "4\n2 2 3 3",
"output": "2 1 3 4 "
},
{
"input": "1\n2",
"output": "1 "
},
{
"input": "3\n3 3 1",
"output": "3 2 1 "
},
{
"input": "5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "5\n5 3 4 4 ... | 1,442,080,866 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 31 | 0 | __author__ = 'dwliv_000'
n=int(input())
g=[int(i) for i in input().split()]
k=1
z=[int(i) for i in range(1,n+1)]
for j in range(n):
if(g[j] in z):
z.remove(g[j])
else:
g[j]=z[k]
z.remove(z[k])
for i in range(n):
print(g[i],end=' ')
| Title: Inventory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numb... | ```python
__author__ = 'dwliv_000'
n=int(input())
g=[int(i) for i in input().split()]
k=1
z=[int(i) for i in range(1,n+1)]
for j in range(n):
if(g[j] in z):
z.remove(g[j])
else:
g[j]=z[k]
z.remove(z[k])
for i in range(n):
print(g[i],end=' ')
``` | -1 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,695,486,111 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | word=input()
word[0].upper()
print(word) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
word=input()
word[0].upper()
print(word)
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,661,877,153 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 186 | 0 | n=int(input())
k=[]
for i in range(n):
x=list(map(int,input().split()))
k.append(x)
sum1=0
sum2=0
sum3=0
for j in range(len(k)):
m=0
sum1=sum1+ k[j][m]
for j in range(len(k)):
m=1
sum2=sum2+k[j][m]
for j in range(len(k)):
m=2
sum3=sum3+k[j][m]
if sum1==0 and sum2==... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
k=[]
for i in range(n):
x=list(map(int,input().split()))
k.append(x)
sum1=0
sum2=0
sum3=0
for j in range(len(k)):
m=0
sum1=sum1+ k[j][m]
for j in range(len(k)):
m=1
sum2=sum2+k[j][m]
for j in range(len(k)):
m=2
sum3=sum3+k[j][m]
if sum1==0 ... | 3.9535 |
558 | B | Amr and The Large Array | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. | Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them. | [
"5\n1 1 2 2 1\n",
"5\n1 2 2 3 1\n",
"6\n1 2 2 1 1 2\n"
] | [
"1 5",
"2 3",
"1 5"
] | A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | 1,000 | [
{
"input": "5\n1 1 2 2 1",
"output": "1 5"
},
{
"input": "5\n1 2 2 3 1",
"output": "2 3"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "1 5"
},
{
"input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1",
"output": "2 7"
},
{
"input": "10\n1 2 3 4 5 5 1 2 3 4",
"output... | 1,436,891,900 | 5,300 | PyPy 3 | RUNTIME_ERROR | PRETESTS | 3 | 93 | 0 | n = int(input())
a = list(map(int, input().split()))
b = [0] * 10
for i in range(n):
b[a[i]] +=1
d = 0
f = []
for i in range(10):
if b[i] > d:
f = []
d = b[i]
f.append(i)
elif b[i] == d:
f.append(i)
l = 0
r = 0
g = 0
l1 = 0
r1 = 0
for i in range(n):
... | Title: Amr and The Large Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to... | ```python
n = int(input())
a = list(map(int, input().split()))
b = [0] * 10
for i in range(n):
b[a[i]] +=1
d = 0
f = []
for i in range(10):
if b[i] > d:
f = []
d = b[i]
f.append(i)
elif b[i] == d:
f.append(i)
l = 0
r = 0
g = 0
l1 = 0
r1 = 0
for i in range... | -1 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,695,451,467 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | word = input()
count = 0
for c in word:
count += (c.isupper())
if (word[0].lower() and count == len(word) - 1) or count == len(word):
print(word.lower())
else:
print(word) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
word = input()
count = 0
for c in word:
count += (c.isupper())
if (word[0].lower() and count == len(word) - 1) or count == len(word):
print(word.lower())
else:
print(word)
``` | 0 | |
440 | A | Forgotten Episode | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watch... | Print the number of the episode that Polycarpus hasn't watched. | [
"10\n3 8 10 1 7 9 6 5 2\n"
] | [
"4\n"
] | none | 500 | [
{
"input": "10\n3 8 10 1 7 9 6 5 2",
"output": "4"
},
{
"input": "5\n4 3 2 1",
"output": "5"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "2\n2",
"output": "1"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "3\n1 3",
"output": "2"
},
... | 1,650,307,244 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 6,963,200 | n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
for i in range(n-1):
b[a[i]-1] = 1
for i in range(n):
if b[i] == 0:
print(i+1)
break | Title: Forgotten Episode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episo... | ```python
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
for i in range(n-1):
b[a[i]-1] = 1
for i in range(n):
if b[i] == 0:
print(i+1)
break
``` | 3 | |
501 | B | Misha and Changing Handles | PROGRAMMING | 1,100 | [
"data structures",
"dsu",
"strings"
] | null | null | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the re... | The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and di... | In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*,... | [
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] | [
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] | none | 500 | [
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd... | 1,614,948,216 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 307,200 | n = int(input())
l = {}
for i in range(n):
o, n = input().split()
l[n] = l.get(o, o)
l.pop(o, None)
print(len(l))
for n, o in l.items():
print(o, n)
| Title: Misha and Changing Handles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is a... | ```python
n = int(input())
l = {}
for i in range(n):
o, n = input().split()
l[n] = l.get(o, o)
l.pop(o, None)
print(len(l))
for n, o in l.items():
print(o, n)
``` | 3 | |
598 | B | Queries on a String | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | null | null | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One ope... | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains thr... | Print the resulting string *s* after processing all *m* queries. | [
"abacaba\n2\n3 6 1\n1 4 2\n"
] | [
"baabcaa\n"
] | The sample is described in problem statement. | 0 | [
{
"input": "abacaba\n2\n3 6 1\n1 4 2",
"output": "baabcaa"
},
{
"input": "u\n1\n1 1 1",
"output": "u"
},
{
"input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4",
"output": "p"
},
{
"input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6",
"output": "ssssssssss"
},
... | 1,660,508,450 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 77 | 307,200 | import sys
readline=sys.stdin.readline
S=list(readline().rstrip())
M=int(readline())
for _ in range(M):
l,r,k=map(int,readline().split())
l-=1
SS=S[l:r]
k%=len(SS)
SS=SS[len(SS)-k:]+SS[:len(SS)-k]
S[l:r]=SS
print(*S,sep="") | Title: Queries on a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**... | ```python
import sys
readline=sys.stdin.readline
S=list(readline().rstrip())
M=int(readline())
for _ in range(M):
l,r,k=map(int,readline().split())
l-=1
SS=S[l:r]
k%=len(SS)
SS=SS[len(SS)-k:]+SS[:len(SS)-k]
S[l:r]=SS
print(*S,sep="")
``` | 3 | |
7 | D | Palindrome Degree | PROGRAMMING | 2,200 | [
"hashing",
"strings"
] | D. Palindrome Degree | 1 | 256 | String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome.
Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For examp... | The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive. | Output the only number — the sum of the polindrome degrees of all the string's prefixes. | [
"a2A\n",
"abacaba\n"
] | [
"1",
"6"
] | none | 0 | [
{
"input": "a2A",
"output": "1"
},
{
"input": "abacaba",
"output": "6"
},
{
"input": "CCeCeCCCee",
"output": "4"
},
{
"input": "opooppppopppopoppopoooppopopooopopppooopppoppoppoppppoooppooooooopppoopoopooooppooooppppppppooopooop",
"output": "3"
},
{
"input": "odri... | 1,462,978,076 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 77,209,600 | __author__ = 'Utena'
from sys import *
def input():
return stdin.readline()
s='0'+input()
n=len(s)
l=r=0
e=1
t=0
d=[0 for i in range(n+1)]
for i in range(1,n):
l=(l*103+ord(s[i]))%1000007
r=(r+ord(s[i])*e)%1000007
e=(e*103)%1000007
if l==r:
d[i]=d[i//2]+1
t+=d[i]
p... | Title: Palindrome Degree
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome.
Let's call the pa... | ```python
__author__ = 'Utena'
from sys import *
def input():
return stdin.readline()
s='0'+input()
n=len(s)
l=r=0
e=1
t=0
d=[0 for i in range(n+1)]
for i in range(1,n):
l=(l*103+ord(s[i]))%1000007
r=(r+ord(s[i])*e)%1000007
e=(e*103)%1000007
if l==r:
d[i]=d[i//2]+1
... | 0 |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,697,103,524 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input("Enter the number of statements: "))
x = 0 # Initial value of x
for i in range(n):
statement = input(f"Enter statement {i + 1}: ")
if "++" in statement:
x += 1
else:
x -= 1
print(f"Final value of x: {x}")
| Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
n = int(input("Enter the number of statements: "))
x = 0 # Initial value of x
for i in range(n):
statement = input(f"Enter statement {i + 1}: ")
if "++" in statement:
x += 1
else:
x -= 1
print(f"Final value of x: {x}")
``` | 0 | |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,659,646,036 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | import sys
n = int(input())
a = list(map(int, input().split()))
m = int(input())
for i in range(m):
x, y = (int(el) for el in input().split())
x -= 1
if x - 1 >= 0:
a[x - 1] += y - 1
if x + 1 <= n - 1:
a[x + 1] += a[x] - y
a[x] = 0
for el in a:
print(el)
... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
import sys
n = int(input())
a = list(map(int, input().split()))
m = int(input())
for i in range(m):
x, y = (int(el) for el in input().split())
x -= 1
if x - 1 >= 0:
a[x - 1] += y - 1
if x + 1 <= n - 1:
a[x + 1] += a[x] - y
a[x] = 0
for el in a:
prin... | 3 | |
977 | C | Less or Equal | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$.
Note that the sequence can contain equal elements.
If there is no suc... | The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the sequence itself. | Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$.
If there is no such $x$, print "-1" (without quotes). | [
"7 4\n3 7 5 1 10 3 20\n",
"7 2\n3 7 5 1 10 3 20\n"
] | [
"6",
"-1\n"
] | In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$.
In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ el... | 0 | [
{
"input": "7 4\n3 7 5 1 10 3 20",
"output": "5"
},
{
"input": "7 2\n3 7 5 1 10 3 20",
"output": "-1"
},
{
"input": "1 0\n1",
"output": "-1"
},
{
"input": "1 0\n2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "3 ... | 1,697,873,474 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
x = arr[k-1]
if k < len(arr) and arr[k] == x:
print(-1)
else:
print(x) | Title: Less or Equal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are... | ```python
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
x = arr[k-1]
if k < len(arr) and arr[k] == x:
print(-1)
else:
print(x)
``` | 0 | |
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted... | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how th... | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output"... | 1,594,724,692 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fo(i,n) for(int i=0; i<n; i++)
#define foo(i,a,n) for(int i=a; i<n; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
void show(vector<auto> v){for(auto it=v.begin(); it!=v.end(); ++it){cout<<*it<<" ";}cou... | Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one... | ```python
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fo(i,n) for(int i=0; i<n; i++)
#define foo(i,a,n) for(int i=a; i<n; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
void show(vector<auto> v){for(auto it=v.begin(); it!=v.end(); ++it){cout<<*it... | -1 | |
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,529,168,592 | 1,692 | PyPy 3 | OK | TESTS | 31 | 140 | 0 | n,m = map(int,input().split())
ikn = list(map(int,input().split()))
stp = list(map(int,input().split()))
code = []
for i in range(n):
if ikn[i] in stp:
code.append(ikn[i])
for i in range(len(code)):
print(code[i],end=' ') | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
n,m = map(int,input().split())
ikn = list(map(int,input().split()))
stp = list(map(int,input().split()))
code = []
for i in range(n):
if ikn[i] in stp:
code.append(ikn[i])
for i in range(len(code)):
print(code[i],end=' ')
``` | 3 | |
958 | D1 | Hyperspace Jump (easy) | PROGRAMMING | 1,400 | [
"expression parsing",
"math"
] | null | null | The Rebel fleet is on the run. It consists of *m* ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independe... | The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) – the number of ships. The next *m* lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer *a* of up to two dec... | Print a single line consisting of *m* space-separated integers. The *i*-th integer should be equal to the number of ships whose coordinate is equal to that of the *i*-th ship (including the *i*-th ship itself). | [
"4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7\n"
] | [
"1 2 2 1 "
] | In the sample testcase, the second and the third ship will both end up at the coordinate 3.
Note that this problem has only two versions – easy and hard. | 0 | [
{
"input": "4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7",
"output": "1 2 2 1 "
},
{
"input": "10\n(44+98)/19\n(36+58)/47\n(62+74)/68\n(69+95)/82\n(26+32)/29\n(32+46)/39\n(32+24)/28\n(47+61)/54\n(39+13)/26\n(98+98)/98",
"output": "1 9 9 9 9 9 9 9 9 9 "
},
{
"input": "30\n(89+76)/87\n(81... | 1,523,690,144 | 644 | Python 3 | OK | TESTS | 16 | 1,762 | 22,835,200 | n=int(input())
dict1={}
dict2={}
for i in range(n):
s=input()
s=s.split('/')
c=int(s[1])
s=s[0].strip('(').strip(')').split('+')
a=int(s[0])
b=int(s[1])
ans=(a+b)/c
try:
dict2[ans] += 1
except:
dict2[ans] = 1
dict1[i] = ans
for i in range(n):
... | Title: Hyperspace Jump (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Rebel fleet is on the run. It consists of *m* ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebe... | ```python
n=int(input())
dict1={}
dict2={}
for i in range(n):
s=input()
s=s.split('/')
c=int(s[1])
s=s[0].strip('(').strip(')').split('+')
a=int(s[0])
b=int(s[1])
ans=(a+b)/c
try:
dict2[ans] += 1
except:
dict2[ans] = 1
dict1[i] = ans
for i in range... | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,609,413,685 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s=input()
t=input()
p1=0
p2=len(s)-1
a=list(s)
while p1>=p2:
t=a[p1]
a[p1]=a[p2]
a[p2]=t
p1+=1
p2-=1
s=''.join(map(str,a))
if s==t:
print('YES')
else:
print('NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s=input()
t=input()
p1=0
p2=len(s)-1
a=list(s)
while p1>=p2:
t=a[p1]
a[p1]=a[p2]
a[p2]=t
p1+=1
p2-=1
s=''.join(map(str,a))
if s==t:
print('YES')
else:
print('NO")
``` | -1 |
69 | E | Subsegments | PROGRAMMING | 1,800 | [
"data structures",
"implementation"
] | E. Subsegments | 1 | 256 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maxi... | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=*n*) — the number of array elements and the length of the segment.
Then follow *n* lines: the *i*-th one contains a single number *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print *n*–*k*<=+<=1 numbers, one per line: on the *i*-th line print of the maximum number of those numbers from the subarray *a**i* *a**i*<=+<=1 … *a**i*<=+<=*k*<=-<=1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | [
"5 3\n1\n2\n2\n3\n3\n",
"6 4\n3\n3\n3\n4\n4\n2\n"
] | [
"1\n3\n2\n",
"4\nNothing\n3\n"
] | none | 2,500 | [
{
"input": "5 3\n1\n2\n2\n3\n3",
"output": "1\n3\n2"
},
{
"input": "6 4\n3\n3\n3\n4\n4\n2",
"output": "4\nNothing\n3"
},
{
"input": "10 3\n-55\n-35\n-80\n91\n-96\n-93\n-39\n-77\n4\n29",
"output": "-35\n91\n91\n91\n-39\n-39\n4\n29"
},
{
"input": "10 3\n-13\n26\n-97\n-38\n43\n-... | 1,649,400,254 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 22 | 1,000 | 2,662,400 |
n, k=map(int,input().split())
nu=[]
for i in range(n):
nu.append(int(input()))
inse=nu[:k]
fre=dict()
si=set()
si.add(-10**10)
for i in range(k):
fre[inse[i]]=inse.count(inse[i])
if inse.count(inse[i])==1:
si.add(inse[i])
a=max(si)
if len(si)==1:
print("Nothing")
else:
... | Title: Subsegments
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned... | ```python
n, k=map(int,input().split())
nu=[]
for i in range(n):
nu.append(int(input()))
inse=nu[:k]
fre=dict()
si=set()
si.add(-10**10)
for i in range(k):
fre[inse[i]]=inse.count(inse[i])
if inse.count(inse[i])==1:
si.add(inse[i])
a=max(si)
if len(si)==1:
print("Nothing")
... | 0 |
1,004 | B | Sonya and Exhibition | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null | Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions shoul... | The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. | Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any. | [
"5 3\n1 3\n2 4\n2 5\n",
"6 3\n5 6\n1 4\n4 6\n"
] | [
"01100",
"110010"
] | In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty ... | 1,000 | [
{
"input": "5 3\n1 3\n2 4\n2 5",
"output": "01010"
},
{
"input": "6 3\n5 6\n1 4\n4 6",
"output": "010101"
},
{
"input": "10 4\n3 3\n1 6\n9 9\n10 10",
"output": "0101010101"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "1000 10\n3 998\n2 1000\n1 999\n2 100... | 1,532,128,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | from math import ceil
n, m = list(map(int,input().split()))
s = [0 for _ in range(n)]
for i in range(m):
l, r = list(map(int,input().split()))
med = ((r-l+1)/2 )
rose, lose = int(med), ceil(med)
for j in range(l-1, r):
if lose!=0:
if s[j]==0:
lose-=1
... | Title: Sonya and Exhibition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the ... | ```python
from math import ceil
n, m = list(map(int,input().split()))
s = [0 for _ in range(n)]
for i in range(m):
l, r = list(map(int,input().split()))
med = ((r-l+1)/2 )
rose, lose = int(med), ceil(med)
for j in range(l-1, r):
if lose!=0:
if s[j]==0:
lose-... | 0 | |
414 | B | Mashmokh and ACM | PROGRAMMING | 1,400 | [
"combinatorics",
"dp",
"number theory"
] | null | null | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog... | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). | Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). | [
"3 2\n",
"6 4\n",
"2 1\n"
] | [
"5\n",
"39\n",
"2\n"
] | In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3]. | 1,000 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "6 4",
"output": "39"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "1478 194",
"output": "312087753"
},
{
"input": "1415 562",
"output": "953558593"
},
{
"input": "1266 844",
"output": "735042656"
... | 1,546,683,783 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 10,240,000 | n, k = map(int, input().split())
d = [[] for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, i+1):
if i % j == 0:
d[i].append(j)
dp = [[0 for _ in range(k)] for _ in range(n+1)]
for i in range(n+1):
dp[i][0] = 1
mod = 10**9+7
for i in range(n+1):
for j in ra... | Title: Mashmokh and ACM
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join h... | ```python
n, k = map(int, input().split())
d = [[] for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, i+1):
if i % j == 0:
d[i].append(j)
dp = [[0 for _ in range(k)] for _ in range(n+1)]
for i in range(n+1):
dp[i][0] = 1
mod = 10**9+7
for i in range(n+1):
f... | 0 | |
92 | B | Binary Number | PROGRAMMING | 1,300 | [
"greedy"
] | B. Binary Number | 1 | 256 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divide... | The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. | Print the required number of actions. | [
"1\n",
"1001001\n",
"101110\n"
] | [
"0\n",
"12\n",
"8\n"
] | Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide... | 1,000 | [
{
"input": "1",
"output": "0"
},
{
"input": "1001001",
"output": "12"
},
{
"input": "101110",
"output": "8"
},
{
"input": "11",
"output": "3"
},
{
"input": "11110001101",
"output": "16"
},
{
"input": "101010100100111100011111001111100001010101111110101... | 1,580,314,741 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 109 | 0 | B=input()
A=0
t=1
for i in range(len(B)-1,-1,-1):
A+=int(B[i])*t
t*=2
sayac=0
while(A!=1):
if((A%2)==1):
A+=1
else:
A/=2
sayac+=1
print(sayac) | Title: Binary Number
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to ... | ```python
B=input()
A=0
t=1
for i in range(len(B)-1,-1,-1):
A+=int(B[i])*t
t*=2
sayac=0
while(A!=1):
if((A%2)==1):
A+=1
else:
A/=2
sayac+=1
print(sayac)
``` | 0 |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,612,337,632 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 154 | 0 | l=[]
n=int(input())
a,b=map(int,input().split())
q=0
c=0
for __ in range(n-1):
x,y=map(int,input().split())
if a>=x and b<=y:
q+=1
a,b=x,y
c= __+1
elif a>x or b<y:
c=0
q= -1
print(-1 if c==0 and q<0 else c+1) | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
l=[]
n=int(input())
a,b=map(int,input().split())
q=0
c=0
for __ in range(n-1):
x,y=map(int,input().split())
if a>=x and b<=y:
q+=1
a,b=x,y
c= __+1
elif a>x or b<y:
c=0
q= -1
print(-1 if c==0 and q<0 else c+1)
``` | 0 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,688,978,875 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | if __name__ == "__main__":
n = int(input())
if(n%2!=0): print("NO")
else: print("YES")
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
if __name__ == "__main__":
n = int(input())
if(n%2!=0): print("NO")
else: print("YES")
``` | 0 |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,649,357,259 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 154 | 0 | n,l,r=map(int,input().split())
print(min(n-l,r+1)) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
n,l,r=map(int,input().split())
print(min(n-l,r+1))
``` | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,694,536,954 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n= int(input())
xC=[]
yC=[]
zC=[]
for i in range(n):
x,y,z = map(int,input().split())
xC.append(x)
yC.append(y)
zC.append(z)
if sum(xC)==0 and sum(yC)==0 and sum(zC)==0:
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n= int(input())
xC=[]
yC=[]
zC=[]
for i in range(n):
x,y,z = map(int,input().split())
xC.append(x)
yC.append(y)
zC.append(z)
if sum(xC)==0 and sum(yC)==0 and sum(zC)==0:
print('YES')
else:
print('NO')
``` | 3.977 |
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac... | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n... | 1,641,739,633 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 124 | 0 | def sup(a):
t=x
q1=0
q2=0
q3=0
q4=0
for j in t:
if j[0]==a[0]:
if j[1]>a[1]:
q1+=1
if j[1]<a[1]:
q2+=1
if j[1]==a[1]:
if j[0]>a[0]:
q3+=1
if j[0]<a[0]:
... | Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give... | ```python
def sup(a):
t=x
q1=0
q2=0
q3=0
q4=0
for j in t:
if j[0]==a[0]:
if j[1]>a[1]:
q1+=1
if j[1]<a[1]:
q2+=1
if j[1]==a[1]:
if j[0]>a[0]:
q3+=1
if j[0]<a[0]:
... | 3 | |
999 | E | Reachability from the Capital | PROGRAMMING | 2,000 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way. | The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_... | Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0. | [
"9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n",
"5 4 5\n1 2\n2 3\n3 4\n4 1\n"
] | [
"3\n",
"1\n"
] | The first example is illustrated by the following:
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following:
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the ci... | 0 | [
{
"input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1",
"output": "3"
},
{
"input": "5 4 5\n1 2\n2 3\n3 4\n4 1",
"output": "1"
},
{
"input": "5000 0 2956",
"output": "4999"
},
{
"input": "2 0 2",
"output": "1"
},
{
"input": "2 1 1\n1 2",
"output": "0"... | 1,665,323,137 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 30 | 77 | 5,222,400 | import sys
from math import sqrt,gcd,factorial,ceil,floor,pi,isqrt
from collections import deque,Counter,OrderedDict
from heapq import heapify,heappush,heappop
#sys.setrecursionlimit(10**6)
input =lambda: sys.stdin.readline()
I =lambda :int(input())
S =lambda :input().strip()
M =lambda :map(int,inpu... | Title: Reachability from the Capital
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities r... | ```python
import sys
from math import sqrt,gcd,factorial,ceil,floor,pi,isqrt
from collections import deque,Counter,OrderedDict
from heapq import heapify,heappush,heappop
#sys.setrecursionlimit(10**6)
input =lambda: sys.stdin.readline()
I =lambda :int(input())
S =lambda :input().strip()
M =lambda :ma... | 0 | |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,539,283,566 | 366 | Python 3 | OK | TESTS | 79 | 171 | 8,806,400 | n = int(input())
nums = list(map(int, input().split()))
setofnums = set()
for i in nums:
setofnums.add(i)
if len(setofnums)>3:
print("NO")
elif len(setofnums)==3:
temp = list(setofnums)
temp.sort()
if temp[2]-temp[1] == temp[1]-temp[0]:
print("YES")
else:
print("NO")
else:
... | Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a... | ```python
n = int(input())
nums = list(map(int, input().split()))
setofnums = set()
for i in nums:
setofnums.add(i)
if len(setofnums)>3:
print("NO")
elif len(setofnums)==3:
temp = list(setofnums)
temp.sort()
if temp[2]-temp[1] == temp[1]-temp[0]:
print("YES")
else:
print("NO")
... | 3 | |
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,673,790,447 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
min_tuition = 999999999
max_quality = -999999999
count = 0
for i in range(n):
a, b = list(map(int, input().split()))
min_tuition = min(min_tuition, a)
max_quality = max(max_quality, b)
if a > min_tuition and b < max_quality:
print("Happy Rabih")
count += 1
... | 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())
min_tuition = 999999999
max_quality = -999999999
count = 0
for i in range(n):
a, b = list(map(int, input().split()))
min_tuition = min(min_tuition, a)
max_quality = max(max_quality, b)
if a > min_tuition and b < max_quality:
print("Happy Rabih")
count... | 0 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,599,991,024 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 265 | 17,510,400 | n = int(input())
socks = [int(x) for x in input().split(' ')]
table = set()
m = 0
for sock in socks:
if sock in table:
table.remove(sock)
else:
table.add(sock)
m = max(m, len(table))
print(m) | 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())
socks = [int(x) for x in input().split(' ')]
table = set()
m = 0
for sock in socks:
if sock in table:
table.remove(sock)
else:
table.add(sock)
m = max(m, len(table))
print(m)
``` | 3 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,632,757,264 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 30 | 248 | 22,835,200 | a = input()
b = input()
from collections import Counter
if Counter(a) == Counter(b):
print('YES')
else:
print('NO') | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
a = input()
b = input()
from collections import Counter
if Counter(a) == Counter(b):
print('YES')
else:
print('NO')
``` | 0 | |
612 | A | The Text Splitting | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the st... | The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The... | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n"
] | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n"
] | none | 0 | [
{
"input": "5 2 3\nHello",
"output": "2\nHe\nllo"
},
{
"input": "10 9 5\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "6 4 5\nPrivet",
"output": "-1"
},
{
"input": "8 1 1\nabacabac",
"output": "8\na\nb\na\nc\na\nb\na\nc"
},
{
"input": "1 1 1\n1",
"ou... | 1,537,980,123 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 124 | 0 | n,p,q=map(int,input().split())
u=p+q
s=input()
if(n%p==0):
print(int(n/p))
for x in range(int(n/p)):
print(s[x*p:(x+1)*p])
elif(n%q==0):
print(int(n/q))
for x in range(int(n/q)):
print(s[x*q:(x+1)*q])
elif(n%u==0):
print(int(n/u)*2)
for x in range(int(n/u)):
print(s[x*u:x*u+p])
print(s[x*u+... | Title: The Text Splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "H... | ```python
n,p,q=map(int,input().split())
u=p+q
s=input()
if(n%p==0):
print(int(n/p))
for x in range(int(n/p)):
print(s[x*p:(x+1)*p])
elif(n%q==0):
print(int(n/q))
for x in range(int(n/q)):
print(s[x*q:(x+1)*q])
elif(n%u==0):
print(int(n/u)*2)
for x in range(int(n/u)):
print(s[x*u:x*u+p])
pr... | 0 | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,474,318,501 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 0 | n = int(input())
h = []
v = []
for i in range(n*n):
horizontal, vertical = map(int, input().split())
if(horizontal not in h) and (vertical not in v):
h.append(horizontal)
v.append(vertical)
print(i+1, end = ' ') | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
n = int(input())
h = []
v = []
for i in range(n*n):
horizontal, vertical = map(int, input().split())
if(horizontal not in h) and (vertical not in v):
h.append(horizontal)
v.append(vertical)
print(i+1, end = ' ')
``` | 3 | |
216 | A | Tiling with Hexagons | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.
The hall also turned out hexagonal in its shape. The King walked along the perimeter of ... | The first line contains three integers: *a*, *b* and *c* (2<=≤<=*a*,<=*b*,<=*c*<=≤<=1000). | Print a single number — the total number of tiles on the hall floor. | [
"2 3 4\n"
] | [
"18"
] | none | 500 | [
{
"input": "2 3 4",
"output": "18"
},
{
"input": "2 2 2",
"output": "7"
},
{
"input": "7 8 13",
"output": "224"
},
{
"input": "14 7 75",
"output": "1578"
},
{
"input": "201 108 304",
"output": "115032"
},
{
"input": "999 998 996",
"output": "298302... | 1,671,263,173 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a,b,c=map(int,input().split())
s=0
while True:
# if a+b+c==3:s+=1
s+=2*(a+b+c-3)
a1=a
b1=b
c1=c
a=max(1,a-1-(b==1 or c==1))
b=max(1,b-1-(a1==1 or c==1))
c=max(1,c-1-(a1==1 or b1==1))
# print(s,a,b,c)
if a+b==2 or b+c==2 or a+c==2:
break
print(s) | Title: Tiling with Hexagons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with ... | ```python
a,b,c=map(int,input().split())
s=0
while True:
# if a+b+c==3:s+=1
s+=2*(a+b+c-3)
a1=a
b1=b
c1=c
a=max(1,a-1-(b==1 or c==1))
b=max(1,b-1-(a1==1 or c==1))
c=max(1,c-1-(a1==1 or b1==1))
# print(s,a,b,c)
if a+b==2 or b+c==2 or a+c==2:
break
print(s)
``... | 0 | |
39 | J | Spelling Check | PROGRAMMING | 1,500 | [
"hashing",
"implementation",
"strings"
] | J. Spelling Check | 2 | 256 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d... | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible... | [
"abdrakadabra\nabrakadabra\n",
"aa\na\n",
"competition\ncodeforces\n"
] | [
"1\n3\n",
"2\n1 2\n",
"0\n"
] | none | 0 | [
{
"input": "abdrakadabra\nabrakadabra",
"output": "1\n3 "
},
{
"input": "aa\na",
"output": "2\n1 2 "
},
{
"input": "competition\ncodeforces",
"output": "0"
},
{
"input": "ab\na",
"output": "1\n2 "
},
{
"input": "bb\nb",
"output": "2\n1 2 "
},
{
"input"... | 1,680,212,963 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | """
https://vjudge.net/problem/CodeForces-39J
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds
extra letters to the words. Of course, the spell-checking system underlines the words for him
and he has to click every word and choose the right variant. Petya got fed up w... | Title: Spelling Check
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and ... | ```python
"""
https://vjudge.net/problem/CodeForces-39J
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds
extra letters to the words. Of course, the spell-checking system underlines the words for him
and he has to click every word and choose the right variant. Petya go... | 0 |
914 | E | Palindromes in a Tree | PROGRAMMING | 2,400 | [
"bitmasks",
"data structures",
"divide and conquer",
"trees"
] | null | null | You are given a tree (a connected acyclic undirected graph) of *n* vertices. Vertices are numbered from 1 to *n* and each vertex is assigned a character from a to t.
A path in the tree is said to be palindromic if at least one permutation of the labels in the path is a palindrome.
For each vertex, output the number o... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of vertices in the tree.
The next *n*<=-<=1 lines each contain two integers *u* and *v* (1<=<=≤<=<=*u*,<=*v*<=<=≤<=<=*n*,<=*u*<=≠<=*v*) denoting an edge connecting vertex *u* and vertex *v*. It is guaranteed that the given graph is a tree.
The... | Print *n* integers in a single line, the *i*-th of which is the number of palindromic paths passing through vertex *i* in the tree. | [
"5\n1 2\n2 3\n3 4\n3 5\nabcbb\n",
"7\n6 2\n4 3\n3 7\n5 2\n7 2\n1 4\nafefdfs\n"
] | [
"1 3 4 3 3 \n",
"1 4 1 1 2 4 2 \n"
] | In the first sample case, the following paths are palindromic:
2 - 3 - 4
2 - 3 - 5
4 - 3 - 5
Additionally, all paths containing only one vertex are palindromic. Listed below are a few paths in the first sample that are not palindromic:
1 - 2 - 3
1 - 2 - 3 - 4
1 - 2 - 3 - 5 | 2,500 | [
{
"input": "5\n1 2\n2 3\n3 4\n3 5\nabcbb",
"output": "1 3 4 3 3 "
},
{
"input": "7\n6 2\n4 3\n3 7\n5 2\n7 2\n1 4\nafefdfs",
"output": "1 4 1 1 2 4 2 "
},
{
"input": "5\n3 1\n3 5\n5 4\n5 2\nticdm",
"output": "1 1 1 1 1 "
},
{
"input": "10\n10 8\n3 2\n9 7\n1 5\n5 3\n7 6\n8 4\n1... | 1,689,640,273 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689640272.903338")# 1689640272.9033587 | Title: Palindromes in a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tree (a connected acyclic undirected graph) of *n* vertices. Vertices are numbered from 1 to *n* and each vertex is assigned a character from a to t.
A path in the tree is said to be palindromic i... | ```python
print("_RANDOM_GUESS_1689640272.903338")# 1689640272.9033587
``` | 0 | |
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989... | 1,574,240,869 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | n = int(input())
l = list(map(int, input().split()))
result = True
for i in range(n-2):
li, ri = i, i+1
for j in range(i+2, n-1):
lj, rj = j, j+1
if l[li] < l[lj] < l[ri] or l[lj] < l[ri] < l[rj]:
result = False
break
if not result:
break
if result... | Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher g... | ```python
n = int(input())
l = list(map(int, input().split()))
result = True
for i in range(n-2):
li, ri = i, i+1
for j in range(i+2, n-1):
lj, rj = j, j+1
if l[li] < l[lj] < l[ri] or l[lj] < l[ri] < l[rj]:
result = False
break
if not result:
break
... | 0 | |
526 | A | King of Thieves | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
An interesting feature of the game is that you can design your own levels that wil... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of segments on the level.
Next line contains the scheme of the level represented as a string of *n* characters '*' and '.'. | If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes). | [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n"
] | [
"yes",
"no"
] | In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14. | 500 | [
{
"input": "16\n.**.*..*.***.**.",
"output": "yes"
},
{
"input": "11\n.*.*...*.*.",
"output": "no"
},
{
"input": "53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.",
"output": "yes"
},
{
"input": "71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.*... | 1,428,180,575 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 93 | 0 | from sys import stdin, stdout
n = int(stdin.readline())
lev = stdin.readline()
res = any(lev[start::step][:5] == '*****' for start in range(0, n) for step in range(1, int(n/4)))
stdout.write(('no','yes')[res]) | Title: King of Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obsta... | ```python
from sys import stdin, stdout
n = int(stdin.readline())
lev = stdin.readline()
res = any(lev[start::step][:5] == '*****' for start in range(0, n) for step in range(1, int(n/4)))
stdout.write(('no','yes')[res])
``` | 0 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,609,855,711 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 186 | 0 | s = input()
t = input()
i = 0
j = 0
while i<len(t):
while i<len(t) and t[i]!=s[j]:
i+=1
if i<len(t):
j+=1
i+=1
print(j+1)
| Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s = input()
t = input()
i = 0
j = 0
while i<len(t):
while i<len(t) and t[i]!=s[j]:
i+=1
if i<len(t):
j+=1
i+=1
print(j+1)
``` | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,622,219,756 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
arr = list(map(int, input().split()))
e = 0
o = 0
for i in range(1,n):
if arr[i]%2==0:
e +=1
x = i
else:
o +=1
y = i
if e == 1:
print(x+1)
elif o==1:
print(y+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
arr = list(map(int, input().split()))
e = 0
o = 0
for i in range(1,n):
if arr[i]%2==0:
e +=1
x = i
else:
o +=1
y = i
if e == 1:
print(x+1)
elif o==1:
print(y+1)
``` | 0 |
746 | D | Green and Black Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order ... | The first line contains four integers *n*, *k*, *a* and *b* (1<=≤<=*k*<=≤<=*n*<=≤<=105, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that *a*<=+<=*b*<==<=*n*. | If it is impossible to drink *n* cups of tea, print "NO" (without quotes).
Otherwise, print the string of the length *n*, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be ... | [
"5 1 3 2\n",
"7 2 2 5\n",
"4 3 4 0\n"
] | [
"GBGBG\n",
"BBGBGBB",
"NO\n"
] | none | 2,000 | [
{
"input": "5 1 3 2",
"output": "GBGBG"
},
{
"input": "7 2 2 5",
"output": "BBGBBGB"
},
{
"input": "4 3 4 0",
"output": "NO"
},
{
"input": "2 2 0 2",
"output": "BB"
},
{
"input": "3 2 0 3",
"output": "NO"
},
{
"input": "1 1 0 1",
"output": "B"
},... | 1,673,971,270 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n, k, a, b = map(int, input().split())
a_min = min(a, b)
b_max = max(a, b)
tea_min, tea_max = 'G', 'B'
if a_min != a:
tea_min, tea_max = tea_max, tea_min
result = ""
while a_min + b_max > 0:
cur = 0
while cur < k:
result += tea_max
b_max -= 1
cur += 1
if a_min > 0:
resu... | Title: Green and Black Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like ... | ```python
n, k, a, b = map(int, input().split())
a_min = min(a, b)
b_max = max(a, b)
tea_min, tea_max = 'G', 'B'
if a_min != a:
tea_min, tea_max = tea_max, tea_min
result = ""
while a_min + b_max > 0:
cur = 0
while cur < k:
result += tea_max
b_max -= 1
cur += 1
if a_min > 0:
... | 0 | |
612 | B | HDD is Outdated Technology | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read s... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments.
The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector. | Print the only integer — the number of time units needed to read the file. | [
"3\n3 1 2\n",
"5\n1 3 5 4 2\n"
] | [
"3\n",
"10\n"
] | In the second example the head moves in the following way:
- 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time un... | 0 | [
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "5\n1 3 5 4 2",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "40"
... | 1,550,910,446 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 763 | 19,353,600 | n, s = int(input()), 0
ar = [(int(value), index + 1) for index, value in enumerate(input().split())]
ar.sort()
for x in range(n - 1):
s += abs(ar[x + 1][1] - ar[x][1])
print(s)
| Title: HDD is Outdated Technology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the ... | ```python
n, s = int(input()), 0
ar = [(int(value), index + 1) for index, value in enumerate(input().split())]
ar.sort()
for x in range(n - 1):
s += abs(ar[x + 1][1] - ar[x][1])
print(s)
``` | 3 | |
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a w... | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "... | 1,612,038,397 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 204,800 | pol_and_ene = map(int, input().split())
temporary_list = list(pol_and_ene)
pol = temporary_list[0]
ene = temporary_list[1]
word1 = []
word2 = []
for i in range(1, pol+1):
string = input()
word1.append(string)
for j in range(1, ene+1):
string2 = input()
word2.append(string2)
compare = list(set(... | Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You... | ```python
pol_and_ene = map(int, input().split())
temporary_list = list(pol_and_ene)
pol = temporary_list[0]
ene = temporary_list[1]
word1 = []
word2 = []
for i in range(1, pol+1):
string = input()
word1.append(string)
for j in range(1, ene+1):
string2 = input()
word2.append(string2)
compare =... | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,648,571,659 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s = input()
t = input()
count=0
for i in range(len(s)) :
if s[i]=t[-i] :
count +=1
if count==len(s) :
print("YES")
else :
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s = input()
t = input()
count=0
for i in range(len(s)) :
if s[i]=t[-i] :
count +=1
if count==len(s) :
print("YES")
else :
print("NO")
``` | -1 |
665 | B | Shopping | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains *k* items. *n* customers have already used the above service. Each user paid for *m* items. Let *a**ij* denote the *j*-th item in the *i*-th person's orde... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*k*<=≤<=100,<=1<=≤<=*m*<=≤<=*k*) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains *k* distinct integers *p**l* (1<=≤<=*p**l*<=≤<=*k*) denoting the initial positions ... | Print the only integer *t* — the total time needed for Ayush to process all the orders. | [
"2 2 5\n3 4 1 2 5\n1 5\n3 1\n"
] | [
"14\n"
] | Customer 1 wants the items 1 and 5.
*pos*(1) = 3, so the new positions are: [1, 3, 4, 2, 5].
*pos*(5) = 5, so the new positions are: [5, 1, 3, 4, 2].
Time taken for the first customer is 3 + 5 = 8.
Customer 2 wants the items 3 and 1.
*pos*(3) = 3, so the new positions are: [3, 5, 1, 4, 2].
*pos*(1) = 3, so the ne... | 0 | [
{
"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1",
"output": "14"
},
{
"input": "4 4 4\n1 2 3 4\n3 4 2 1\n4 3 2 1\n4 1 2 3\n4 1 2 3",
"output": "59"
},
{
"input": "1 1 1\n1\n1",
"output": "1"
},
{
"input": "10 1 100\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 8... | 1,574,287,466 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 1 | 233 | 2,150,400 | n, m, k = map(int, input().split())
b = [0] * (k + 1)
a = list(map(int, input().split()))
for i in range(k):
b[a[i]] = i + 1
s = 0
for i in range(n):
c = list(map(int, input().split()))
for j in range(m):
s += b[c[j]]
for l in range(b[c[j]]):
b[a[l]] += 1
b[c[... | Title: Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains *k* items. *n* customers have already used the above service... | ```python
n, m, k = map(int, input().split())
b = [0] * (k + 1)
a = list(map(int, input().split()))
for i in range(k):
b[a[i]] = i + 1
s = 0
for i in range(n):
c = list(map(int, input().split()))
for j in range(m):
s += b[c[j]]
for l in range(b[c[j]]):
b[a[l]] += 1
... | -1 | |
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,692,010,392 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 280 | 7,884,800 | # Wadea #
arr = []
for i in range(int(input())):
n = input()
arr.append(n)
c = 0
for i in range(1,len(arr)):
if arr[i] == arr[i-1]:
pass
else:
c += 1
print(c+1)
| 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
# Wadea #
arr = []
for i in range(int(input())):
n = input()
arr.append(n)
c = 0
for i in range(1,len(arr)):
if arr[i] == arr[i-1]:
pass
else:
c += 1
print(c+1)
``` | 3 | |
929 | A | Прокат велосипедов | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат и... | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=.... | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы доб... | 500 | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},... | 1,520,056,561 | 51,661 | Python 3 | OK | TESTS | 52 | 77 | 5,632,000 | n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
# print('n:', n)
# print('k:', k)
# print('x:', x)
distance = x[0]
count = 1
for i in range(n-1):
# print('x[i]:', x[i])
# print('distance:', distance)
if x[i] + k < x[i+1]:
count = -1
break
if distance + k >= x[i]... | Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся... | ```python
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
# print('n:', n)
# print('k:', k)
# print('x:', x)
distance = x[0]
count = 1
for i in range(n-1):
# print('x[i]:', x[i])
# print('distance:', distance)
if x[i] + k < x[i+1]:
count = -1
break
if distance +... | 3 | |
762 | D | Maximum path | PROGRAMMING | 2,300 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given a rectangular table 3<=×<=*n*. Each cell contains an integer. You can move from one cell to another if they share a side.
Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cells twice, and the sum of numbers written in the cells of this path is ma... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns in the table.
Next three lines contain *n* integers each — the description of the table. The *j*-th number in the *i*-th line corresponds to the cell *a**ij* (<=-<=109<=≤<=*a**ij*<=≤<=109) of the table. | Output the maximum sum of numbers on a path from the upper left cell to the bottom right cell of the table, that doesn't visit any of the cells twice. | [
"3\n1 1 1\n1 -1 1\n1 1 1\n",
"5\n10 10 10 -1 -1\n-1 10 10 10 10\n-1 10 10 10 10\n"
] | [
"7\n",
"110\n"
] | The path for the first example:
The path for the second example: | 0 | [
{
"input": "3\n1 1 1\n1 -1 1\n1 1 1",
"output": "7"
},
{
"input": "5\n10 10 10 -1 -1\n-1 10 10 10 10\n-1 10 10 10 10",
"output": "110"
},
{
"input": "15\n-87 -91 31 63 91 35 -14 51 20 20 -20 -94 -59 77 76\n11 81 22 -29 91 -26 -10 -12 46 10 100 88 14 64 41\n26 -31 99 -39 -30 30 28 74 -7 2... | 1,627,995,671 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 1,000 | 24,371,200 | import sys
input = sys.stdin.readline
def solve():
M = (
((0,), (0,1), (0,1,2), (0,1,2)),
((0,1), (1,), (1,2), None),
((0,1,2), (1,2), (2,), (0,1,2)),
((0,1,2), None, (0,1,2), (0,1,2)))
INF = int(9e18-1e9)
n = int(input())
a = [list(map(int, input().split())) for i in range(3)]
dp = [[None]*(n+1... | Title: Maximum path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular table 3<=×<=*n*. Each cell contains an integer. You can move from one cell to another if they share a side.
Find such path from the upper left cell to the bottom right cell of the table that do... | ```python
import sys
input = sys.stdin.readline
def solve():
M = (
((0,), (0,1), (0,1,2), (0,1,2)),
((0,1), (1,), (1,2), None),
((0,1,2), (1,2), (2,), (0,1,2)),
((0,1,2), None, (0,1,2), (0,1,2)))
INF = int(9e18-1e9)
n = int(input())
a = [list(map(int, input().split())) for i in range(3)]
dp = [[... | 0 | |
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,439,564,628 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 |
row = input()
row = int(row)
n = row
matrix = [list(map(int, input().split() )) for r in range(row)]
def dive_G(divisor):
def dive(divided):
num = 0
while divided%divisor == 0:
num += 1
divided /= divisor
return num
def dp(num, matrix):
dive = dive_G(num)
amount = [[dive(c) for... | 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
row = input()
row = int(row)
n = row
matrix = [list(map(int, input().split() )) for r in range(row)]
def dive_G(divisor):
def dive(divided):
num = 0
while divided%divisor == 0:
num += 1
divided /= divisor
return num
def dp(num, matrix):
dive = dive_G(num)
amount = [[d... | -1 |
433 | A | Kitahara Haruki's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. | In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). | [
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | 500 | [
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"o... | 1,679,332,927 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 24 | 46 | 0 |
n = int(input())
a = list(map(int,input().split()))
hundreds = 0
twos = 0
for i in a:
if i == 100:
hundreds += 1
else:
twos += 1
if twos %2 == 0:
if hundreds %2 == 0:
print("YES")
else:
print("NO")
else:
if hundreds % 2 == 0 and hundreds-(2*(two... | Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't w... | ```python
n = int(input())
a = list(map(int,input().split()))
hundreds = 0
twos = 0
for i in a:
if i == 100:
hundreds += 1
else:
twos += 1
if twos %2 == 0:
if hundreds %2 == 0:
print("YES")
else:
print("NO")
else:
if hundreds % 2 == 0 and hundre... | 0 | |
598 | D | Igor In the Museum | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i... | First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that ... | Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | 0 | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\... | 1,682,725,542 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 5,222,400 | import sys
sys.setrecursionlimit(10**6)
linhas, colunas, numPosicoes = map(int, input().split())
museu = [input() for _ in range(linhas)]
posicao = [0] * (linhas * colunas + 5)
visitado = [[0] * (colunas + 1) for _ in range(linhas + 1)]
def buscaEmProfundidade(a, b, id):
global respostas
if a... | Title: Igor In the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.'... | ```python
import sys
sys.setrecursionlimit(10**6)
linhas, colunas, numPosicoes = map(int, input().split())
museu = [input() for _ in range(linhas)]
posicao = [0] * (linhas * colunas + 5)
visitado = [[0] * (colunas + 1) for _ in range(linhas + 1)]
def buscaEmProfundidade(a, b, id):
global respostas... | 0 | |
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with... | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per... | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n99... | 1,616,062,738 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 307,200 | n=int(input())
lst=[]
for x in range(0,4):
arr=list(input())
a,b,c,d,e,f,g,h,i,j=arr.count('0'),arr.count('1'),arr.count('2'),arr.count('3'),arr.count('4'),arr.count('5'),arr.count('6'),arr.count('7'),arr.count('8'),arr.count('9')
if a>n or b>n or c>n or d>n or e>n or f>n or g>n or h>n or i>n or j>n:
print("... | Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preff... | ```python
n=int(input())
lst=[]
for x in range(0,4):
arr=list(input())
a,b,c,d,e,f,g,h,i,j=arr.count('0'),arr.count('1'),arr.count('2'),arr.count('3'),arr.count('4'),arr.count('5'),arr.count('6'),arr.count('7'),arr.count('8'),arr.count('9')
if a>n or b>n or c>n or d>n or e>n or f>n or g>n or h>n or i>n or j>n:
... | 0 | |
830 | B | Cards Sorting | PROGRAMMING | 1,600 | [
"data structures",
"implementation",
"sortings"
] | null | null | Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cards in the deck.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), where *a**i* is the number written on the *i*-th from top card in the deck. | Print the total number of times Vasily takes the top card from the deck. | [
"4\n6 3 1 2\n",
"1\n1000\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"7\n",
"1\n",
"7\n"
] | In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards ... | 1,000 | [
{
"input": "4\n6 3 1 2",
"output": "7"
},
{
"input": "1\n1000",
"output": "1"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "7"
},
{
"input": "64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 416 944 162 939 164 1047 359 114 499 99 713 300 268 316 256... | 1,500,958,683 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 4,608,000 | n = int(input())
s = list(map(int,input().split(' ')))
a = sorted(range(len(s)), key=lambda k: s[k])
c = 0
x = a[0] + 1
i = n-1
while i > 0:
if a[i] < a[i-1]:
k = a[i] - a[i-1] + n
else:
k = a[i] - a[i-1]
c += k
x -= c//n
i -= 1
print(c+x) | Title: Cards Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them.
Vasily decid... | ```python
n = int(input())
s = list(map(int,input().split(' ')))
a = sorted(range(len(s)), key=lambda k: s[k])
c = 0
x = a[0] + 1
i = n-1
while i > 0:
if a[i] < a[i-1]:
k = a[i] - a[i-1] + n
else:
k = a[i] - a[i-1]
c += k
x -= c//n
i -= 1
print(c+x)
``` | 0 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,621,912,245 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 154 | 0 | lst1 = list(map(int,input().split()))
lst2 = list(map(int,input().split()))
lst3 = list(map(int,input().split()))
x = lst1[0]
y = lst2[1]
z = lst3[2]
sumlst1 = sum(lst1)
sumlst2 = sum(lst2)
sumlst3 = sum(lst3)
yandz = sumlst1
x = ((sumlst2 + sumlst3 + yandz) - 2*sumlst1)//2
y = sumlst1 + x - sumlst2
z = sum... | Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
lst1 = list(map(int,input().split()))
lst2 = list(map(int,input().split()))
lst3 = list(map(int,input().split()))
x = lst1[0]
y = lst2[1]
z = lst3[2]
sumlst1 = sum(lst1)
sumlst2 = sum(lst2)
sumlst3 = sum(lst3)
yandz = sumlst1
x = ((sumlst2 + sumlst3 + yandz) - 2*sumlst1)//2
y = sumlst1 + x - sumlst... | 3 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,584,265,489 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | n=int(input())
s=input()
k=len(s)
t=int(0)
for i in s:
if i=='1': t+=1
if t==k:print(k)
else: print(t+1)
| Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n=int(input())
s=input()
k=len(s)
t=int(0)
for i in s:
if i=='1': t+=1
if t==k:print(k)
else: print(t+1)
``` | 0 | |
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1.... | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
}... | 1,608,671,509 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 404 | 9,932,800 | from sys import stdin as sin
def gint():return int(sin.readline())
def gmap():return map(int,sin.readline().split())
def glist():return list(map(int,sin.readline().split()))
def gstr():return sin.readline()
n,k=gmap()
l=glist()
if l.count(l[0])==n:print(0)
elif l[k-1:len(l)].count(l[k-1])==n-k+1:
for i in range(k-... | Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the cur... | ```python
from sys import stdin as sin
def gint():return int(sin.readline())
def gmap():return map(int,sin.readline().split())
def glist():return list(map(int,sin.readline().split()))
def gstr():return sin.readline()
n,k=gmap()
l=glist()
if l.count(l[0])==n:print(0)
elif l[k-1:len(l)].count(l[k-1])==n-k+1:
for i i... | 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.