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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,615,992,863 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 154 | 0 | s = str(input())
print(s.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = str(input())
print(s.lower())
``` | 0 |
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
... | 1,616,080,425 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 0 | n=int(input())
s=input()
li=[]
x=0
for i in s:
if i=='B':x+=1
elif i=='W'and x!=0:
li.append(x)
x=0
if(s[len(s)-1]=='B'):li.append(x)
print(len(li))
for i in li:
print(i,end=" ")
| Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the... | ```python
n=int(input())
s=input()
li=[]
x=0
for i in s:
if i=='B':x+=1
elif i=='W'and x!=0:
li.append(x)
x=0
if(s[len(s)-1]=='B'):li.append(x)
print(len(li))
for i in li:
print(i,end=" ")
``` | 3 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,684,949,668 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 327 | 62,566,400 | def solve():
n = int(input().strip())
a = list(map(int, input().strip().split()))
total_sum = sum(a)
if total_sum % 3 != 0:
print(0)
else:
required_sum = total_sum // 3
current_sum = 0
count = [0]*n
for i in range(n-1, -1, -1):
current_s... | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
def solve():
n = int(input().strip())
a = list(map(int, input().strip().split()))
total_sum = sum(a)
if total_sum % 3 != 0:
print(0)
else:
required_sum = total_sum // 3
current_sum = 0
count = [0]*n
for i in range(n-1, -1, -1):
... | 3 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,664,901,832 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 8 | 216 | 2,048,000 | n,m=map(int,input().split())
l,k=[],[]
s=0
for _ in range(m):
x,y=map(int,input().split())
l.append(x)
k.append(y)
while n>0:
if n>l[k.index(max(k))]:
n-=l[k.index(max(k))]
s+=l[k.index(max(k))]*max(k)
k.remove(max(k))
l.remove(l[k.index(max(k))])
else:
... | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
n,m=map(int,input().split())
l,k=[],[]
s=0
for _ in range(m):
x,y=map(int,input().split())
l.append(x)
k.append(y)
while n>0:
if n>l[k.index(max(k))]:
n-=l[k.index(max(k))]
s+=l[k.index(max(k))]*max(k)
k.remove(max(k))
l.remove(l[k.index(max(k))])
... | -1 |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,678,366,898 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n=int(input())
c=0
a=list(map(int,input().split()))
for i in range(1,n):
if a[i]>a[i-1]:c+=1
print(c) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
c=0
a=list(map(int,input().split()))
for i in range(1,n):
if a[i]>a[i-1]:c+=1
print(c)
``` | 0 | |
976 | B | Lara Croft and the New Game | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D e... | The only line contains three integers *n*, *m* and *k* (2<=≤<=*n*,<=*m*<=≤<=109, *n* is always even, 0<=≤<=*k*<=<<=*n*·*m*). Note that *k* doesn't fit into 32-bit integer type! | Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves *k* times. | [
"4 3 0\n",
"4 3 11\n",
"4 3 7\n"
] | [
"1 1\n",
"1 2\n",
"3 2\n"
] | Here is her path on matrix 4 by 3: | 0 | [
{
"input": "4 3 0",
"output": "1 1"
},
{
"input": "4 3 11",
"output": "1 2"
},
{
"input": "4 3 7",
"output": "3 2"
},
{
"input": "1000000000 2 1999999999",
"output": "1 2"
},
{
"input": "1000000000 1000000000 999999999999999999",
"output": "1 2"
},
{
"... | 1,525,237,556 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 108 | 7,065,600 | n, m, k = map(int, input().split())
now = [1,1]
if k <= n-1:
now[0] += k
else:
now = [n, 2]
k -= n
loop = k//(2*(m-1))
now = [n-2*loop, 2]
k %= (2*(m-1))
if k <= m - 2:
now[1] += k
elif k <= m -1:
now[0] -= 1
now[1] = m
else:
now[... | Title: Lara Croft and the New Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil... | ```python
n, m, k = map(int, input().split())
now = [1,1]
if k <= n-1:
now[0] += k
else:
now = [n, 2]
k -= n
loop = k//(2*(m-1))
now = [n-2*loop, 2]
k %= (2*(m-1))
if k <= m - 2:
now[1] += k
elif k <= m -1:
now[0] -= 1
now[1] = m
else:
... | 3 | |
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s... | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"outp... | 1,566,967,944 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 108 | 307,200 | n,m = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
if (arr[m-1]==n):
print ("NO")
else:
flag = False
for i in range(0,m-2):
if(arr[i+2]-arr[i]==2):
print ("NO")
flag = True
break
if not flag:
print ("YES")
| Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o... | ```python
n,m = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
if (arr[m-1]==n):
print ("NO")
else:
flag = False
for i in range(0,m-2):
if(arr[i+2]-arr[i]==2):
print ("NO")
flag = True
break
if not flag:
print ("YES")
``` | -1 | |
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,663,398,240 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=int(input())
num=input().split()
x=[]
for i in range(n-1):
x.append(str(abs(int(num[i]))-int(num[i+1])))
y=max(x,key=x.count)
if abs(int(num[0])-int(num[1]))!=int(y):
print(1)
else:
for i in range(n-1):
if abs(int(num[i])-int(num[i+1]))!=int(y):
print(i+1)
break | 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())
num=input().split()
x=[]
for i in range(n-1):
x.append(str(abs(int(num[i]))-int(num[i+1])))
y=max(x,key=x.count)
if abs(int(num[0])-int(num[1]))!=int(y):
print(1)
else:
for i in range(n-1):
if abs(int(num[i])-int(num[i+1]))!=int(y):
print(i+1)
... | 0 |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,683,106,840 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | n,k=map(int,input().split())
t,p=0,0
for i in range(1,n+1):
t+=5*i
if t>240-k:
p=i-1
break
else:
p=n
print(p) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
n,k=map(int,input().split())
t,p=0,0
for i in range(1,n+1):
t+=5*i
if t>240-k:
p=i-1
break
else:
p=n
print(p)
``` | 3 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,679,860,095 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n, k=map(int ,input().split())
l = []
for i in range(n):
l.append(i*5)
left, right = 0, 10
mid = 0
while left + 1 < right:
mid = (left + right) // 2
if l[mid] <= l[-1]:
left = mid
else:
right = mid
print(l[left])
# Sun Mar 26 2023 22:48:14 GMT+0300 (Moscow Standard Time)
| Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
n, k=map(int ,input().split())
l = []
for i in range(n):
l.append(i*5)
left, right = 0, 10
mid = 0
while left + 1 < right:
mid = (left + right) // 2
if l[mid] <= l[-1]:
left = mid
else:
right = mid
print(l[left])
# Sun Mar 26 2023 22:48:14 GMT+0300 (Moscow Standard Time)
`... | -1 | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,655,897,556 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n=int(input())
x=set()
for i in range(n):
k=int(input())
if(k<=n):
x.add(k)
print(n-len(x)) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n=int(input())
x=set()
for i in range(n):
k=int(input())
if(k<=n):
x.add(k)
print(n-len(x))
``` | -1 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,694,874,582 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 61 | 0 | s = [int(i) for i in input().split()]
m = min(s)
mn = max(s)
if mn == m:
print(m, 0)
else:
print(m, (mn - m) // 2) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
s = [int(i) for i in input().split()]
m = min(s)
mn = max(s)
if mn == m:
print(m, 0)
else:
print(m, (mn - m) // 2)
``` | 3 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,513,952,538 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 154 | 5,632,000 | n,m=[int(i) for i in input().split()]
price=[int(i)*(-1) for i in input().split()]
lst=[]
for i in price:
if i>0:
lst.append(i)
lst.sort(reverse=True)
s=0
for i in range(min(len(lst),m)):
s+=lst[i]
print(s)
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n,m=[int(i) for i in input().split()]
price=[int(i)*(-1) for i in input().split()]
lst=[]
for i in price:
if i>0:
lst.append(i)
lst.sort(reverse=True)
s=0
for i in range(min(len(lst),m)):
s+=lst[i]
print(s)
``` | 3.95101 |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,504,491,675 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 154 | 0 | s=input()
a,b=list(),list()
for i in range(0,len(s)-9,10):a.append(s[i:i+10])
for i in range(10):b.append(input())
for i in a:print(b.index(i),end='') | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
s=input()
a,b=list(),list()
for i in range(0,len(s)-9,10):a.append(s[i:i+10])
for i in range(10):b.append(input())
for i in a:print(b.index(i),end='')
``` | 3.9615 |
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the chi... | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space... | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
... | 1,620,418,647 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
sys.stdin = open("input. txt", "r")
sys.stdout = open("output.txt","w")
n = int(input())
a = str(input())
b=n//2
for i in range (b):
if a[i]=='L':
print((i+1),((i+1)+b))
if a[i]=='R':
print(((i+1+b),(i+1))
| Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t... | ```python
import sys
sys.stdin = open("input. txt", "r")
sys.stdout = open("output.txt","w")
n = int(input())
a = str(input())
b=n//2
for i in range (b):
if a[i]=='L':
print((i+1),((i+1)+b))
if a[i]=='R':
print(((i+1+b),(i+1))
``` | -1 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,692,092,317 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | n=int(input())
for i in range (n):
ch=input()
ch.lower()
x=len(ch)
if x>10:
ch=ch[0]+str(x-2)+ch[-1]
print(ch)
else:
print(ch) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n=int(input())
for i in range (n):
ch=input()
ch.lower()
x=len(ch)
if x>10:
ch=ch[0]+str(x-2)+ch[-1]
print(ch)
else:
print(ch)
``` | 3.969 |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,673,880,556 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n=int(input())
l=list(map(int,input().split()))
maxi=l[0]
mini=l[0]
c=0
for i in range(1,n):
if l[i]>maxi:
c+=1
maxi=l[i]
elif l[i]<mini:
c+=1
mini=l[i]
print(c)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
l=list(map(int,input().split()))
maxi=l[0]
mini=l[0]
c=0
for i in range(1,n):
if l[i]>maxi:
c+=1
maxi=l[i]
elif l[i]<mini:
c+=1
mini=l[i]
print(c)
``` | 3 | |
476 | D | Dreamoon and Sets | PROGRAMMING | 1,900 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Dreamoon likes to play with sets, integers and . is defined as the largest positive integer that divides both *a* and *b*.
Let *S* be a set of exactly four distinct integers greater than 0. Define *S* to be of rank *k* if and only if for all pairs of distinct elements *s**i*, *s**j* from *S*, .
Given *k* and *n*, Dr... | The single line of the input contains two space separated integers *n*, *k* (1<=≤<=*n*<=≤<=10<=000,<=1<=≤<=*k*<=≤<=100). | On the first line print a single integer — the minimal possible *m*.
On each of the next *n* lines print four space separated integers representing the *i*-th set.
Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal *m*, print any o... | [
"1 1\n",
"2 2\n"
] | [
"5\n1 2 3 5\n",
"22\n2 4 6 22\n14 18 10 16\n"
] | For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e2af04e5e60e1fe79a4d74bf22dfa575f0b0f7bb.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 2,000 | [
{
"input": "1 1",
"output": "5\n1 3 4 5"
},
{
"input": "2 2",
"output": "22\n2 6 8 10\n14 18 20 22"
},
{
"input": "7 7",
"output": "287\n7 21 28 35\n49 63 70 77\n91 105 112 119\n133 147 154 161\n175 189 196 203\n217 231 238 245\n259 273 280 287"
},
{
"input": "13 7",
"out... | 1,693,821,262 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n,k=[int(e) for e in input().split()]
print(k*(6*(n-1)+5))
for i in range(n):
print(6*i+1,6*i+2,6*i+3,6*i+5) | Title: Dreamoon and Sets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon likes to play with sets, integers and . is defined as the largest positive integer that divides both *a* and *b*.
Let *S* be a set of exactly four distinct integers greater than 0. Define *S* to be of rank ... | ```python
n,k=[int(e) for e in input().split()]
print(k*(6*(n-1)+5))
for i in range(n):
print(6*i+1,6*i+2,6*i+3,6*i+5)
``` | 0 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,697,033,922 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | import sys
a, b = map(int,sys.stdin.readline().split())
ans = a
while a >0:
a = a//b
ans +=a
print(ans+a)
| Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
import sys
a, b = map(int,sys.stdin.readline().split())
ans = a
while a >0:
a = a//b
ans +=a
print(ans+a)
``` | 0 | |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,671,480,279 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | a = list(input().strip().split())
n, t, k, d = int(a[0]),int(a[1]),int(a[2]),int(a[3])
i_t = (n/k) * t
x = d//t if d > t else t//d
g_t = (x*t)+((n/(k*x))-x)*min(t, d)
if i_t > g_t:
print('YES')
else:
print('No') | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
a = list(input().strip().split())
n, t, k, d = int(a[0]),int(a[1]),int(a[2]),int(a[3])
i_t = (n/k) * t
x = d//t if d > t else t//d
g_t = (x*t)+((n/(k*x))-x)*min(t, d)
if i_t > g_t:
print('YES')
else:
print('No')
``` | 0 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,614,313,187 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 307,200 | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))[:n]
q=rem=0
fc=len(a)
#print(a)
for i in range(n):
#print(a)
c=0
rem=a[i]
while(rem!=0):
q=rem%10
rem//=10
#print(q)
if(q==4 or q==7):
c+=1
#print("\n")
#print(c)
if(c>m):
fc-=1... | Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))[:n]
q=rem=0
fc=len(a)
#print(a)
for i in range(n):
#print(a)
c=0
rem=a[i]
while(rem!=0):
q=rem%10
rem//=10
#print(q)
if(q==4 or q==7):
c+=1
#print("\n")
#print(c)
if(c>m):
... | 3 | |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,609,054,525 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 202 | 2,048,000 | n=int(input())
l=[]
res=0
for _ in range(n):
s=input()
res+=(s.count("C")//2)
l.append(s)
for i in range(n):
temp=0
for j in range(n):
if s[j][i]=="C":
temp+=1
res+=(temp//2)
print(res) | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
n=int(input())
l=[]
res=0
for _ in range(n):
s=input()
res+=(s.count("C")//2)
l.append(s)
for i in range(n):
temp=0
for j in range(n):
if s[j][i]=="C":
temp+=1
res+=(temp//2)
print(res)
``` | -1 | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,658,735,759 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 46 | 0 |
num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
n,x=int(input())%6,int(input())
p=["012","102","120","210","201","021"]
print(p[n][x]) | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
n,x=int(input())%6,int(input())
p=["012","102","120","210","201","021"]
print(p[n][x])
``` | 3 | |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,664,101,425 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | #a= [int(x) for x in input().split()]
def asd():
a= [int(x) for x in input().split()]
cols=a[1]
rows=a[0]
#arr = [[0 for i in range(cols)] for j in range(rows)]
arr = []
for x in range(rows):
arr.append([int(y) for y in input().split()])
f=0... | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
#a= [int(x) for x in input().split()]
def asd():
a= [int(x) for x in input().split()]
cols=a[1]
rows=a[0]
#arr = [[0 for i in range(cols)] for j in range(rows)]
arr = []
for x in range(rows):
arr.append([int(y) for y in input().split()])
... | 0 |
412 | B | Network Configuration | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* deno... | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | [
"3 2\n40 20 30\n",
"6 4\n100 20 40 20 50 50\n"
] | [
"30\n",
"40\n"
] | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | 1,000 | [
{
"input": "3 2\n40 20 30",
"output": "30"
},
{
"input": "6 4\n100 20 40 20 50 50",
"output": "40"
},
{
"input": "1 1\n16",
"output": "16"
},
{
"input": "2 1\n10000 17",
"output": "10000"
},
{
"input": "2 2\n200 300",
"output": "200"
},
{
"input": "3 1... | 1,571,055,963 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 140 | 0 | n,k=list(map(int,input().split(" ")))
print(min(sorted(list(map(int,input().split(" "))),reverse=True)[:k])) | Title: Network Configuration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly a... | ```python
n,k=list(map(int,input().split(" ")))
print(min(sorted(list(map(int,input().split(" "))),reverse=True)[:k]))
``` | 3 | |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,653,122,172 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 46 | 0 | import sys
input = sys.stdin.readline
from math import pi
d, h, v, e = map(int, input().split())
c = pi*(d/2)**2*e
if v <= c:
print("NO")
else:
print("YES")
print(pi*(d/2)**2*h/(v-c)) | Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, cont... | ```python
import sys
input = sys.stdin.readline
from math import pi
d, h, v, e = map(int, input().split())
c = pi*(d/2)**2*e
if v <= c:
print("NO")
else:
print("YES")
print(pi*(d/2)**2*h/(v-c))
``` | 3 | |
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s... | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"outp... | 1,633,020,758 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 46 | 7,065,600 | n, m = map(int , input().split())
values = sorted(list(map(int , input().split())))
result = "YES"
for i in range(m-2):
if (values[i+2] - values[i+1]) + (values[i+1] - values[i]) == 2:
result = "NO"
break
if m and (values[0] == 1 or values[m-1] == n):
result = "NO"
print(result)
... | Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o... | ```python
n, m = map(int , input().split())
values = sorted(list(map(int , input().split())))
result = "YES"
for i in range(m-2):
if (values[i+2] - values[i+1]) + (values[i+1] - values[i]) == 2:
result = "NO"
break
if m and (values[0] == 1 or values[m-1] == n):
result = "NO"
prin... | -1 | |
486 | B | OR in Matrix | PROGRAMMING | 1,300 | [
"greedy",
"hashing",
"implementation"
] | null | null | Let's define logical *OR* as an operation on two logical values (i. e. values that belong to the set {0,<=1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical *OR* of three or more logical values in the same manner:
where is equal to 1 if some *a**i*<==... | The first line contains two integer *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=100), number of rows and number of columns of matrices respectively.
The next *m* lines each contain *n* integers separated by spaces describing rows of matrix *B* (each element of *B* is either 0 or 1). | In the first line, print "NO" if Nam has made a mistake when calculating *B*, otherwise print "YES". If the first line is "YES", then also print *m* rows consisting of *n* integers representing matrix *A* that can produce given matrix *B*. If there are several solutions print any one. | [
"2 2\n1 0\n0 0\n",
"2 3\n1 1 1\n1 1 1\n",
"2 3\n0 1 0\n1 1 1\n"
] | [
"NO\n",
"YES\n1 1 1\n1 1 1\n",
"YES\n0 0 0\n0 1 0\n"
] | none | 1,000 | [
{
"input": "2 2\n1 0\n0 0",
"output": "NO"
},
{
"input": "2 3\n1 1 1\n1 1 1",
"output": "YES\n1 1 1\n1 1 1"
},
{
"input": "2 3\n0 1 0\n1 1 1",
"output": "YES\n0 0 0\n0 1 0"
},
{
"input": "5 5\n1 1 1 1 1\n1 0 0 0 0\n1 0 0 0 0\n1 0 0 0 0\n1 0 0 0 0",
"output": "YES\n1 0 0 0... | 1,696,561,550 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 819,200 | import copy
def check_sides(b, n, m, i, j, covered):
temp = 0
col = 0
covered_temp = copy.deepcopy(covered)
while col < n:
if b[i][col] == 0:
covered = copy.deepcopy(covered_temp)
return [covered, -1]
elif covered[i][col] == 0:
temp += 1
... | Title: OR in Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define logical *OR* as an operation on two logical values (i. e. values that belong to the set {0,<=1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical... | ```python
import copy
def check_sides(b, n, m, i, j, covered):
temp = 0
col = 0
covered_temp = copy.deepcopy(covered)
while col < n:
if b[i][col] == 0:
covered = copy.deepcopy(covered_temp)
return [covered, -1]
elif covered[i][col] == 0:
temp += 1
... | 0 | |
765 | B | Code obfuscation | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"strings"
] | null | null | Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and rep... | In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters. | If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO". | [
"abacaba\n",
"jinotega\n"
] | [
"YES\n",
"NO\n"
] | In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result... | 1,000 | [
{
"input": "abacaba",
"output": "YES"
},
{
"input": "jinotega",
"output": "NO"
},
{
"input": "aaaaaaaaaaa",
"output": "YES"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "bab",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"in... | 1,645,895,947 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | s = input()
ans = [0] * 26
for i in s:
ans[ord(i) - 97] += 1
for i in s:
k = ord(i) - 97
for j in range(k):
if ans[j] == 0:
print('NO')
exit()
print('YES') | Title: Code obfuscation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming cont... | ```python
s = input()
ans = [0] * 26
for i in s:
ans[ord(i) - 97] += 1
for i in s:
k = ord(i) - 97
for j in range(k):
if ans[j] == 0:
print('NO')
exit()
print('YES')
``` | 0 | |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,529,531,855 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 5,324,800 |
""" *** Author--Saket Saumya ***
IIITM
"""
import math
import os
import random
import re
from sys import stdin, stdout
from collections import Counter
from itertools import permutations
def si():
return str(stdin.readline())
def ii():
return int(stdin.readline())
def mi():
return map(int, std... | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
""" *** Author--Saket Saumya ***
IIITM
"""
import math
import os
import random
import re
from sys import stdin, stdout
from collections import Counter
from itertools import permutations
def si():
return str(stdin.readline())
def ii():
return int(stdin.readline())
def mi():
return ma... | -1 | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,602,159,922 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 155 | 2,150,400 | n = int(input())
res = []
def su(i):
return sum(list(map(int, list(str(i)))))
for i in range(10000):
if i + su(i) == n:
res.append(i)
print(len(res))
print(*res) | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
n = int(input())
res = []
def su(i):
return sum(list(map(int, list(str(i)))))
for i in range(10000):
if i + su(i) == n:
res.append(i)
print(len(res))
print(*res)
``` | 0 | |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,490,626,278 | 978 | Python 3 | WRONG_ANSWER | TESTS | 19 | 295 | 21,401,600 | def main():
_ = int(input())
inp = list(map(int, input().split()))
inp.sort()
diff_cnt = {}
for i in range(1, len(inp)):
diff = inp[i] - inp[i - 1]
if diff in diff_cnt:
diff_cnt[diff] += 1
else:
diff_cnt[diff] = 1
k_cnt, k = max([(p_... | Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
def main():
_ = int(input())
inp = list(map(int, input().split()))
inp.sort()
diff_cnt = {}
for i in range(1, len(inp)):
diff = inp[i] - inp[i - 1]
if diff in diff_cnt:
diff_cnt[diff] += 1
else:
diff_cnt[diff] = 1
k_cnt, k ... | 0 | |
12 | B | Correct Solution? | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | B. Correct Solution? | 2 | 256 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe... | The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes. | Print OK if Bob's answer is correct and WRONG_ANSWER otherwise. | [
"3310\n1033\n",
"4\n5\n"
] | [
"OK\n",
"WRONG_ANSWER\n"
] | none | 0 | [
{
"input": "3310\n1033",
"output": "OK"
},
{
"input": "4\n5",
"output": "WRONG_ANSWER"
},
{
"input": "40\n04",
"output": "WRONG_ANSWER"
},
{
"input": "12\n12",
"output": "OK"
},
{
"input": "432\n234",
"output": "OK"
},
{
"input": "17109\n01179",
"o... | 1,692,521,429 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n = input()
s = input()
a = ["1", "0", "2", "3", "4", '5', '6', '7', '8', '9']
ot = ""
for i in range(10):
ot = ot + n.count(a[i])*a[i]
if ot == s:
print("OK")
else:
print("WRONG_ANSWER") | Title: Correct Solution?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuf... | ```python
n = input()
s = input()
a = ["1", "0", "2", "3", "4", '5', '6', '7', '8', '9']
ot = ""
for i in range(10):
ot = ot + n.count(a[i])*a[i]
if ot == s:
print("OK")
else:
print("WRONG_ANSWER")
``` | 0 |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,417,619,305 | 505 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 46 | 0 | n = int(input())
f = 0
s = 0
for i in range(n):
a = int(input())
if a > 0:
f += a
else:
s += -a
if f != s:
print("first") if f > s else print("second")
else:
print("first") if n % 2 == 1 else print("second")
| Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
n = int(input())
f = 0
s = 0
for i in range(n):
a = int(input())
if a > 0:
f += a
else:
s += -a
if f != s:
print("first") if f > s else print("second")
else:
print("first") if n % 2 == 1 else print("second")
``` | 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,670,606,789 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 122 | 0 | s=input()
t=input()
z=s[::-1]
if t==z:
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()
z=s[::-1]
if t==z:
print("YES")
else:
print("NO")
``` | 3.9695 |
808 | B | Average Sleep Time | PROGRAMMING | 1,300 | [
"data structures",
"implementation",
"math"
] | null | null | It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp k... | The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | Output average sleeping time over all weeks.
The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point. | [
"3 2\n3 4 7\n",
"1 1\n10\n",
"8 2\n1 2 4 100000 123 456 789 1\n"
] | [
"9.0000000000\n",
"10.0000000000\n",
"28964.2857142857\n"
] | In the third example there are *n* - *k* + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. | 0 | [
{
"input": "3 2\n3 4 7",
"output": "9.0000000000"
},
{
"input": "1 1\n10",
"output": "10.0000000000"
},
{
"input": "8 2\n1 2 4 100000 123 456 789 1",
"output": "28964.2857142857"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n100000",
"ou... | 1,694,045,079 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 202 | 26,828,800 | n, k = map(int, input().split())
activities = list(map(int, input().split()))
cumulative_sum = [0] * (n + 1)
for i in range(n):
cumulative_sum[i + 1] = cumulative_sum[i] + activities[i]
total_time = 0.0
for i in range(k, n + 1):
week_time = cumulative_sum[i] - cumulative_sum[i - k]
total_t... | Title: Average Sleep Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his s... | ```python
n, k = map(int, input().split())
activities = list(map(int, input().split()))
cumulative_sum = [0] * (n + 1)
for i in range(n):
cumulative_sum[i + 1] = cumulative_sum[i] + activities[i]
total_time = 0.0
for i in range(k, n + 1):
week_time = cumulative_sum[i] - cumulative_sum[i - k]
... | 3 | |
838 | D | Airplane Arrangements | PROGRAMMING | 2,700 | [
"math",
"number theory"
] | null | null | There is an airplane which has *n* rows from front to back. There will be *m* people boarding this airplane.
This airplane has an entrance at the very front and very back of the plane.
Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the... | The first line of input will contain two integers *n*,<=*m* (1<=≤<=*m*<=≤<=*n*<=≤<=1<=000<=000), the number of seats, and the number of passengers, respectively. | Print a single number, the number of ways, modulo 109<=+<=7. | [
"3 3\n"
] | [
"128\n"
] | Here, we will denote a passenger by which seat they were assigned, and which side they came from (either "F" or "B" for front or back, respectively).
For example, one valid way is 3B, 3B, 3B (i.e. all passengers were assigned seat 3 and came from the back entrance). Another valid way would be 2F, 1B, 3F.
One invalid ... | 0 | [
{
"input": "3 3",
"output": "128"
},
{
"input": "1000000 1000000",
"output": "233176135"
},
{
"input": "1000000 500000",
"output": "211837745"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "10 1",
"output": "20"
},
{
"input": "285042 201091",
"o... | 1,502,305,742 | 2,147,483,647 | PyPy 3 | OK | TESTS | 65 | 140 | 23,142,400 | MOD = 10 ** 9 + 7
n, m = input().split(' ')
n = int(n)
m = int(m)
ans = pow(2 * (n + 1), m, MOD)
ans = (ans * (n + 1 - m)) % MOD
ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD
print(ans)
| Title: Airplane Arrangements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is an airplane which has *n* rows from front to back. There will be *m* people boarding this airplane.
This airplane has an entrance at the very front and very back of the plane.
Each person has some assig... | ```python
MOD = 10 ** 9 + 7
n, m = input().split(' ')
n = int(n)
m = int(m)
ans = pow(2 * (n + 1), m, MOD)
ans = (ans * (n + 1 - m)) % MOD
ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD
print(ans)
``` | 3 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,586,668,321 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | n,k=map(int,input().split())
alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
kq=[]
ans=''
while k > 0:
x=alpha.pop(0)
ans+=x
kq.append(x)
k-=1
while len(ans) <= n:
y=kq.pop(0)
ans+=y
print(ans)
| Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
n,k=map(int,input().split())
alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
kq=[]
ans=''
while k > 0:
x=alpha.pop(0)
ans+=x
kq.append(x)
k-=1
while len(ans) <= n:
y=kq.pop(0)
ans+=y
print(ans)
``` | 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,614,799,890 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 307,200 | def yo(ma,mi,n,s):
if ma == n:
return s
main1 = n//ma
main2 = n//mi
flag = 0
for i in range(main1,-1,-1):
for j in range(0,main2+1):
if ma*i+mi*j == n:
flag = 1
break
if flag == 1:
break
main1 = i
... | 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
def yo(ma,mi,n,s):
if ma == n:
return s
main1 = n//ma
main2 = n//mi
flag = 0
for i in range(main1,-1,-1):
for j in range(0,main2+1):
if ma*i+mi*j == n:
flag = 1
break
if flag == 1:
break
... | 0 | |
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,544,707,170 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 109 | 2,457,600 | def main():
n, a, b = map(int, input().split())
line = input()
spaces = [len(e) for e in line.split('*') if e]
ca, cb = a, b
for e in spaces:
if e % 2 != 0:
if ca > cb:
cb -= e // 2
ca -= e - e // 2
else:
ca -... | 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
def main():
n, a, b = map(int, input().split())
line = input()
spaces = [len(e) for e in line.split('*') if e]
ca, cb = a, b
for e in spaces:
if e % 2 != 0:
if ca > cb:
cb -= e // 2
ca -= e - e // 2
else:
... | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,686,028,258 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | dubstep = list(input().split("WUB"))
lyrics = ' '.join(dubstep).strip()
print(lyrics) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
dubstep = list(input().split("WUB"))
lyrics = ' '.join(dubstep).strip()
print(lyrics)
``` | 3 | |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,698,236,069 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | inp = int(input())
s = 'I hate'
p = 'I love'
res = ""
#I hate that I love that I hate it
for i in range(inp):
j = i+1
if j%2 == 1:
res = res+s+' that'+' '
else:
res =res+p+' that'+' '
print(res[0:len(res)-5] +'it')
| Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
inp = int(input())
s = 'I hate'
p = 'I love'
res = ""
#I hate that I love that I hate it
for i in range(inp):
j = i+1
if j%2 == 1:
res = res+s+' that'+' '
else:
res =res+p+' that'+' '
print(res[0:len(res)-5] +'it')
``` | 3 | |
926 | C | Is This a Zebra? | PROGRAMMING | 1,700 | [
"implementation"
] | null | null | A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of *n* pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of *n* zeros and ones, where 0 means that the corresponding column is all white, and 1 m... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the width of the photo.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=1) — the description of the photo. If *a**i* is zero, the *i*-th column is all black. If *a**i* is one, then the *i*-th column is ... | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO".
You can print each letter in any case (upper or lower). | [
"9\n0 0 0 1 1 1 0 0 0\n",
"7\n0 0 0 1 1 1 1\n",
"5\n1 1 1 1 1\n",
"8\n1 1 1 0 0 0 1 1\n",
"9\n1 1 0 1 1 0 1 1 0\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n"
] | The first two examples are described in the statements.
In the third example all pixels are white, so the photo can be a photo of zebra.
In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is e... | 0 | [
{
"input": "9\n0 0 0 1 1 1 0 0 0",
"output": "YES"
},
{
"input": "7\n0 0 0 1 1 1 1",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "YES"
},
{
"input": "8\n1 1 1 0 0 0 1 1",
"output": "NO"
},
{
"input": "9\n1 1 0 1 1 0 1 1 0",
"output": "NO"
},
{
... | 1,521,304,536 | 3,636 | Python 3 | OK | TESTS | 64 | 171 | 8,704,000 | def main():
n = int(input())
photo = [int(x) for x in (input().split())]
color = dict()
cnt = 0
for i in range(n):
if i == 0:
cnt += 1
continue
if photo[i] == photo[i - 1]:
cnt += 1
if photo[i] != photo[i - 1]:
color... | Title: Is This a Zebra?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of *n* pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo ... | ```python
def main():
n = int(input())
photo = [int(x) for x in (input().split())]
color = dict()
cnt = 0
for i in range(n):
if i == 0:
cnt += 1
continue
if photo[i] == photo[i - 1]:
cnt += 1
if photo[i] != photo[i - 1]:
... | 3 | |
482 | A | Diverse Permutation | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your task is to find such permutation *p* of length *n*, that the group of number... | The single line of the input contains two space-separated positive integers *n*, *k* (1<=≤<=*k*<=<<=*n*<=≤<=105). | Print *n* integers forming the permutation. If there are multiple answers, print any of them. | [
"3 2\n",
"3 1\n",
"5 2\n"
] | [
"1 3 2\n",
"1 2 3\n",
"1 3 2 4 5\n"
] | By |*x*| we denote the absolute value of number *x*. | 500 | [
{
"input": "3 2",
"output": "1 3 2"
},
{
"input": "3 1",
"output": "1 2 3"
},
{
"input": "5 2",
"output": "1 3 2 4 5"
},
{
"input": "5 4",
"output": "1 5 2 4 3"
},
{
"input": "10 4",
"output": "1 10 2 9 8 7 6 5 4 3"
},
{
"input": "10 3",
"output": ... | 1,543,288,653 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 342 | 5,734,400 | def main():
n, k = map(int, input().split())
res = [1]
visited = {1}
j = 0
for i in range(k, 0, -1):
res.append(res[-1] + i if j % 2 == 0 else res[-1] - i)
visited.add(res[-1])
j += 1
for i in range(1, n + 1):
if i not in visited:
res.... | Title: Diverse Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<... | ```python
def main():
n, k = map(int, input().split())
res = [1]
visited = {1}
j = 0
for i in range(k, 0, -1):
res.append(res[-1] + i if j % 2 == 0 else res[-1] - i)
visited.add(res[-1])
j += 1
for i in range(1, n + 1):
if i not in visited:
... | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,683,484,853 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 124 | 0 | a=input().split("WUB")
for i in a:
if i!="":
print(i,end=" ") | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
a=input().split("WUB")
for i in a:
if i!="":
print(i,end=" ")
``` | 3 | |
797 | C | Minimal string | PROGRAMMING | 1,700 | [
"data structures",
"greedy",
"strings"
] | null | null | Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u*... | First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. | Print resulting string *u*. | [
"cab\n",
"acdb\n"
] | [
"abc\n",
"abdc\n"
] | none | 0 | [
{
"input": "cab",
"output": "abc"
},
{
"input": "acdb",
"output": "abdc"
},
{
"input": "a",
"output": "a"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "dijee",
"output": "deeji"
},
{
"input": "bhrmc",
... | 1,626,366,770 | 2,147,483,647 | Python 3 | OK | TESTS | 189 | 327 | 8,806,400 | import math
import bisect
def getList(method=int):
return list(map(method, input().split()))
def getInt():
return int(input())
def hasGreater(c):
global mp
for k, v in mp.items():
if c > k and v:
return True
return False
s = [v for v in input()]
t = [... | Title: Minimal string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first char... | ```python
import math
import bisect
def getList(method=int):
return list(map(method, input().split()))
def getInt():
return int(input())
def hasGreater(c):
global mp
for k, v in mp.items():
if c > k and v:
return True
return False
s = [v for v in input... | 3 | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,600,287,846 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 204,800 | entrada = list(input().split())
aula = map(int,input().split())
sono = list(input().split())
valor2 = int(entrada[1])
soma = 0
soma1 = 0
soma2 = 0
for i in range(int(entrada[0])):
if(sono[i] == '1'):
soma1 += int(aula[i])
aula[i] = '0'
for i in range(1,int(entrada[0])):
aula[i] = int(aula[i])+int(aula[i-1])
... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
entrada = list(input().split())
aula = map(int,input().split())
sono = list(input().split())
valor2 = int(entrada[1])
soma = 0
soma1 = 0
soma2 = 0
for i in range(int(entrada[0])):
if(sono[i] == '1'):
soma1 += int(aula[i])
aula[i] = '0'
for i in range(1,int(entrada[0])):
aula[i] = int(aula[i])+int(au... | -1 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,041,375 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | def s_c():
a=int(input())
c=0
for _ in range(a):
petya,vasya,tonya=map(int,input().split())
if petya+vasya+tonya>=2:
c+=1
print(c)
s_c() | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
def s_c():
a=int(input())
c=0
for _ in range(a):
petya,vasya,tonya=map(int,input().split())
if petya+vasya+tonya>=2:
c+=1
print(c)
s_c()
``` | 3 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,699,940,358 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | def min_steps_to_friend_house(x):
# Calculate the number of steps needed
steps = (x + 4) // 5
return steps
# Read input
x = int(input())
# Calculate and print the result
result = min_steps_to_friend_house(x)
print(result)
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
def min_steps_to_friend_house(x):
# Calculate the number of steps needed
steps = (x + 4) // 5
return steps
# Read input
x = int(input())
# Calculate and print the result
result = min_steps_to_friend_house(x)
print(result)
``` | 3 | |
593 | A | 2Char | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sendi... | The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct,... | Print a single integer — the maximum possible total length of words in Andrew's article. | [
"4\nabb\ncacc\naaa\nbbb\n",
"5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n"
] | [
"9",
"6"
] | In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}. | 250 | [
{
"input": "4\nabb\ncacc\naaa\nbbb",
"output": "9"
},
{
"input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa",
"output": "6"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\nz\nz",
"output": "2"
},
{
"input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy",
"output"... | 1,680,892,096 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | word, article = [], []
length = 0
for i in range(int(input())):
temp = input("")
word.append(temp)
while (len(article) < 1):
for j in temp:
if j not in article:
article.append(j)
for i in word:
for j in i:
if (j not in article):
word.remove(... | Title: 2Char
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written an... | ```python
word, article = [], []
length = 0
for i in range(int(input())):
temp = input("")
word.append(temp)
while (len(article) < 1):
for j in temp:
if j not in article:
article.append(j)
for i in word:
for j in i:
if (j not in article):
wo... | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,674,324,426 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | a=int(input())
for j in range(a):
n=input()
if len(n)<=10:
print(n)
else:
for i in range(len(n)):
if i==len(n)-1:
print(n[0],end="")
print(len(n)-2,end="")
print(n[i]) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
a=int(input())
for j in range(a):
n=input()
if len(n)<=10:
print(n)
else:
for i in range(len(n)):
if i==len(n)-1:
print(n[0],end="")
print(len(n)-2,end="")
print(n[i])
``` | 3.977 |
573 | B | Bear and Blocks | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"math"
] | null | null | Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called inter... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109) — sizes of towers. | Print the number of operations needed to destroy all towers. | [
"6\n2 1 4 6 2 2\n",
"7\n3 3 3 1 3 3 3\n"
] | [
"3\n",
"2\n"
] | The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. | 1,000 | [
{
"input": "6\n2 1 4 6 2 2",
"output": "3"
},
{
"input": "7\n3 3 3 1 3 3 3",
"output": "2"
},
{
"input": "7\n5128 5672 5805 5452 5882 5567 5032",
"output": "4"
},
{
"input": "10\n1 2 2 3 5 5 5 4 2 1",
"output": "5"
},
{
"input": "14\n20 20 20 20 20 20 3 20 20 20 2... | 1,670,447,952 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 61 | 0 | from sys import stdin
import math
n = int(stdin.readline().rstrip())
nums = list(map(int, stdin.readline().rstrip().split(' ')))
ans = 0
while sum(nums) != 0:
changes = {}
for i in range(len(nums)):
if i == 0 or i == len(nums) - 1:
changes[i] = 0
else:
chan... | Title: Bear and Blocks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sa... | ```python
from sys import stdin
import math
n = int(stdin.readline().rstrip())
nums = list(map(int, stdin.readline().rstrip().split(' ')))
ans = 0
while sum(nums) != 0:
changes = {}
for i in range(len(nums)):
if i == 0 or i == len(nums) - 1:
changes[i] = 0
else:
... | 0 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,697,040,704 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 0 | x=int(input())
cont=0
while x!=0:
if x>=5:
x-=5
cont+=1
if(x==4):
x-=4
cont+=1
if(x==3):
x-=3
cont+=1
if(x==2):
x-=2
cont+=1
if(x==1):
x-=1
cont+=1
print(cont) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
x=int(input())
cont=0
while x!=0:
if x>=5:
x-=5
cont+=1
if(x==4):
x-=4
cont+=1
if(x==3):
x-=3
cont+=1
if(x==2):
x-=2
cont+=1
if(x==1):
x-=1
cont+=1
print(cont)
``` | 3 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,646,961,896 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 409,600 | import re
import sys
pattern = re.compile(r"h[a-zA-Z]*?e[a-zA-Z]*?i[a-zA-Z]*?d[a-zA-Z]*?i")
word = sys.argv[1]
print("YES") if re.search(pattern, word) else print("NO")
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
import re
import sys
pattern = re.compile(r"h[a-zA-Z]*?e[a-zA-Z]*?i[a-zA-Z]*?d[a-zA-Z]*?i")
word = sys.argv[1]
print("YES") if re.search(pattern, word) else print("NO")
``` | -1 | |
877 | D | Olya and Energy Drinks | PROGRAMMING | 2,100 | [
"data structures",
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks.
Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or littered with cans.
Olya drank a lot of energy drink, so now she can run *k* meters per second. Each second she... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the sizes of the room and Olya's speed.
Then *n* lines follow containing *m* characters each, the *i*-th of them contains on *j*-th position "#", if the cell (*i*,<=*j*) is littered with cans, and "." otherwise.
The last line c... | Print a single integer — the minimum time it will take Olya to get from (*x*1,<=*y*1) to (*x*2,<=*y*2).
If it's impossible to get from (*x*1,<=*y*1) to (*x*2,<=*y*2), print -1. | [
"3 4 4\n....\n###.\n....\n1 1 3 1\n",
"3 4 1\n....\n###.\n....\n1 1 3 1\n",
"2 2 1\n.#\n#.\n1 1 2 2\n"
] | [
"3",
"8",
"-1"
] | In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second.
In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds.
Olya does not recommend drinking ener... | 2,000 | [
{
"input": "3 4 4\n....\n###.\n....\n1 1 3 1",
"output": "3"
},
{
"input": "3 4 1\n....\n###.\n....\n1 1 3 1",
"output": "8"
},
{
"input": "2 2 1\n.#\n#.\n1 1 2 2",
"output": "-1"
},
{
"input": "10 10 1\n##########\n#.........\n#.#######.\n#.#.....#.\n#.#.###.#.\n#.#.#.#.#.\n... | 1,668,171,586 | 2,986 | PyPy 3 | WRONG_ANSWER | TESTS | 30 | 576 | 37,888,000 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * m + v
def bfs(x1, y1, x2, y2):
q1, q2 = [], []
q1.append((x1, y1, 1))
q1.append((x1, y1, 2))
dist1, dist2 = [inf] * l, [inf] * l
dist1[f(x1, y1)], dist2[f(x1, y1)] = 0, 0
d =... | Title: Olya and Energy Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks.
Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or litt... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * m + v
def bfs(x1, y1, x2, y2):
q1, q2 = [], []
q1.append((x1, y1, 1))
q1.append((x1, y1, 2))
dist1, dist2 = [inf] * l, [inf] * l
dist1[f(x1, y1)], dist2[f(x1, y1)] = 0, ... | 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,651,527,093 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 77 | 2,457,600 | def argmax(lst):
return lst.index(max(lst))
n,m = (int(i) for i in input().split(" "))
arr = {}
for _ in range(m):
x = [int(i) for i in input().split(" ")]
y = argmax(x)
arr[y] = arr.get(y,0)+1
c = -1
c2 = -1
for i,j in arr.items():
if j>c:
c = j
c2 = i
elif... | 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
def argmax(lst):
return lst.index(max(lst))
n,m = (int(i) for i in input().split(" "))
arr = {}
for _ in range(m):
x = [int(i) for i in input().split(" ")]
y = argmax(x)
arr[y] = arr.get(y,0)+1
c = -1
c2 = -1
for i,j in arr.items():
if j>c:
c = j
c2 = i... | 3 | |
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 1,000 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,520,179,767 | 2,067 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 46 | 5,632,000 | a = list(map(int, input().split()))
match = a[0] / 2
if a[1] <= match and a[2] > match:
print("Final!")
c=0
while match!=1:
c+=1
match/=2
print(c) | Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in th... | ```python
a = list(map(int, input().split()))
match = a[0] / 2
if a[1] <= match and a[2] > match:
print("Final!")
c=0
while match!=1:
c+=1
match/=2
print(c)
``` | 0 | |
333 | E | Summer Earnings | PROGRAMMING | 2,500 | [
"binary search",
"bitmasks",
"brute force",
"geometry",
"sortings"
] | null | null | Many schoolchildren look for a job for the summer, and one day, when Gerald was still a schoolboy, he also decided to work in the summer. But as Gerald was quite an unusual schoolboy, he found quite unusual work. A certain Company agreed to pay him a certain sum of money if he draws them three identical circles on a pl... | The first line contains a single integer *n* — the number of centers (3<=≤<=*n*<=≤<=3000). The following *n* lines each contain two integers *x**i*,<=*y**i* (<=-<=104<=≤<=*x**i*,<=*y**i*<=≤<=104) — the coordinates of potential circle centers, provided by the Company.
All given points are distinct. | Print a single real number — maximum possible radius of circles. The answer will be accepted if its relative or absolute error doesn't exceed 10<=-<=6. | [
"3\n0 1\n1 0\n1 1\n",
"7\n2 -3\n-2 -3\n3 0\n-3 -1\n1 -2\n2 -2\n-1 0\n"
] | [
"0.50000000000000000000\n",
"1.58113883008418980000\n"
] | none | 2,500 | [] | 1,681,386,603 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 4 | 3,368 | 268,390,400 | def dis(x1, y1, x2, y2):
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)
n = int(input())
a = [[0] * 3 for _ in range(n * n)]
x, y = [0], [0]
for _ in range(n):
xx, yy = map(int, input().split()) # 坐标
x.append(xx)
y.append(yy)
m = 0 # 边数
st = [[0] * (n + 1) for _ in range(n + 1)]
f... | Title: Summer Earnings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many schoolchildren look for a job for the summer, and one day, when Gerald was still a schoolboy, he also decided to work in the summer. But as Gerald was quite an unusual schoolboy, he found quite unusual work. A cert... | ```python
def dis(x1, y1, x2, y2):
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)
n = int(input())
a = [[0] * 3 for _ in range(n * n)]
x, y = [0], [0]
for _ in range(n):
xx, yy = map(int, input().split()) # 坐标
x.append(xx)
y.append(yy)
m = 0 # 边数
st = [[0] * (n + 1) for _ in range(... | 0 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,636,407,392 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 28,364,800 | n = int(input(""))
l = input("").split(" ")
gaps = []
l = [int(e) for e in l]
l = sorted(l)
for x in range(len(l)-1):
gaps.append(l[x+1]-l[x])
print(gaps)
x = gaps.index(max(gaps))
if x == 0:
print(sum(gaps[x+2:]))
elif x == len(gaps) - 1:
print(sum(gaps[0:len(gaps)-2]))
else:
print(sum(gaps[0:x... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
n = int(input(""))
l = input("").split(" ")
gaps = []
l = [int(e) for e in l]
l = sorted(l)
for x in range(len(l)-1):
gaps.append(l[x+1]-l[x])
print(gaps)
x = gaps.index(max(gaps))
if x == 0:
print(sum(gaps[x+2:]))
elif x == len(gaps) - 1:
print(sum(gaps[0:len(gaps)-2]))
else:
print(su... | 0 | |
761 | D | Dasha and Very Difficult Problem | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Dasha logged into the system and began to solve problems. One of them is as follows:
Given two sequences *a* and *b* of length *n* each you need to write a sequence *c* of length *n*, the *i*-th element of which is calculated as follows: *c**i*<==<=*b**i*<=-<=*a**i*.
About sequences *a* and *b* we know that their ele... | The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*l*<=≤<=*r*<=≤<=109) — the length of the sequence and boundaries of the segment where the elements of sequences *a* and *b* are.
The next line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (*l*<=≤<=*a**i*<=≤<=*r*) — the elements o... | If there is no the suitable sequence *b*, then in the only line print "-1".
Otherwise, in the only line print *n* integers — the elements of any suitable sequence *b*. | [
"5 1 5\n1 1 1 1 1\n3 1 5 4 2\n",
"4 2 9\n3 4 8 9\n3 2 1 4\n",
"6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6\n"
] | [
"3 1 5 4 2 ",
"2 2 2 9 ",
"-1\n"
] | Sequence *b* which was found in the second sample is suitable, because calculated sequence *c* = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that *c*<sub class="lower-index">*i*</sub> = *b*<sub class="lower-index">*i*</sub> - *a*<sub class="lower-index">*i*</sub>) has compressed sequence equals to *p* = ... | 2,000 | [
{
"input": "5 1 5\n1 1 1 1 1\n3 1 5 4 2",
"output": "3 1 5 4 2 "
},
{
"input": "4 2 9\n3 4 8 9\n3 2 1 4",
"output": "2 2 2 9 "
},
{
"input": "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6",
"output": "-1"
},
{
"input": "5 1 7\n1 4 4 6 5\n5 2 1 4 3",
"output": "2 2 1 6 4 "
},
{
... | 1,485,877,862 | 4,562 | Python 3 | OK | TESTS | 63 | 327 | 20,889,600 | n,l,r = map(int,input().split())
A = list(map(int,input().split()))
P = list(map(int,input().split()))
s = [0] * n
per=0
for j in range(n):
s[P[j] - 1] = j
b = [0] * n
b[s[0]] = l
for j in range(1,n):
last = b[s[j-1]] - A[s[j-1]]
nexs = last+1
if r - A[s[j]] > last:
b[s[j]] =... | Title: Dasha and Very Difficult Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dasha logged into the system and began to solve problems. One of them is as follows:
Given two sequences *a* and *b* of length *n* each you need to write a sequence *c* of length *n*, the *i*-th elemen... | ```python
n,l,r = map(int,input().split())
A = list(map(int,input().split()))
P = list(map(int,input().split()))
s = [0] * n
per=0
for j in range(n):
s[P[j] - 1] = j
b = [0] * n
b[s[0]] = l
for j in range(1,n):
last = b[s[j-1]] - A[s[j-1]]
nexs = last+1
if r - A[s[j]] > last:
... | 3 | |
847 | D | Dog Show | PROGRAMMING | 2,200 | [
"constructive algorithms",
"data structures",
"greedy"
] | null | null | A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win!
On the show a dog needs to eat as many bowls of dog food as poss... | Two integer numbers are given in the first line - *n* and *T* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*T*<=≤<=2·109) — the number of bowls of food and the time when the dog is stopped.
On the next line numbers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) are given, where *t**i* is the moment of time when the *i*-th bowl o... | Output a single integer — the maximum number of bowls of food the dog will be able to eat in *T* seconds. | [
"3 5\n1 5 3\n",
"1 2\n1\n",
"1 1\n1\n"
] | [
"2\n",
"1\n",
"0\n"
] | In the first example the dog should skip the second bowl to eat from the two bowls (the first and the third). | 0 | [
{
"input": "3 5\n1 5 3",
"output": "2"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "2 2\n2 3",
"output": "0"
},
{
"input": "2 3\n2 1",
"output": "1"
},
{
"i... | 1,536,441,426 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n, T = input().strip().split(' ')
n,T = int(n), int(T)
a = input().strip().split(' ')
a = [int(i) for i in a]
eat = 0
time = 1
for i in range(len(a)):
if time == T:
break
while a[i] != 0:
for k in range(len(a)):
if a[k] != 0:
a[k]-=1
time +=1
if time == T:
break
if a[i] == 0:
... | Title: Dog Show
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants an... | ```python
n, T = input().strip().split(' ')
n,T = int(n), int(T)
a = input().strip().split(' ')
a = [int(i) for i in a]
eat = 0
time = 1
for i in range(len(a)):
if time == T:
break
while a[i] != 0:
for k in range(len(a)):
if a[k] != 0:
a[k]-=1
time +=1
if time == T:
break
if a... | 0 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,624,177,524 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n=int(input())
arr=list(map(int,input().split()))
arr.sort()
for j in arr:
if(j>arr[0]):
print(j)
break | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
for j in arr:
if(j>arr[0]):
print(j)
break
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers *k* and *p*, w... | The input consists of two space-separated integers *p* and *k* (3<=≤<=*p*<=≤<=1<=000<=000, 0<=≤<=*k*<=≤<=*p*<=-<=1) on a single line. It is guaranteed that *p* is an odd prime number. | Print a single integer, the number of distinct functions *f* modulo 109<=+<=7. | [
"3 2\n",
"5 4\n"
] | [
"3\n",
"25\n"
] | In the first sample, *p* = 3 and *k* = 2. The following functions work:
1. *f*(0) = 0, *f*(1) = 1, *f*(2) = 2. 1. *f*(0) = 0, *f*(1) = 2, *f*(2) = 1. 1. *f*(0) = *f*(1) = *f*(2) = 0. | 0 | [
{
"input": "3 2",
"output": "3"
},
{
"input": "5 4",
"output": "25"
},
{
"input": "7 2",
"output": "49"
},
{
"input": "7 6",
"output": "343"
},
{
"input": "10007 25",
"output": "100140049"
},
{
"input": "40037 4",
"output": "602961362"
},
{
... | 1,448,988,678 | 4,578 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 62 | 307,200 | c=1000000007
#special cases for k=0, 1
p, k = map(int, input().split(" "))
def binary(number):
#turn into string
s=""
while number!=0:
r = number%2
s = str(r) + s
number = number//2
return s
def mod(base, expo, mod):
#write expo as binary and calculate to ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted w... | ```python
c=1000000007
#special cases for k=0, 1
p, k = map(int, input().split(" "))
def binary(number):
#turn into string
s=""
while number!=0:
r = number%2
s = str(r) + s
number = number//2
return s
def mod(base, expo, mod):
#write expo as binary and cal... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,639,802,943 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n=int(input())
a=input().split()
newa=[]
for j in a:
newa.append(int(j))
num=0
can=[]
cannot=[]
for i in range(n):
if newa[i]%2==0:
num+=1; can.append(i)
if newa[i]%2!=0:
cannot.append(i)
if num==n-1:
print()
else:
print(i in can) | 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())
a=input().split()
newa=[]
for j in a:
newa.append(int(j))
num=0
can=[]
cannot=[]
for i in range(n):
if newa[i]%2==0:
num+=1; can.append(i)
if newa[i]%2!=0:
cannot.append(i)
if num==n-1:
print()
else:
print(i in can)
``` | 0 |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,688,023,816 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 13 | 124 | 0 | rounds = int(input())
scores:dict = {
}
highes = 'a[0]'
while(rounds != 0):
a = list(input().split())
if highes == 'a[0]':
highes = a[0]
if a[0] in scores.keys():
scores.update({a[0]:scores[a[0]]+int(a[1])})
else:
scores.update({a[0]:int(a[1])})
rounds = rounds-1... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
rounds = int(input())
scores:dict = {
}
highes = 'a[0]'
while(rounds != 0):
a = list(input().split())
if highes == 'a[0]':
highes = a[0]
if a[0] in scores.keys():
scores.update({a[0]:scores[a[0]]+int(a[1])})
else:
scores.update({a[0]:int(a[1])})
rounds ... | 0 |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,644,946,522 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 2,560,000 | n = int(input())
num = str(1378**n)
print(num[-1])
| Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n = int(input())
num = str(1378**n)
print(num[-1])
``` | 0 | |
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* ar... | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
... | 1,444,647,215 | 6,215 | Python 3 | WRONG_ANSWER | PRETESTS | 8 | 62 | 0 | n = int(input())
a = list(map(int, input().split()))
x = sum(map(int, list(a)))
b = 1
d = 0
for i in range(1,n-1):
if a[i] + a[i+1] >= 1:
b += 1
if a[i] + a[i+1] == 0:
d = 1
b = abs(b - d)
if a[0] == 0 or a[n-1] == 0:
b = b - 1
if a[0] == 1 or a[n-1] == 1:
b = b + 1
if x =... | Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic ... | ```python
n = int(input())
a = list(map(int, input().split()))
x = sum(map(int, list(a)))
b = 1
d = 0
for i in range(1,n-1):
if a[i] + a[i+1] >= 1:
b += 1
if a[i] + a[i+1] == 0:
d = 1
b = abs(b - d)
if a[0] == 0 or a[n-1] == 0:
b = b - 1
if a[0] == 1 or a[n-1] == 1:
b = b +... | 0 | |
204 | A | Little Elephant and Interval | PROGRAMMING | 1,500 | [
"binary search",
"combinatorics",
"dp"
] | null | null | The Little Elephant very much loves sums on intervals.
This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 4... | The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | On a single line print a single integer — the answer to the problem. | [
"2 47\n",
"47 1024\n"
] | [
"12\n",
"98\n"
] | In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | 500 | [
{
"input": "2 47",
"output": "12"
},
{
"input": "47 1024",
"output": "98"
},
{
"input": "1 1000",
"output": "108"
},
{
"input": "1 10000",
"output": "1008"
},
{
"input": "47 8545",
"output": "849"
},
{
"input": "1000 1000",
"output": "0"
},
{
... | 1,580,288,559 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 34 | 218 | 307,200 | def count(l,L):
x=0
if L<=10:x=L
else:
x+=9
if L<=100:x+=(L//11)
else:
x+=9
leng=len(l)
for i in range(max(0,leng-3)):
x+=(9*(10**(i+1)))
leng-=2
for i,y in enumerate(l[:-1]):
y=i... | Title: Little Elephant and Interval
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), ... | ```python
def count(l,L):
x=0
if L<=10:x=L
else:
x+=9
if L<=100:x+=(L//11)
else:
x+=9
leng=len(l)
for i in range(max(0,leng-3)):
x+=(9*(10**(i+1)))
leng-=2
for i,y in enumerate(l[:-1]):
... | 0 | |
568 | B | Symmetric and Transitive | PROGRAMMING | 1,900 | [
"combinatorics",
"dp",
"math"
] | null | null | Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.
A set ρ of pairs (*a*,<=*b*) of elem... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=4000). | In a single line print the answer to the problem modulo 109<=+<=7. | [
"1\n",
"2\n",
"3\n"
] | [
"1\n",
"3\n",
"10\n"
] | If *n* = 1 there is only one such relation — an empty one, i.e. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8891a227c918474e5d76377d4644cd7cc01e1ffd.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In other words, for a single element *x* of set *A* the following is hold: <img alig... | 1,000 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "10"
},
{
"input": "4",
"output": "37"
},
{
"input": "5",
"output": "151"
},
{
"input": "6",
"output": "674"
},
{
"input": "7",
"output": "3263"... | 1,439,814,380 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | MOD = 1000000007
dp = [1]
n = input()
if (n==1):
print 1
else:
for i in range(1,n):
dp.append([1])
for j in range(1,i+1):
dp[i].append(0)
c = [[0,0]]
for i in range(1,n+1):
c.append([1, i])
for j in range(2,i+1):
if (j>i-1):
... | Title: Symmetric and Transitive
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. ... | ```python
MOD = 1000000007
dp = [1]
n = input()
if (n==1):
print 1
else:
for i in range(1,n):
dp.append([1])
for j in range(1,i+1):
dp[i].append(0)
c = [[0,0]]
for i in range(1,n+1):
c.append([1, i])
for j in range(2,i+1):
if (j>i-1... | -1 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,677,943,237 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 61 | 0 | s = str(input())
moves = 0
indx = 0
for i in range(len(s)):
point = abs(ord(s[i]) - 97)
if (abs(indx - point) < 13):
moves += abs(indx - point)
else:
moves += 26 - abs(indx - point)
indx = point
print(moves)
| 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
s = str(input())
moves = 0
indx = 0
for i in range(len(s)):
point = abs(ord(s[i]) - 97)
if (abs(indx - point) < 13):
moves += abs(indx - point)
else:
moves += 26 - abs(indx - point)
indx = point
print(moves)
``` | 3 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,596,807,025 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 155 | 20,582,400 | from collections import deque
def solve(n):
if(n<100):
if(n<10):
n-=1
return n,1
elif(n%11 <= n%10 and n>9):
n-=11
r=11
elif(n%10 < n%11 and n>9):
n-=10
r=10
return n,r
elif(n>=100 and n<1000):
a=n%111
b=n%110
c=n%101
d=n%100
... | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
from collections import deque
def solve(n):
if(n<100):
if(n<10):
n-=1
return n,1
elif(n%11 <= n%10 and n>9):
n-=11
r=11
elif(n%10 < n%11 and n>9):
n-=10
r=10
return n,r
elif(n>=100 and n<1000):
a=n%111
b=n%110
c=n%101
d=n... | 0 | |
922 | C | Cave Painting | PROGRAMMING | 1,600 | [
"brute force",
"number theory"
] | null | null | Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp.
Imp wan... | The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018). | Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper). | [
"4 4\n",
"5 3\n"
] | [
"No\n",
"Yes\n"
] | In the first sample remainders modulo 1 and 4 coincide. | 1,250 | [
{
"input": "4 4",
"output": "No"
},
{
"input": "5 3",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "744 18",
"output": "No"
},
{
"input": "47879 10",
"output": "Yes"
},
{
"input": "1000000000000000000 1000000000000000000",
"ou... | 1,658,556,091 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n, k = map(int,input().split())
if n % 2 == 0 and k >= 2:
print("NO")
elif n % 3 == 0 and k >= 3:
print("NO")
elif n % 2 == 1 and k >= n:
print("NO")
else:
print("YES")
| Title: Cave Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all ... | ```python
n, k = map(int,input().split())
if n % 2 == 0 and k >= 2:
print("NO")
elif n % 3 == 0 and k >= 3:
print("NO")
elif n % 2 == 1 and k >= n:
print("NO")
else:
print("YES")
``` | 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,692,597,031 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 | def solve(s):
start = 'a'
sum = 0
for i in range(len(s)):
x = abs(ord(s[i]) - ord(start))
y = 26 - abs(x)
sum += min(x, y)
start = s[i]
print(sum)
if __name__ == "__main__":
solve(input())
| 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 solve(s):
start = 'a'
sum = 0
for i in range(len(s)):
x = abs(ord(s[i]) - ord(start))
y = 26 - abs(x)
sum += min(x, y)
start = s[i]
print(sum)
if __name__ == "__main__":
solve(input())
``` | 3 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,618,665,347 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | t=int(input())
for i in range(t):
l=[int(x) for x in input().split()]
l=list(set(l))
l.sort()
if len(l)<2:
print("NO")
else:
print(l[1])
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
t=int(input())
for i in range(t):
l=[int(x) for x in input().split()]
l=list(set(l))
l.sort()
if len(l)<2:
print("NO")
else:
print(l[1])
``` | -1 |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,605,734,175 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,150,400 | # A. Summer Camp
n = int(input())
lst = [str(x) for x in range(n)]
s = ''.join(lst)
print(s[n])
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
# A. Summer Camp
n = int(input())
lst = [str(x) for x in range(n)]
s = ''.join(lst)
print(s[n])
``` | -1 | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,589,217,194 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 6,656,000 | # cook your dish here
n=int(input())
count=0
x=1
while int(bin(x)[2:])<=n:
count+=1
x+=1
print(count) | Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
# cook your dish here
n=int(input())
count=0
x=1
while int(bin(x)[2:])<=n:
count+=1
x+=1
print(count)
``` | 3.841409 |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,418,836,269 | 2,469 | Python 3 | OK | TESTS | 19 | 61 | 0 | n=int(input())
lis=input().split()
for i in range(n):
lis[i]=int(lis[i])
def diff(a):
m=a[1]-a[0]
for i in range(1,len(a)-1):
if a[i+1]-a[i]>m:
m=a[i+1]-a[i]
return m
lis2=[]
for i in range(1,n-1):
lis2.append(diff(lis[:i]+lis[i+1:]))
print(min(lis2))
... | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n=int(input())
lis=input().split()
for i in range(n):
lis[i]=int(lis[i])
def diff(a):
m=a[1]-a[0]
for i in range(1,len(a)-1):
if a[i+1]-a[i]>m:
m=a[i+1]-a[i]
return m
lis2=[]
for i in range(1,n-1):
lis2.append(diff(lis[:i]+lis[i+1:]))
print(min(lis2))
... | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,695,113,645 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | s = input()
word = "hello"
p = 0
for c in s:
if c == word[p]:
p += 1
if p == len(word):
print("YES")
exit()
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
word = "hello"
p = 0
for c in s:
if c == word[p]:
p += 1
if p == len(word):
print("YES")
exit()
print("NO")
``` | 3.977 |
401 | C | Team | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. | In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. | [
"1 2\n",
"4 8\n",
"4 10\n",
"1 5\n"
] | [
"101\n",
"110110110101\n",
"11011011011011\n",
"-1\n"
] | none | 1,500 | [
{
"input": "1 2",
"output": "101"
},
{
"input": "4 8",
"output": "110110110101"
},
{
"input": "4 10",
"output": "11011011011011"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "3 4",
"output": "1010101"
},
{
"input": "3 10",
"output": "-1"
},
... | 1,699,905,956 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | def main(n, m):
if m/2-1 > n or n-2 >= m:
return -1
ans = ''
if m/2 >= n:
ans += '110'*(n) + '1'*(m - (n*2))
elif n == m or n-1 == m :
ans += '01'*(m) + '0'*(n-m)
else:
ans += '110'*((m-n)//2) + '10'*(n-(m-n)//2) + '1' * (m - (((m-n)//2)*2 + n-(m-n)//2))
... | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each t... | ```python
def main(n, m):
if m/2-1 > n or n-2 >= m:
return -1
ans = ''
if m/2 >= n:
ans += '110'*(n) + '1'*(m - (n*2))
elif n == m or n-1 == m :
ans += '01'*(m) + '0'*(n-m)
else:
ans += '110'*((m-n)//2) + '10'*(n-(m-n)//2) + '1' * (m - (((m-n)//2)*2 + n-(m-n)... | 0 | |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,697,014,984 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 59 | 77 | 0 | #problem ll
T=int(input())
s=input()
a=set()
for i in s:
if i.isalpha():
i=i.lower()
a.add(i)
if len(a)==26:
print("Yes")
else:
print("No")
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
#problem ll
T=int(input())
s=input()
a=set()
for i in s:
if i.isalpha():
i=i.lower()
a.add(i)
if len(a)==26:
print("Yes")
else:
print("No")
``` | 3 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,699,628,461 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
a = list(map(int, input().split()))
total_sum = sum(a)
if total_sum % 3 != 0:
print(0)
else:
target_sum = total_sum // 3
prefix_sum = [0] * n
cnt = [0] * n
prefix_sum[0] = a[0]
for i in range(1, n):
prefix_sum[i] = prefix_sum[i-1] + a[i]
if prefix_sum[n-1... | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
n = int(input())
a = list(map(int, input().split()))
total_sum = sum(a)
if total_sum % 3 != 0:
print(0)
else:
target_sum = total_sum // 3
prefix_sum = [0] * n
cnt = [0] * n
prefix_sum[0] = a[0]
for i in range(1, n):
prefix_sum[i] = prefix_sum[i-1] + a[i]
if pref... | 0 | |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 ... | 1,599,843,027 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 280 | 0 | n, m = [int(s) for s in input().split(' ')]
ans = [n // m] * (m - n % m) + [n // m + 1] * (n % m)
print(*ans) | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ... | ```python
n, m = [int(s) for s in input().split(' ')]
ans = [n // m] * (m - n % m) + [n // m + 1] * (n % m)
print(*ans)
``` | 3 | |
976 | C | Nested Segments | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"sortings"
] | null | null | You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment. | Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. | [
"5\n1 10\n2 9\n3 9\n2 3\n2 9\n",
"3\n1 5\n2 6\n6 20\n"
] | [
"2 1\n",
"-1 -1\n"
] | In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly. | 0 | [
{
"input": "5\n1 10\n2 9\n3 9\n2 3\n2 9",
"output": "2 1"
},
{
"input": "3\n1 5\n2 6\n6 20",
"output": "-1 -1"
},
{
"input": "1\n1 1000000000",
"output": "-1 -1"
},
{
"input": "2\n1 1000000000\n1 1000000000",
"output": "2 1"
},
{
"input": "2\n1 1000000000\n5000000... | 1,525,151,152 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 103 | 2,000 | 65,945,600 | n= int(input())
seg = []
for i in range(n):
seg.append(list(map(int,input().split())))
seg[i].append(i+1)
seg = sorted(seg,key=lambda x : (x[0],-x[1]))
for i in range(n):
if i == n-1 or n <= 1:
print("-1 -1")
break
elif seg[i][1] >= seg[i+1][1]:
print(seg[i... | Title: Nested Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment... | ```python
n= int(input())
seg = []
for i in range(n):
seg.append(list(map(int,input().split())))
seg[i].append(i+1)
seg = sorted(seg,key=lambda x : (x[0],-x[1]))
for i in range(n):
if i == n-1 or n <= 1:
print("-1 -1")
break
elif seg[i][1] >= seg[i+1][1]:
p... | 0 | |
357 | A | Group of Students | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got ... | The first line contains integer *m* (2<=≤<=*m*<=≤<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≤<=*c**i*<=≤<=100). The third line contains two space-separated integers *x* and *y* (1<=≤<=*x*<=≤<=*y*<=≤<=10000). At least one *c**i* is greater than 0. | If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them. | [
"5\n3 4 3 2 1\n6 8\n",
"5\n0 3 3 4 2\n3 10\n",
"2\n2 5\n3 6\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | 500 | [
{
"input": "5\n3 4 3 2 1\n6 8",
"output": "3"
},
{
"input": "5\n0 3 3 4 2\n3 10",
"output": "4"
},
{
"input": "2\n2 5\n3 6",
"output": "0"
},
{
"input": "3\n0 1 0\n2 10",
"output": "0"
},
{
"input": "5\n2 2 2 2 2\n5 5",
"output": "0"
},
{
"input": "10\... | 1,381,928,368 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 62 | 204,800 | m=int(input())
c=list(map(int,input().split()))
x,y=map(int,input().split())
for i in range(1,m):
if((sum(c[:i])>=x and sum(c[:i])<=y) and ((sum(c[i:])>=x and sum(c[i:])<=y))):
m=0
break
if(m==0):
print(i+1)
else:
print(0)
| Title: Group of Students
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According ... | ```python
m=int(input())
c=list(map(int,input().split()))
x,y=map(int,input().split())
for i in range(1,m):
if((sum(c[:i])>=x and sum(c[:i])<=y) and ((sum(c[i:])>=x and sum(c[i:])<=y))):
m=0
break
if(m==0):
print(i+1)
else:
print(0)
``` | 3 | |
919 | A | Supermarket | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation"
] | null | null | We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo.
Now imagine you'd... | The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples.
The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b ... | The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$.
Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} ... | [
"3 5\n1 2\n3 4\n1 3\n",
"2 1\n99 100\n98 99\n"
] | [
"1.66666667\n",
"0.98989899\n"
] | In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan.
In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan. | 500 | [
{
"input": "3 5\n1 2\n3 4\n1 3",
"output": "1.66666667"
},
{
"input": "2 1\n99 100\n98 99",
"output": "0.98989899"
},
{
"input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 8... | 1,665,988,076 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 109 | 4,300,800 | n,m = map(int,input().strip().split())
mini = 100
while(n):
a,b = map(int,input().strip().split())
if (a/b)*m <mini:
mini = (a/b)*m
n-=1
print(round(mini, 8)) | Title: Supermarket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (Yo... | ```python
n,m = map(int,input().strip().split())
mini = 100
while(n):
a,b = map(int,input().strip().split())
if (a/b)*m <mini:
mini = (a/b)*m
n-=1
print(round(mini, 8))
``` | 0 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,677,470,100 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | //http://codeforces.com/problemset/problem/455/A
#include </bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[100005];
ll freq[100005];
int main()
{
int n,mx=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
freq[a[i]]++;
mx=max(mx,a[i]);
}
dp[1]=freq[1];
for... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
//http://codeforces.com/problemset/problem/455/A
#include </bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[100005];
ll freq[100005];
int main()
{
int n,mx=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
freq[a[i]]++;
mx=max(mx,a[i]);
}
dp[1]=freq... | -1 | |
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,693,739,796 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | s = input()
i = 0
fs = ""
while i < len(s):
if s[i] == ".":
fs += "0"
i += 1
else:
sub = (s[i]+s[i+1])
if sub == "-.":
fs += "1"
elif sub == "--":
fs += "2"
i += 2
print(fs) | 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
s = input()
i = 0
fs = ""
while i < len(s):
if s[i] == ".":
fs += "0"
i += 1
else:
sub = (s[i]+s[i+1])
if sub == "-.":
fs += "1"
elif sub == "--":
fs += "2"
i += 2
print(fs)
``` | 3.969 |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,696,238,213 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 186 | 1,228,800 | a = input()
for i in a:
if i.lower() not in ['a','e','i','o','u','y']:
print('.',end="")
if i.isupper():
i = i.lower()
print(i,end="")
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
a = input()
for i in a:
if i.lower() not in ['a','e','i','o','u','y']:
print('.',end="")
if i.isupper():
i = i.lower()
print(i,end="")
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,596,222,975 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 202 | 22,323,200 | import re
p='[h][a-z]*[e][a-z]*[l][a-z]*[l][a-z]*o'
s=input()
if re.search(p,s):
print('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
import re
p='[h][a-z]*[e][a-z]*[l][a-z]*[l][a-z]*o'
s=input()
if re.search(p,s):
print('YES')
else:
print('NO')
``` | 3.85742 |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,610,018,319 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 307,200 | a=np.ones((3,3),dtype=int)
c=np.zeros((3,3),dtype=int)
for i in range(3):
b=input()
c[i]=b.split()
for i in range(3):
for j in range(3):
if c[i][j]%2!=0:
a[i][j]=1-a[i][j]
if (i-1)>=0:
a[i-1][j]=1-a[i-1][j]
if (i+1)<... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
a=np.ones((3,3),dtype=int)
c=np.zeros((3,3),dtype=int)
for i in range(3):
b=input()
c[i]=b.split()
for i in range(3):
for j in range(3):
if c[i][j]%2!=0:
a[i][j]=1-a[i][j]
if (i-1)>=0:
a[i-1][j]=1-a[i-1][j]
... | -1 | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,600,517,965 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 248 | 0 | n = int(input())
ans = "NO"
for i in range(1,n + 1):
a = (i * (i + 1)) / 2
if a > n:
break
if a == n:
ans = "YES"
print(ans) | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
n = int(input())
ans = "NO"
for i in range(1,n + 1):
a = (i * (i + 1)) / 2
if a > n:
break
if a == n:
ans = "YES"
print(ans)
``` | 3.938 |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,602,250,551 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | #author:: Blackink
#tt = int(input())
#while tt:
#tt -= 1
#ll = list(map(int,(input().split())))
n = int(input())
m = int(input())
if n < 27:
r = 2**n
d = m%r
else:
print(m)
| Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
#author:: Blackink
#tt = int(input())
#while tt:
#tt -= 1
#ll = list(map(int,(input().split())))
n = int(input())
m = int(input())
if n < 27:
r = 2**n
d = m%r
else:
print(m)
``` | 0 | |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,633,507,289 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 3,000 | 6,758,400 | def main():
n = int(input()) + 1
count = 0
for i in range(2, n):
for j in range(i+1, n):
for k in range(j+1, n):
if i**2 + j**2 == k**2:
count += 1
print(count)
main()
| Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
def main():
n = int(input()) + 1
count = 0
for i in range(2, n):
for j in range(i+1, n):
for k in range(j+1, n):
if i**2 + j**2 == k**2:
count += 1
print(count)
main()
``` | 0 | |
851 | B | Arpa and an exam about geometry | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ... | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | 1,000 | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"i... | 1,504,558,616 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 39 | 124 | 0 | ax, ay, bx, by, cx, cy = [int(i) for i in input().split()]
def dist(ax, ay, bx, by):
return ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5
if ((ax - bx) * (cy - by) == (ay - by) * (cx - bx)) or (dist(ax, ay, bx, by) != dist(bx, by, cx, cy)):
print("No")
else:
print("Yes")
| Title: Arpa and an exam about geometry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle... | ```python
ax, ay, bx, by, cx, cy = [int(i) for i in input().split()]
def dist(ax, ay, bx, by):
return ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5
if ((ax - bx) * (cy - by) == (ay - by) * (cx - bx)) or (dist(ax, ay, bx, by) != dist(bx, by, cx, cy)):
print("No")
else:
print("Yes")
``` | 0 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,686,060,471 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 1,536,000 | n=int(input())
s=list(input())
l=[]
i=0
while(s):
if(n%2==0):
if(i%2!=0):
l.append(s[0])
else:
l.insert(0,s[0])
else:
if(i%2==0):
l.append(s[0])
else:
l.insert(0,s[0])
s.pop(0)
i+=1
l="".join(l)
print(l)
| Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n=int(input())
s=list(input())
l=[]
i=0
while(s):
if(n%2==0):
if(i%2!=0):
l.append(s[0])
else:
l.insert(0,s[0])
else:
if(i%2==0):
l.append(s[0])
else:
l.insert(0,s[0])
s.pop(0)
i+=1
l="".join(l)
print(l)
``` | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,700,038,340 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 102,400 | a=list(map(int,input().split()))
s=input()
cal=s.count('1')*a[0]+s.count('2')*a[1]+s.count('3')*a[2]+s.count('4')*a[3]
print(cal)
| Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
a=list(map(int,input().split()))
s=input()
cal=s.count('1')*a[0]+s.count('2')*a[1]+s.count('3')*a[2]+s.count('4')*a[3]
print(cal)
``` | 3 | |
708 | A | Letters Cyclic Shift | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation",
"strings"
] | null | null | You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is ... | The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters. | Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring. | [
"codeforces\n",
"abacaba\n"
] | [
"bncdenqbdr\n",
"aaacaba\n"
] | String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i*... | 500 | [
{
"input": "codeforces",
"output": "bncdenqbdr"
},
{
"input": "abacaba",
"output": "aaacaba"
},
{
"input": "babbbabaababbaa",
"output": "aabbbabaababbaa"
},
{
"input": "bcbacaabcababaccccaaaabacbbcbbaa",
"output": "abaacaabcababaccccaaaabacbbcbbaa"
},
{
"input": "... | 1,596,184,392 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 26 | 1,000 | 7,065,600 | a,s,iz='',input(),0
if set(s)=={'a'}:a+=s[:-1]+'z'
else:
for i in range(len(s)):
if s[i]=='a' and iz<1:a+=s[i]
elif s[i]=='a' and iz>=1:
a+=s[len(a):]
break
else:a,iz=a+chr(ord(s[i])-1),iz+1
print(a)
| Title: Letters Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each cha... | ```python
a,s,iz='',input(),0
if set(s)=={'a'}:a+=s[:-1]+'z'
else:
for i in range(len(s)):
if s[i]=='a' and iz<1:a+=s[i]
elif s[i]=='a' and iz>=1:
a+=s[len(a):]
break
else:a,iz=a+chr(ord(s[i])-1),iz+1
print(a)
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,692,581,933 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a=input("")
b=len(a)-2
x= a[0]
y=a[len(a)-1]
print(x,b,y,sep='')
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
a=input("")
b=len(a)-2
x= a[0]
y=a[len(a)-1]
print(x,b,y,sep='')
``` | 0 |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,692,883,733 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 13,619,200 | n = int(input())
arr = [int(x) for x in input().split()]
found = [-1 for i in range(n + 1)]
m = int(input())
querries = [int(x) for x in input().split()]
one = 0
for e in querries:
index = found[e]
if index == -1:
index = arr.index(e)
found[e] = index
one += index
print... | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
arr = [int(x) for x in input().split()]
found = [-1 for i in range(n + 1)]
m = int(input())
querries = [int(x) for x in input().split()]
one = 0
for e in querries:
index = found[e]
if index == -1:
index = arr.index(e)
found[e] = index
one += inde... | 0 | |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,652,638,120 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define ll long long
#define eb(n) emplace_back(n)
#define for1(k,a,n) for(auto (k)=a;(k)<(n);(k)++)
#define bd(n) n.begin(),(n).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
using namespace std;
int main()
{
fast
int num,lim,sum=0;
cin>>num>>lim;
int... | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
#include <bits/stdc++.h>
#define ll long long
#define eb(n) emplace_back(n)
#define for1(k,a,n) for(auto (k)=a;(k)<(n);(k)++)
#define bd(n) n.begin(),(n).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
using namespace std;
int main()
{
fast
int num,lim,sum=0;
cin>>num... | -1 |
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.