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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
252 | B | Unsorting Array | PROGRAMMING | 1,800 | [
"brute force",
"sortings"
] | null | null | Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* non-negative space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109. | If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to *n*. | [
"1\n1\n",
"2\n1 2\n",
"4\n1 2 3 4\n",
"3\n1 1 1\n"
] | [
"-1\n",
"-1\n",
"1 2\n",
"-1\n"
] | In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | 1,000 | [
{
"input": "1\n1",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "-1"
},
{
"input": "4\n1 2 3 4",
"output": "1 2"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "3\n1 2 2",
"output": "1 2"
},
{
"input": "5\n1 1 1 1 2",
"output": "2 5"
... | 1,592,829,494 | 3,194 | Python 3 | WRONG_ANSWER | TESTS | 15 | 280 | 8,499,200 | def Sort(a,n):
for i in range(1,n):
if a[i]>a[i-1]:
break
if i==n:
return True
for i in range(1,n):
if a[i]>a[i-1]:
return False
return True
n = int(input())
a = list(map(int,input().split()))
if n==1 or n==2 or (n==3 and a[0]==a[-1]) or a.co... | Title: Unsorting Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the... | ```python
def Sort(a,n):
for i in range(1,n):
if a[i]>a[i-1]:
break
if i==n:
return True
for i in range(1,n):
if a[i]>a[i-1]:
return False
return True
n = int(input())
a = list(map(int,input().split()))
if n==1 or n==2 or (n==3 and a[0]==a[-1... | 0 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,599,122,175 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | a,b=map(int,input().split())
ans=a*b
c=1
for i in range(a):
row=input()
if row.find('S'):
ans-=c
c+=2
print(ans) | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
a,b=map(int,input().split())
ans=a*b
c=1
for i in range(a):
row=input()
if row.find('S'):
ans-=c
c+=2
print(ans)
``` | 0 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,629,256,154 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 154 | 6,758,400 | import math
a=[]
a=list(map(int,input().split()))
ab=a[0]
bc=a[1]
ca=a[2]
c=math.sqrt(ca/(ab/bc))
b=math.sqrt(ab/(ca/bc))
a=math.sqrt(ab/(bc/ca))
print(int(4*(a+b+c)))
| Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
a=[]
a=list(map(int,input().split()))
ab=a[0]
bc=a[1]
ca=a[2]
c=math.sqrt(ca/(ab/bc))
b=math.sqrt(ab/(ca/bc))
a=math.sqrt(ab/(bc/ca))
print(int(4*(a+b+c)))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 0 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,617,236,176 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 93 | 0 | n, m = input().split()
a=set(map(int,input().split()))
b=set(map(int,input().split()))
if b.intersection(a):
print(min(b.intersection(a)))
else:
minimum = min(min(a), min(b))
maximum = max(min(a), min(b))
print(int(str(minimum)+str(maximum)))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty... | ```python
n, m = input().split()
a=set(map(int,input().split()))
b=set(map(int,input().split()))
if b.intersection(a):
print(min(b.intersection(a)))
else:
minimum = min(min(a), min(b))
maximum = max(min(a), min(b))
print(int(str(minimum)+str(maximum)))
``` | 3 | |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,676,039,627 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 778 | 10,444,800 | s = input()
st = []
siz = len(s)
ans = 0
for i in range(siz):
if (s[i] == "("):
st.append("(")
elif s[i] == ")":
if (len(st) != 0):
ans += 1
st.pop()
print(ans * 2)
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
s = input()
st = []
siz = len(s)
ans = 0
for i in range(siz):
if (s[i] == "("):
st.append("(")
elif s[i] == ")":
if (len(st) != 0):
ans += 1
st.pop()
print(ans * 2)
``` | 3.902745 |
888 | C | K-Dominant Character | PROGRAMMING | 1,400 | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* such that there exists at least one *k*-dominant character. | The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000). | Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character. | [
"abacaba\n",
"zzzzz\n",
"abcde\n"
] | [
"2\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "2"
},
{
"input": "zzzzz",
"output": "1"
},
{
"input": "abcde",
"output": "3"
},
{
"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab",
"output": "8"
},
{
"input": "daabcdabbab... | 1,593,062,103 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 202 | 9,216,000 | s=input()
se=set(s)
if len(se)==len(s):
print((len(s)//2)+1)
elif len(se)==1:
print(1)
else:
dif={}
d={}
for index,i in enumerate(s):
if d.get(i,[])!=[]:
if len(d[i])>=2:
dif[i]=max(index-d[i][-1],dif[i])
else:
dif[i] =ind... | Title: K-Dominant Character
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* s... | ```python
s=input()
se=set(s)
if len(se)==len(s):
print((len(s)//2)+1)
elif len(se)==1:
print(1)
else:
dif={}
d={}
for index,i in enumerate(s):
if d.get(i,[])!=[]:
if len(d[i])>=2:
dif[i]=max(index-d[i][-1],dif[i])
else:
d... | 0 | |
917 | D | Stranger Trees | PROGRAMMING | 2,600 | [
"dp",
"math",
"matrices",
"trees"
] | null | null | Will shares a psychic connection with the Upside Down Monster, so everything the monster knows, Will knows. Suddenly, he started drawing, page after page, non-stop. Joyce, his mom, and Chief Hopper put the drawings together, and they realized, it's a labeled tree!
A tree is a connected acyclic graph. Will's tree has *... | The first line of input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the tree.
The next *n*<=-<=1 lines contain the edges of Will's tree. Each line contains two integers *v* and *u* (1<=≤<=*v*,<=*u*<=≤<=*n*, *v*<=≠<=*u*), endpoints of an edge. It is guaranteed that the given graph is a tree. | Print *n* integers in one line. *i*-th integer should be the number of the number of labeled trees with *n* vertices that share exactly *i*<=-<=1 edges with Will's tree, modulo 1000<=000<=007<==<=109<=+<=7. | [
"3\n1 2\n1 3\n",
"4\n1 2\n2 3\n3 4\n",
"4\n1 2\n1 3\n1 4\n"
] | [
"0 2 1 ",
"1 7 7 1 ",
"0 9 6 1 "
] | none | 2,000 | [] | 1,692,700,860 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692700860.4007442")# 1692700860.4007614 | Title: Stranger Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Will shares a psychic connection with the Upside Down Monster, so everything the monster knows, Will knows. Suddenly, he started drawing, page after page, non-stop. Joyce, his mom, and Chief Hopper put the drawings toget... | ```python
print("_RANDOM_GUESS_1692700860.4007442")# 1692700860.4007614
``` | 0 | |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,652,389,526 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | s=[]
for i in range(4):
s.append(input())
for i in range(3):
for j in range(3):
t = [s[i][j],s[i][j+1],s[i+1][j],s[i+1][j+1]]
if t.count('#')!=2:
print('YES')
exit()
print('NO') | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
s=[]
for i in range(4):
s.append(input())
for i in range(3):
for j in range(3):
t = [s[i][j],s[i][j+1],s[i+1][j],s[i+1][j+1]]
if t.count('#')!=2:
print('YES')
exit()
print('NO')
``` | 3 | |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,600,000,824 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 296 | 20,787,200 | import math
data = list(input())
pr = [False]*math.ceil(len(data)//2)
am = int(input())
arr = list(map(int,input().split()))
arr.sort()
prSum = False
for i in range(am):
prSum = not prSum
end = 0
if i < am-1:
end = arr[i+1]
else:
end = len(pr)
for g in range(arr[i]-1,en... | Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
import math
data = list(input())
pr = [False]*math.ceil(len(data)//2)
am = int(input())
arr = list(map(int,input().split()))
arr.sort()
prSum = False
for i in range(am):
prSum = not prSum
end = 0
if i < am-1:
end = arr[i+1]
else:
end = len(pr)
for g in range(a... | 3 | |
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,699,952,949 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 30 | 614,400 | n = int(input())
num = [0]*100005
arr = [int(x) for x in input().split()]
nums = []
for x in arr:
if num[x] == 0:
nums.append(x)
num[x] += 1
nums.sort()
x = [0, num[nums[0]]*nums[0]]
for i in range(1, len(nums)):
y0 = x[1]
y1 = x[int(nums[i-1]+1 != nums[i])] + nums[i]*num[nums[i]]
... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n = int(input())
num = [0]*100005
arr = [int(x) for x in input().split()]
nums = []
for x in arr:
if num[x] == 0:
nums.append(x)
num[x] += 1
nums.sort()
x = [0, num[nums[0]]*nums[0]]
for i in range(1, len(nums)):
y0 = x[1]
y1 = x[int(nums[i-1]+1 != nums[i])] + nums[i]*num[n... | 0 | |
988 | B | Substrings Sort | PROGRAMMING | 1,100 | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su... | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | 0 | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "Y... | 1,698,147,605 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 62 | 0 | n = int(input())
strings = [input() for r in range(n)]
strings.sort(key=len)
if all(strings[i] in strings[i+1] for i in range(n-1)):
print("YES")
for s in strings:
print(s)
else:
print("NO") | Title: Substrings Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String ... | ```python
n = int(input())
strings = [input() for r in range(n)]
strings.sort(key=len)
if all(strings[i] in strings[i+1] for i in range(n-1)):
print("YES")
for s in strings:
print(s)
else:
print("NO")
``` | 3 | |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,617,992,795 | 395 | PyPy 3 | OK | TESTS | 71 | 2,043 | 33,177,600 | n = int(input())
fx, fy = {}, {}
f = {}
for i in range(n):
x, y = map(int, input().split())
fx[x] = fx.get(x, 0) + 1
fy[y] = fy.get(y, 0) + 1
pt = (x, y)
f[pt] = f.get(pt, 0) + 1
res = 0
for k, v in fx.items():
res += v * (v - 1) // 2
for k, v in fy.items():
res += v * (v - 1) // 2
for ... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
n = int(input())
fx, fy = {}, {}
f = {}
for i in range(n):
x, y = map(int, input().split())
fx[x] = fx.get(x, 0) + 1
fy[y] = fy.get(y, 0) + 1
pt = (x, y)
f[pt] = f.get(pt, 0) + 1
res = 0
for k, v in fx.items():
res += v * (v - 1) // 2
for k, v in fy.items():
res += v * (v - 1) ... | 3 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,663,017,496 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 60 | 0 | d=dict(); l=list(); n=int(input())
a=list(map(int,input().split())) ; M=max(a)
fa= [0]*(M+1)
for x in range(n) : fa[a[x]]+=1
print(len(set(a)))
for x in range(M+1) :
if fa[x] > 1 :
print(x,a.index(x,a.index(x)+1)-a.index(x))
elif fa[x] == 1 : print(x,0)
| Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
d=dict(); l=list(); n=int(input())
a=list(map(int,input().split())) ; M=max(a)
fa= [0]*(M+1)
for x in range(n) : fa[a[x]]+=1
print(len(set(a)))
for x in range(M+1) :
if fa[x] > 1 :
print(x,a.index(x,a.index(x)+1)-a.index(x))
elif fa[x] == 1 : print(x,0)
``` | 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,606,200,246 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 186 | 0 | data1 = input()
data2 = input()
result = "YES"
for i in range(len(data1)):
if data1[i] != data2[len(data1)-i-1]:
result = "NO"
print(result)
| 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
data1 = input()
data2 = input()
result = "YES"
for i in range(len(data1)):
if data1[i] != data2[len(data1)-i-1]:
result = "NO"
print(result)
``` | -1 |
630 | H | Benches | PROGRAMMING | 1,400 | [
"combinatorics",
"math"
] | null | null | The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possib... | The only line of the input contains one integer *n* (5<=≤<=*n*<=≤<=100) — the number of east to west paths and north to south paths. | Output one integer — the number of ways to place the benches. | [
"5\n"
] | [
"120"
] | none | 0 | [
{
"input": "5",
"output": "120"
},
{
"input": "6",
"output": "4320"
},
{
"input": "7",
"output": "52920"
},
{
"input": "15",
"output": "1082161080"
},
{
"input": "17",
"output": "4594961280"
},
{
"input": "72",
"output": "23491596420472320"
},
... | 1,694,990,580 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | from math import comb
n = int(input())
possibilidades = comb(n, 5)
for i in range(5, 0, -1):
possibilidades *= i
print(possibilidades) | Title: Benches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections.
The city funded purchase of five benches. To make... | ```python
from math import comb
n = int(input())
possibilidades = comb(n, 5)
for i in range(5, 0, -1):
possibilidades *= i
print(possibilidades)
``` | 0 | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,627,570,217 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 6,758,400 | a = int(input())
b = int(input())
d = abs(a - b)
n = d // 2
if d % 2 == 0:
solution = n * ((n+1) / 2) * 2
else:
solution = n * ((n+1) / 2) * 2 + n + 1
print(int(solution)) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
a = int(input())
b = int(input())
d = abs(a - b)
n = d // 2
if d % 2 == 0:
solution = n * ((n+1) / 2) * 2
else:
solution = n * ((n+1) / 2) * 2 + n + 1
print(int(solution))
``` | 3 | |
722 | A | Broken Clock | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken ... | The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes. | The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them. | [
"24\n17:30\n",
"12\n17:30\n",
"24\n99:99\n"
] | [
"17:30\n",
"07:30\n",
"09:09\n"
] | none | 500 | [
{
"input": "24\n17:30",
"output": "17:30"
},
{
"input": "12\n17:30",
"output": "07:30"
},
{
"input": "24\n99:99",
"output": "09:09"
},
{
"input": "12\n05:54",
"output": "05:54"
},
{
"input": "12\n00:05",
"output": "01:05"
},
{
"input": "24\n23:80",
... | 1,588,694,051 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 155 | 0 | def correct_hour(is24, a, b):
if is24:
if a > 2:
a = 0
elif a == 2 and b > 3:
b = 0
else:
if a == b == 0:
b = 1
elif a > 1:
if b == 0:
a = 1
else:
a = 0
elif a == 1 and b > 2:
... | Title: Broken Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes cha... | ```python
def correct_hour(is24, a, b):
if is24:
if a > 2:
a = 0
elif a == 2 and b > 3:
b = 0
else:
if a == b == 0:
b = 1
elif a > 1:
if b == 0:
a = 1
else:
a = 0
elif a == 1 and b... | 0 | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,601,235,158 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 108 | 0 | a = int(input())
b = int(input())
d = int(abs(b-a))
S = 0
if d % 2 == 0:
for i in range(int(d/2)+1):
S = S+i
print(2*S)
else:
for i in range(int((d-1)/2)+1):
S = S+i
print(2*S+int((d-1)/2)+1) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
a = int(input())
b = int(input())
d = int(abs(b-a))
S = 0
if d % 2 == 0:
for i in range(int(d/2)+1):
S = S+i
print(2*S)
else:
for i in range(int((d-1)/2)+1):
S = S+i
print(2*S+int((d-1)/2)+1)
``` | 3 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,684,330,972 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | n,k,l,c,d,p,nl,np = list(map(int,input().split()))
mc = c*d
mp = p/n
ml = k*l/n
ll = ml//nl
cc = mc//n
pp = mp//np
print(int(min(ll,cc,pp))) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n,k,l,c,d,p,nl,np = list(map(int,input().split()))
mc = c*d
mp = p/n
ml = k*l/n
ll = ml//nl
cc = mc//n
pp = mp//np
print(int(min(ll,cc,pp)))
``` | 3 | |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,538,869,234 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 0 | word = input()
aux = word
n = len(word)
res = 1
while True:
word2 = aux[n-1] + aux[0:n-1]
if word2 != word:
res+=1
aux=word2
else:
break
print(str(res))
| Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
word = input()
aux = word
n = len(word)
res = 1
while True:
word2 = aux[n-1] + aux[0:n-1]
if word2 != word:
res+=1
aux=word2
else:
break
print(str(res))
``` | 3 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,616,435,855 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 307,200 | def gcd(x, y):
if x > y:
small = y
else:
small = x
for i in range(1, small+1):
if((x % i == 0) and (y % i == 0)):
gcd = i
return gcd
n,s=int(input()),0
for i in range(2,n):
k=n
while k!=0:
s+=k%i
k//=i
p=gcd(s,n-... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
def gcd(x, y):
if x > y:
small = y
else:
small = x
for i in range(1, small+1):
if((x % i == 0) and (y % i == 0)):
gcd = i
return gcd
n,s=int(input()),0
for i in range(2,n):
k=n
while k!=0:
s+=k%i
k//=i
... | 0 |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,599,278,514 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 140 | 0 | n = input()
vogals = ["a","e","i","o","u"]
quant=0
for letter in n:
if(letter.isdigit()):
if(int(letter)%2!=0):
quant+=1
elif(letter in vogals):
quant+=1
print(quant)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
n = input()
vogals = ["a","e","i","o","u"]
quant=0
for letter in n:
if(letter.isdigit()):
if(int(letter)%2!=0):
quant+=1
elif(letter in vogals):
quant+=1
print(quant)
``` | 3 | |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,644,441,678 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | nums = [0,4,7,10,13,24]
bidders = 6
nums.sort()
second_bidder = len(nums) - 2
print(nums[second_bidder], len(nums))
| Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
nums = [0,4,7,10,13,24]
bidders = 6
nums.sort()
second_bidder = len(nums) - 2
print(nums[second_bidder], len(nums))
``` | 0 | |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,699,961,985 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 30 | 0 | def read_line() -> map:
return map(int, input().split())
# 6
# 1 2
# 1 3
# 2 5
# 2 6
# 3 4
n = int(input())
roads = [(go_from, go_to) for go_from, go_to in (read_line() for _ in range(n-1))]
roads.sort(key=lambda x: (x[0], x[1]))
prev_ways = {}
cur_ways = {1: 0}
for go_from, go_to in roads:
if cur_ways.get... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
def read_line() -> map:
return map(int, input().split())
# 6
# 1 2
# 1 3
# 2 5
# 2 6
# 3 4
n = int(input())
roads = [(go_from, go_to) for go_from, go_to in (read_line() for _ in range(n-1))]
roads.sort(key=lambda x: (x[0], x[1]))
prev_ways = {}
cur_ways = {1: 0}
for go_from, go_to in roads:
if cu... | -1 | |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,635,861,256 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,505,600 | n = 1
while n != 0:
n -= 1
x,y = map(int,input().split())
s = list (input())
l=[]
for i in s:
l.append(ord(i)-96)
m= pref(pos)
for i in range(q):
f,g = map(int,input().split())
print(m[g]-m[f-1])
| Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
n = 1
while n != 0:
n -= 1
x,y = map(int,input().split())
s = list (input())
l=[]
for i in s:
l.append(ord(i)-96)
m= pref(pos)
for i in range(q):
f,g = map(int,input().split())
print(m[g]-m[f-1])
``` | -1 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,665,508,743 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | n,m=map(int,input().split())
l=[]
for i in range(n):
s=input()
s=list(s)
for j in range(m):
if s[j]=='.':
if (i+j)&1:s[j]='W'
else: s[j]='B'
l.append(s)
for c in l: print("".join(c)) | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
n,m=map(int,input().split())
l=[]
for i in range(n):
s=input()
s=list(s)
for j in range(m):
if s[j]=='.':
if (i+j)&1:s[j]='W'
else: s[j]='B'
l.append(s)
for c in l: print("".join(c))
``` | 3 | |
896 | A | Nephren gives a riddle | PROGRAMMING | 1,700 | [
"binary search",
"dfs and similar"
] | null | null |
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, *f*0... ∞.
*f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? ... | The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions.
Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018). | One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query. | [
"3\n1 1\n1 2\n1 111111111111\n",
"5\n0 69\n1 194\n1 139\n0 47\n1 66\n",
"10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n"
] | [
"Wh.",
"abdef",
"Areyoubusy"
] | For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend. | 500 | [
{
"input": "3\n1 1\n1 2\n1 111111111111",
"output": "Wh."
},
{
"input": "5\n0 69\n1 194\n1 139\n0 47\n1 66",
"output": "abdef"
},
{
"input": "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474",
"output": "Areyoubusy"
},
{
"input": "1\n0 1",
"outpu... | 1,659,974,467 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 46 | 1,331,200 | import sys
readline=sys.stdin.readline
le=[75]
while le[-1]<=10**18:
le.append(le[-1]*2+68)
le+=[10**19]*(10**5-len(le))
def main(N,K):
if N==0:
retu='What are you doing at the end of the world? Are you busy? Will you save us?'[K]
elif K<34:
retu='What are you doing while sending... | Title: Nephren gives a riddle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, *f*0... ∞.
*f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to ... | ```python
import sys
readline=sys.stdin.readline
le=[75]
while le[-1]<=10**18:
le.append(le[-1]*2+68)
le+=[10**19]*(10**5-len(le))
def main(N,K):
if N==0:
retu='What are you doing at the end of the world? Are you busy? Will you save us?'[K]
elif K<34:
retu='What are you doing whi... | -1 | |
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs som... | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaran... | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1... | 1,615,575,047 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 278 | 6,963,200 | n, s, t = input().split(" ")
n = int(n)
s = int(s)
t = int(t)
seq = input().split(" ")
arr = []
for i in seq:
arr.append(int(i))
isPossible = False
for i in range(len(arr)):
if s == t:
isPossible = True
print(i)
break
s = arr[s-1]
if isPossible is not True:
print(-1)
... | Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ... | ```python
n, s, t = input().split(" ")
n = int(n)
s = int(s)
t = int(t)
seq = input().split(" ")
arr = []
for i in seq:
arr.append(int(i))
isPossible = False
for i in range(len(arr)):
if s == t:
isPossible = True
print(i)
break
s = arr[s-1]
if isPossible is not True:
print(... | 3 | |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,688,634,419 | 2,147,483,647 | Python 3 | OK | TESTS | 5 | 30 | 0 | n = int(input())
print(25)
# Thu Jul 06 2023 12:06:58 GMT+0300 (Moscow Standard Time)
| Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
n = int(input())
print(25)
# Thu Jul 06 2023 12:06:58 GMT+0300 (Moscow Standard Time)
``` | 3 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,686,245,694 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 46 | 2,764,800 | q = list(map(int, input().split()))
m = max(q)
n = min(q)
mx = q.index(m)
mn = q.index(n)
del q[mx]
del q[mn]
print ((m - q[0]) + (q[0] - n)) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
q = list(map(int, input().split()))
m = max(q)
n = min(q)
mx = q.index(m)
mn = q.index(n)
del q[mx]
del q[mn]
print ((m - q[0]) + (q[0] - n))
``` | -1 | |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,621,137,935 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 124 | 0 | n=int(input())
A=list(map(int,input().split()))
m=int(input())
B=list(map(int,input().split()))
r=[]
cnt=0
for i in range(m):
for j in range(n):
if B[i]%A[j]==0:
r.append(B[i]/A[j])
m=(int(max(r)))
for w in r:
if w==m:
cnt+=1
print(cnt) | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
n=int(input())
A=list(map(int,input().split()))
m=int(input())
B=list(map(int,input().split()))
r=[]
cnt=0
for i in range(m):
for j in range(n):
if B[i]%A[j]==0:
r.append(B[i]/A[j])
m=(int(max(r)))
for w in r:
if w==m:
cnt+=1
print(cnt)
``` | 3 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,670,925,488 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 61 | 0 | n=int(input())
z=list(map(int,input().split()))
z=set(z)
c=0
for i in z:
if i!=0:
c=c+1
print(c) | Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n=int(input())
z=list(map(int,input().split()))
z=set(z)
c=0
for i in z:
if i!=0:
c=c+1
print(c)
``` | 3 | |
769 | D | k-Interesting Pairs Of Integers | PROGRAMMING | 1,700 | [
"*special",
"bitmasks",
"brute force",
"meet-in-the-middle"
] | null | null | Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=104), which Vasya has. | Print the number of pairs (*i*, *j*) so that *i*<=<<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. | [
"4 1\n0 3 2 1\n",
"6 0\n200 100 100 100 200 200\n"
] | [
"4\n",
"6\n"
] | In the first test there are 4 k-interesting pairs:
- (1, 3), - (1, 4), - (2, 3), - (2, 4).
In the second test *k* = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs:
- (1, 5), - (1, 6), - (2, 3), - (2, 4), - (3, 4), ... | 2,000 | [
{
"input": "4 1\n0 3 2 1",
"output": "4"
},
{
"input": "6 0\n200 100 100 100 200 200",
"output": "6"
},
{
"input": "2 0\n1 1",
"output": "1"
},
{
"input": "2 0\n0 0",
"output": "1"
},
{
"input": "2 0\n10000 10000",
"output": "1"
},
{
"input": "2 0\n0 1... | 1,488,713,138 | 84,338 | Python 3 | RUNTIME_ERROR | PRETESTS | 4 | 62 | 4,812,800 | def new_nuber(x, changes):
for bit in changes:
x = x ^ (1 << bit)
return x
def process(x, depth, changes):
last_bit = -1 if depth == 0 else changes[depth - 1]
if last_bit < 13:
if depth < k:
for bit in range(last_bit + 1, 13):
changes.append(bit)
... | Title: k-Interesting Pairs Of Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, ... | ```python
def new_nuber(x, changes):
for bit in changes:
x = x ^ (1 << bit)
return x
def process(x, depth, changes):
last_bit = -1 if depth == 0 else changes[depth - 1]
if last_bit < 13:
if depth < k:
for bit in range(last_bit + 1, 13):
changes.append(bit)
... | -1 | |
74 | B | Train | PROGRAMMING | 1,500 | [
"dp",
"games",
"greedy"
] | B. Train | 2 | 256 | A stowaway and a controller play the following game.
The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or ... | The first line contains three integers *n*, *m* and *k*. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2<=≤<=*n*<=≤<=50, 1<=≤<=*m*,<=*k*<=≤<=*n*, *m*<=≠<=*k*).
The second line contains the direction in which a controller moves. "to head" means ... | If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. | [
"5 3 2\nto head\n0001001\n",
"3 2 1\nto tail\n0001\n"
] | [
"Stowaway",
"Controller 2"
] | none | 1,000 | [
{
"input": "5 3 2\nto head\n0001001",
"output": "Stowaway"
},
{
"input": "3 2 1\nto tail\n0001",
"output": "Controller 2"
},
{
"input": "4 2 1\nto tail\n1000001",
"output": "Controller 6"
},
{
"input": "2 1 2\nto head\n111111",
"output": "Stowaway"
},
{
"input": "... | 1,644,063,448 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 310 | 4,608,000 | import math
import sys
import queue
from heapq import heappop, heappush
import random
def solve():
n, m, k = map(int, input().split())
dir = -1 if str(input()) == "to head" else 1
s = str(input())
f = [0 for i in range(n)]
# 0 - moving
# 1 - stay
pos = -1
for i i... | Title: Train
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A stowaway and a controller play the following game.
The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some tw... | ```python
import math
import sys
import queue
from heapq import heappop, heappush
import random
def solve():
n, m, k = map(int, input().split())
dir = -1 if str(input()) == "to head" else 1
s = str(input())
f = [0 for i in range(n)]
# 0 - moving
# 1 - stay
pos = -1
... | 0 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,571,394,035 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 18 15:44:11 2019
@author: nandu
"""
n = int(input())
x = 0
y = 0
z = 0
for i in range(n):
a, b, c = map(int,input().split())
x += a
y += b
z += c
if (x==0) and (y==0) and (z==0):
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 18 15:44:11 2019
@author: nandu
"""
n = int(input())
x = 0
y = 0
z = 0
for i in range(n):
a, b, c = map(int,input().split())
x += a
y += b
z += c
if (x==0) and (y==0) and (z==0):
print('YES')
else:
print('NO')
``` | 3.9455 |
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For exam... | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts ... | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1... | 1,636,087,876 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 124 | 28,672,000 | import sys
def solve():
N = len(B)
count0 = [0] * (N + 1)
count1 = [0] * (N + 1)
for i in range(N):
count0[i + 1] = count0[i]
count1[i + 1] = count1[i]
if B[i] == 1:
count1[i + 1] += 1
else:
count0[i + 1] += 1
ans = 0
M = l... | Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is de... | ```python
import sys
def solve():
N = len(B)
count0 = [0] * (N + 1)
count1 = [0] * (N + 1)
for i in range(N):
count0[i + 1] = count0[i]
count1[i + 1] = count1[i]
if B[i] == 1:
count1[i + 1] += 1
else:
count0[i + 1] += 1
ans = 0
... | 3 | |
899 | B | Months and Years | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. | If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large). | [
"4\n31 31 30 31\n",
"2\n30 30\n",
"5\n29 31 30 31 30\n",
"3\n31 28 30\n",
"3\n31 31 28\n"
] | [
"Yes\n\n",
"No\n\n",
"Yes\n\n",
"No\n\n",
"Yes\n\n"
] | In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of... | 1,000 | [
{
"input": "4\n31 31 30 31",
"output": "Yes"
},
{
"input": "2\n30 30",
"output": "No"
},
{
"input": "5\n29 31 30 31 30",
"output": "Yes"
},
{
"input": "3\n31 28 30",
"output": "No"
},
{
"input": "3\n31 31 28",
"output": "Yes"
},
{
"input": "24\n29 28 3... | 1,513,687,213 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 77 | 6,246,400 | n, w, m = int(input()), 'No', [31,28,31,30,31,30,31,31,30,31,30,31]*3
g = list(map(int,input().split()))
x = [28 if i == 29 else i for i in g]
for j in range(len(m)):
if m[j:j+n] == x:
w = 'Yes'
break
if g.count(29) == 2:
print('No')
else:
print(w)
| Title: Months and Years
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, ... | ```python
n, w, m = int(input()), 'No', [31,28,31,30,31,30,31,31,30,31,30,31]*3
g = list(map(int,input().split()))
x = [28 if i == 29 else i for i in g]
for j in range(len(m)):
if m[j:j+n] == x:
w = 'Yes'
break
if g.count(29) == 2:
print('No')
else:
print(w)
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,630,302,012 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 154 | 6,758,400 | l=input().strip().split(" ")
a=int(l[0])*int(l[1])//2
print(a) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
l=input().strip().split(" ")
a=int(l[0])*int(l[1])//2
print(a)
``` | 3.948911 |
888 | C | K-Dominant Character | PROGRAMMING | 1,400 | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* such that there exists at least one *k*-dominant character. | The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000). | Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character. | [
"abacaba\n",
"zzzzz\n",
"abcde\n"
] | [
"2\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "2"
},
{
"input": "zzzzz",
"output": "1"
},
{
"input": "abcde",
"output": "3"
},
{
"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab",
"output": "8"
},
{
"input": "daabcdabbab... | 1,512,936,853 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 124 | 29,593,600 | # -*- coding: utf-8 -*-
"""
Created on Mon Dec 11 01:57:07 2017
@author: Sand Boa
"""
s=float('inf')
a=input()
for i in list(set(a)):
leng=max(list(map(len,a.split(i))))
if leng<s:
s=leng
print(s+1)
| Title: K-Dominant Character
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* s... | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 11 01:57:07 2017
@author: Sand Boa
"""
s=float('inf')
a=input()
for i in list(set(a)):
leng=max(list(map(len,a.split(i))))
if leng<s:
s=leng
print(s+1)
``` | 3 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,633,702,202 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 216 | 20,172,800 | from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
count=Counter(a)
fc=((count[5])//9)*9
zc=count[0]
if zc==fc==0:
print(-1)
elif fc==0:
print(0)
else:
ans='5'*fc + '0'*zc
print(ans) | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
count=Counter(a)
fc=((count[5])//9)*9
zc=count[0]
if zc==fc==0:
print(-1)
elif fc==0:
print(0)
else:
ans='5'*fc + '0'*zc
print(ans)
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,637,490,525 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def sequence(a,b,m,n):
if m==0:
return True
elif n==0:
return False
if a[m-1]=b[n-1]:
return sequence(a,b,m-1,n-1)
return sequence(a,b,m,n-1)
string=input()
a="hello"
la=5
lb=len(string)
if sequence(a,string,la,lb):
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
def sequence(a,b,m,n):
if m==0:
return True
elif n==0:
return False
if a[m-1]=b[n-1]:
return sequence(a,b,m-1,n-1)
return sequence(a,b,m,n-1)
string=input()
a="hello"
la=5
lb=len(string)
if sequence(a,string,la,lb):
print("YES")
else:
print("NO")
... | -1 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,563,803,607 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 312 | 1,126,400 | from fractions import Fraction
y,w=map(int,input().split())
if max(y,w)==0:
print(Fraction(6-max(y,w),6))
exit(0)
print(Fraction(6-max(y,w)+1,6))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
from fractions import Fraction
y,w=map(int,input().split())
if max(y,w)==0:
print(Fraction(6-max(y,w),6))
exit(0)
print(Fraction(6-max(y,w)+1,6))
``` | 0 |
424 | A | Squats | PROGRAMMING | 900 | [
"implementation"
] | null | null | Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ethe... | The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. | In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. | [
"4\nxxXx\n",
"2\nXX\n",
"6\nxXXxXx\n"
] | [
"1\nXxXx\n",
"1\nxX\n",
"0\nxXXxXx\n"
] | none | 500 | [
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "2\nXX",
"output": "1\nxX"
},
{
"input": "6\nxXXxXx",
"output": "0\nxXXxXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "22\nXXxXXxxXxXxXXXX... | 1,698,154,885 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | n=int(input())
m=input()
col_minets=0
a=''
s=len(m)
k=m.count('X')
if k<s//2:
b=s//2-k
if b<0:
b*=-1
i=0
while b>0:
if m[i]=='x':
col_minets+=1
b-=1
a+='X'
else:
a+='x'
i+=1
a+=m[i:]
pri... | Title: Squats
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to ... | ```python
n=int(input())
m=input()
col_minets=0
a=''
s=len(m)
k=m.count('X')
if k<s//2:
b=s//2-k
if b<0:
b*=-1
i=0
while b>0:
if m[i]=='x':
col_minets+=1
b-=1
a+='X'
else:
a+='x'
i+=1
a+=m[i:... | 0 | |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,558,542,061 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | n,k = map(int,input().split(" "))
a=[]
for i in range(1,n):
if n%i == 0:
a.append(i)
if len(a)<k:
print(-1)
else:
print(a[k-1]) | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
n,k = map(int,input().split(" "))
a=[]
for i in range(1,n):
if n%i == 0:
a.append(i)
if len(a)<k:
print(-1)
else:
print(a[k-1])
``` | 0 | |
784 | G | BF Calculator | PROGRAMMING | 2,000 | [
"*special"
] | null | null | In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, whe... | The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (res... | Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps. | [
"2+3\n",
"9-7\n"
] | [
"++>\n+++>\n<[<+>-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n",
"+++++++++>\n+++++++>\n<[<->-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n"
] | You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs. | 0 | [
{
"input": "2+3",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "9-7",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "1+1+1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "... | 1,585,158,398 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 217 | 2,150,400 | print("+"*ord(str(eval(input()))) + ".") | Title: BF Calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of intege... | ```python
print("+"*ord(str(eval(input()))) + ".")
``` | -1 | |
884 | C | Bertown Subway | PROGRAMMING | 1,500 | [
"dfs and similar",
"greedy",
"math"
] | null | null | The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown Transport Law:
1. For each station *i* there exists exactly one train that goes from this station... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100000) — the number of stations.
The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the current structure of the subway. All these numbers are distinct. | Print one number — the maximum possible value of convenience. | [
"3\n2 1 3\n",
"5\n1 5 4 3 2\n"
] | [
"9\n",
"17\n"
] | In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3).
In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<... | 0 | [
{
"input": "3\n2 1 3",
"output": "9"
},
{
"input": "5\n1 5 4 3 2",
"output": "17"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "4"
},
{
"input": "2\n2 1",
"output": "4"
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 ... | 1,509,448,949 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 265 | 15,052,800 |
bz=[0 for i in range(1000000)]
to=[0 for i in range(1000000)]
n=0
n=int(input())
i=1
for x in (input().split()):
to[i]=int(x)
i+=1
all_num=0
mx1=0
mx2=0
for i in range(1,n+1):
if (bz[i]==0):
x=i
num=0;
while (bz[x]==0):
num+=1
bz[x]=1
x=to[x]
all_num+=num**2
if (mx1<=num):
mx1,mx2=num,mx1
el... | Title: Bertown Subway
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown... | ```python
bz=[0 for i in range(1000000)]
to=[0 for i in range(1000000)]
n=0
n=int(input())
i=1
for x in (input().split()):
to[i]=int(x)
i+=1
all_num=0
mx1=0
mx2=0
for i in range(1,n+1):
if (bz[i]==0):
x=i
num=0;
while (bz[x]==0):
num+=1
bz[x]=1
x=to[x]
all_num+=num**2
if (mx1<=num):
mx1,mx2=nu... | 3 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,627,076,003 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
from sys import stdin
a = raw_input()
q_1 = list(map(int,sys.stdin.readline().strip().split(' ')))
q_2 = sorted(q_1)
b = int(raw_input())
for i in range(b):
l = list(map(int,sys.stdin.readline().strip().split(' '))
sys.stdout.write(l[0] == 1 ? sum(q_1[ l[1]-1 : l[2] ] ) : sum(q_2[ l[1]-1 : ... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
import sys
from sys import stdin
a = raw_input()
q_1 = list(map(int,sys.stdin.readline().strip().split(' ')))
q_2 = sorted(q_1)
b = int(raw_input())
for i in range(b):
l = list(map(int,sys.stdin.readline().strip().split(' '))
sys.stdout.write(l[0] == 1 ? sum(q_1[ l[1]-1 : l[2] ] ) : sum(q_2[... | -1 | |
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example ... | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
}... | 1,564,426,822 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 124 | 0 | a,b,c=[int(i) for i in input().split(" ")]
for i in range(b):
d,a=divmod(10*a,b)
if d==c:
print(i+1)
exit()
print("-1") | Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, ... | ```python
a,b,c=[int(i) for i in input().split(" ")]
for i in range(b):
d,a=divmod(10*a,b)
if d==c:
print(i+1)
exit()
print("-1")
``` | 3 | |
301 | A | Yaroslav and Sequence | PROGRAMMING | 1,800 | [
"constructive algorithms"
] | null | null | Yaroslav has an array, consisting of (2·*n*<=-<=1) integers. In a single operation Yaroslav can change the sign of exactly *n* elements in the array. In other words, in one operation Yaroslav can select exactly *n* array elements, and multiply each of them by -1.
Yaroslav is now wondering: what maximum sum of array el... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains (2·*n*<=-<=1) integers — the array elements. The array elements do not exceed 1000 in their absolute value. | In a single line print the answer to the problem — the maximum sum that Yaroslav can get. | [
"2\n50 50 50\n",
"2\n-1 -100 -1\n"
] | [
"150\n",
"100\n"
] | In the first sample you do not need to change anything. The sum of elements equals 150.
In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100. | 500 | [
{
"input": "2\n50 50 50",
"output": "150"
},
{
"input": "2\n-1 -100 -1",
"output": "100"
},
{
"input": "3\n-959 -542 -669 -513 160",
"output": "2843"
},
{
"input": "4\n717 473 344 -51 -548 703 -869",
"output": "3603"
},
{
"input": "5\n270 -181 957 -509 -6 937 -175... | 1,568,312,794 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | n = int(input())
lst = [int(x) for x in input().split()]
x = len([elem for elem in lst if elem < 0])
values = sorted([abs(elem) for elem in lst])
result = sum(values)
if n % 2 == 0 and x % 2 == 1:
result = -2 * values[0]
print(result)
| Title: Yaroslav and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array, consisting of (2·*n*<=-<=1) integers. In a single operation Yaroslav can change the sign of exactly *n* elements in the array. In other words, in one operation Yaroslav can select exactly *n... | ```python
n = int(input())
lst = [int(x) for x in input().split()]
x = len([elem for elem in lst if elem < 0])
values = sorted([abs(elem) for elem in lst])
result = sum(values)
if n % 2 == 0 and x % 2 == 1:
result = -2 * values[0]
print(result)
``` | 0 | |
279 | C | Ladder | PROGRAMMING | 1,700 | [
"dp",
"implementation",
"two pointers"
] | null | null | You've got an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Also, you've got *m* queries, the *i*-th query is described by two integers *l**i*,<=*r**i*. Numbers *l**i*,<=*r**i* define a subsegment of the original array, that is, the sequence of numbers *a**l**i*,<=*a**l**i*<=+<=1,<=*a**l**i*<=+<=2,<=...... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of array elements and the number of queries. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where number *a**i* stands for the *i*-th array element.
The following *m* lines cont... | Print *m* lines, in the *i*-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the *i*-th query is the ladder, or word "No" (without the quotes) otherwise. | [
"8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8\n"
] | [
"Yes\nYes\nNo\nYes\nNo\nYes\n"
] | none | 1,500 | [
{
"input": "8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8",
"output": "Yes\nYes\nNo\nYes\nNo\nYes"
},
{
"input": "1 1\n6\n1 1",
"output": "Yes"
},
{
"input": "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2",
"output": "Yes\nYes\nYes\nYes\nYes"
},
{
"input": "10 10\n4 7 2 6 4 8 1 2 1 ... | 1,673,551,141 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 11,366,400 | n, q = list(map(int, input().split()))
arr = list(map(int, input().split()))
dp1 = [0] * n
dp2 = [0] * n
i = 0
while i < n:
c = i
while c + 1 < n and arr[c] <= arr[c + 1]:
c+=1
for j in range(i,c):
dp1[j] = c - i
if c == i: i+=1
else:i = c
i = 0
while i < n:
c = i
... | Title: Ladder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Also, you've got *m* queries, the *i*-th query is described by two integers *l**i*,<=*r**i*. Numbers *l**i*,<=*r**i* define a subsegment of the original... | ```python
n, q = list(map(int, input().split()))
arr = list(map(int, input().split()))
dp1 = [0] * n
dp2 = [0] * n
i = 0
while i < n:
c = i
while c + 1 < n and arr[c] <= arr[c + 1]:
c+=1
for j in range(i,c):
dp1[j] = c - i
if c == i: i+=1
else:i = c
i = 0
while i < n:
... | 0 | |
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ... | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "... | 1,552,546,948 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 280 | 0 | n = input()
x = n.replace('/', '')
if len(x) == 0:
print('/')
else:
if n[0] == '/' and n[-1] == '/':
n = n.replace('/', ' ')
n = n.split()
n.insert(0, '')
elif n[0] == '/' and n[-1] != '/':
n = n.replace('/', ' ')
n = n.split()
n.insert(0, '')
... | Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n... | ```python
n = input()
x = n.replace('/', '')
if len(x) == 0:
print('/')
else:
if n[0] == '/' and n[-1] == '/':
n = n.replace('/', ' ')
n = n.split()
n.insert(0, '')
elif n[0] == '/' and n[-1] != '/':
n = n.replace('/', ' ')
n = n.split()
n.insert(0... | 3.93 |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,691,312,086 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 405 | 28,057,600 | # /**
# * author: brownfox2k6
# * created: 05/08/2023 21:49:54 Hanoi, Vietnam
# **/
n = int(input())
child = [[] for _ in range(n+1)]
for _ in range(n-1):
u, v = map(int, input().split())
child[u].append(v)
child[v].append(u)
vis = [False] * (n+1)
vis[1] = True
ans = 0
st = [(1, ... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
# /**
# * author: brownfox2k6
# * created: 05/08/2023 21:49:54 Hanoi, Vietnam
# **/
n = int(input())
child = [[] for _ in range(n+1)]
for _ in range(n-1):
u, v = map(int, input().split())
child[u].append(v)
child[v].append(u)
vis = [False] * (n+1)
vis[1] = True
ans = 0
... | 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,622,654,595 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 312 | 0 | n, m = map(int, input().split())
ara = list(map(int, input().split(" ")))
'''
def merge_sort(lo, hi):
if (lo == hi):
return;
mid = lo + (hi - lo)//2
merge_sort(lo, mid)
merge_sort(mid+1, hi)
temp = [-1 for i in range(hi-lo+1)]
i = lo
j = mid+1
k = 0
... | 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 = map(int, input().split())
ara = list(map(int, input().split(" ")))
'''
def merge_sort(lo, hi):
if (lo == hi):
return;
mid = lo + (hi - lo)//2
merge_sort(lo, mid)
merge_sort(mid+1, hi)
temp = [-1 for i in range(hi-lo+1)]
i = lo
j = mid+1
... | 3.922 |
0 | none | none | none | 0 | [
"none"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. Th... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin p... | 0 | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"o... | 1,524,577,070 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 389 | 7,475,200 | n = int(input())
#print(n)
yo = set()
ans = 0
flag = 0
for i in range(26):
yo.add(chr(ord('a')+i))
for i in range(n):
s = input().split()
if i == n - 1 :
continue
if s[0] == '!':
bro = set()
for j in s[1]:
bro.add(j)
for j in range(26):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter... | ```python
n = int(input())
#print(n)
yo = set()
ans = 0
flag = 0
for i in range(26):
yo.add(chr(ord('a')+i))
for i in range(n):
s = input().split()
if i == n - 1 :
continue
if s[0] == '!':
bro = set()
for j in s[1]:
bro.add(j)
for j in range(26)... | 3 | |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooo... | 1,564,856,066 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 109 | 307,200 | n=int(input())
a=0
b=1
aa=[]
aa.append(a)
aa.append(b)
for i in range(3,n+1):
c=a+b
aa.append(c)
a=b
b=c
s=""
for i in range(n):
if((i+1) in aa):
s+="O"
else:
s+="o"
print(s) | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
n=int(input())
a=0
b=1
aa=[]
aa.append(a)
aa.append(b)
for i in range(3,n+1):
c=a+b
aa.append(c)
a=b
b=c
s=""
for i in range(n):
if((i+1) in aa):
s+="O"
else:
s+="o"
print(s)
``` | 0 | |
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,676,678,893 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | string = input()
countUpper = 0
countLower = 0
for i in string:
if (i.isupper() != False):
countUpper += 1
else:
countLower += 1
if (countLower>=countUpper):
print(string.lower())
else:
print(string.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
string = input()
countUpper = 0
countLower = 0
for i in string:
if (i.isupper() != False):
countUpper += 1
else:
countLower += 1
if (countLower>=countUpper):
print(string.lower())
else:
print(string.upper())
``` | 3.977 |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,618,490,794 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 280 | 16,384,000 | n=int(input())
l=list(map(int, input().split()))
if(n%2==0):
a=n//2
b=n//2
else:
if sum(l[:n//2])>sum(l[n//2+1:]):
a=n//2
b=n//2
else:
a=n//2+1
b=n//2+1
while(a>=0):
if sum(l[:a])==sum(l[b:]):
print(sum(l[:a]))
break
... | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
n=int(input())
l=list(map(int, input().split()))
if(n%2==0):
a=n//2
b=n//2
else:
if sum(l[:n//2])>sum(l[n//2+1:]):
a=n//2
b=n//2
else:
a=n//2+1
b=n//2+1
while(a>=0):
if sum(l[:a])==sum(l[b:]):
print(sum(l[:a]))
brea... | 0 | |
985 | E | Pencils and Boxes | PROGRAMMING | 2,100 | [
"binary search",
"data structures",
"dp",
"greedy",
"two pointers"
] | null | null | Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n* of *n* integer numbers — saturation of the color of each pencil. Now Mis... | The first line contains three integer numbers *n*, *k* and *d* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105, 0<=≤<=*d*<=≤<=109) — the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively.
The second line contains *n* integer numbers *a*1,<=... | Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO". | [
"6 3 10\n7 2 7 7 4 2\n",
"6 2 3\n4 5 3 13 4 10\n",
"3 2 5\n10 16 22\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10.
In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and p... | 0 | [
{
"input": "6 3 10\n7 2 7 7 4 2",
"output": "YES"
},
{
"input": "6 2 3\n4 5 3 13 4 10",
"output": "YES"
},
{
"input": "3 2 5\n10 16 22",
"output": "NO"
},
{
"input": "8 7 13\n52 85 14 52 92 33 80 85",
"output": "NO"
},
{
"input": "6 4 0\n1 3 2 4 2 1",
"output"... | 1,623,795,795 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 19 | 733 | 49,971,200 | def process(A, k, d):
n = len(A)
if n < k:
return 'NO'
A = sorted(A)
current = [[0, 0, 1]]
for i in range(1, n):
i0 = current[-1][0]
i1 = current[-1][1]
if (A[i]-A[i0] > d):
if current[-1][2] >= k:
current.append([i, i, 1])
... | Title: Pencils and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a seque... | ```python
def process(A, k, d):
n = len(A)
if n < k:
return 'NO'
A = sorted(A)
current = [[0, 0, 1]]
for i in range(1, n):
i0 = current[-1][0]
i1 = current[-1][1]
if (A[i]-A[i0] > d):
if current[-1][2] >= k:
current.append([i, i,... | 0 | |
780 | C | Andryusha and Colored Balloons | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a c... | The first line contains single integer *n* (3<=≤<=*n*<=≤<=2·105) — the number of squares in the park.
Each of the next (*n*<=-<=1) lines contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other u... | In the first line print single integer *k* — the minimum number of colors Andryusha has to use.
In the second line print *n* integers, the *i*-th of them should be equal to the balloon color on the *i*-th square. Each of these numbers should be within range from 1 to *k*. | [
"3\n2 3\n1 3\n",
"5\n2 3\n5 3\n4 3\n1 3\n",
"5\n2 1\n3 2\n4 3\n5 4\n"
] | [
"3\n1 3 2 ",
"5\n1 3 2 5 4 ",
"3\n1 2 3 1 2 "
] | In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.
In the second example there are following triples of consequently connected squares:
- 1 → 3 → 2 - 1 → 3 → 4 - 1 → 3 → 5 - 2 → 3 → 4 - 2 → 3 → 5 - 4 → 3 → 5
In the third example there are following... | 1,250 | [
{
"input": "3\n2 3\n1 3",
"output": "3\n1 3 2 "
},
{
"input": "5\n2 3\n5 3\n4 3\n1 3",
"output": "5\n1 3 2 5 4 "
},
{
"input": "5\n2 1\n3 2\n4 3\n5 4",
"output": "3\n1 2 3 1 2 "
},
{
"input": "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2",
"output": "5\n1 2 1 3 2 1 2 ... | 1,695,730,019 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 131,379,200 | import sys
sys.setrecursionlimit(100005)
def solve():
n = int(input())
adj = [[]for i in range(n+1)]
color1 = [-1]*(n+1)
color2 = [False]*(n+1)
for i in range(n-1):
a,b = map(int,input().split())
adj[a].append(b)
adj[b].append(a)
def dfs(s,par):
res = 1+len(adj[s])
for i in adj[s]:
if i!=par:
fo... | Title: Andryusha and Colored Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectio... | ```python
import sys
sys.setrecursionlimit(100005)
def solve():
n = int(input())
adj = [[]for i in range(n+1)]
color1 = [-1]*(n+1)
color2 = [False]*(n+1)
for i in range(n-1):
a,b = map(int,input().split())
adj[a].append(b)
adj[b].append(a)
def dfs(s,par):
res = 1+len(adj[s])
for i in adj[s]:
if i!=p... | 0 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,696,136,342 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | s = input().capitalize()
print(s) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
s = input().capitalize()
print(s)
``` | 0 | |
567 | B | Berland National Library | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.
Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of records in the system log. Next follow *n* events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ *r**i*" or "- *r**i*", where *r**i* is an integer from 1 to 106, the r... | Print a single integer — the minimum possible capacity of the reading room. | [
"6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7\n",
"2\n- 1\n- 2\n",
"2\n+ 1\n- 1\n"
] | [
"3",
"2",
"1"
] | In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3. | 1,000 | [
{
"input": "6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7",
"output": "3"
},
{
"input": "2\n- 1\n- 2",
"output": "2"
},
{
"input": "2\n+ 1\n- 1",
"output": "1"
},
{
"input": "5\n+ 1\n- 1\n+ 2\n+ 3\n- 4",
"output": "3"
},
{
"input": "3\n- 1\n- 2\n- 3",
"output": "... | 1,619,592,932 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 62 | 0 | if __name__=="__main__":
n=int(input())
li=[]
ma = []
for i in range(n):
r=input()
li.append(r)
for i in range(n):
c=0
if li[i][0]=="+":
c=c+1
else:
temp=li[i]
temp='+'+temp[1:]
if temp not in li[0:... | Title: Berland National Library
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.
Today was the... | ```python
if __name__=="__main__":
n=int(input())
li=[]
ma = []
for i in range(n):
r=input()
li.append(r)
for i in range(n):
c=0
if li[i][0]=="+":
c=c+1
else:
temp=li[i]
temp='+'+temp[1:]
if temp no... | 0 | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,576,131,640 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 280 | 307,200 | n = int(input())
leftd = {0: 0, 1: 0}
rightd = {0: 0, 1: 0}
for i in range(n):
a, b = map(int, input().split())
leftd[a] += 1
rightd[b] += 1
minl = 0
minr = 0
if (leftd[0] < leftd[1]):
minl = leftd[0]
else:
minl = leftd[1]
if (rightd[0] < rightd[1]):
minr = rightd[0]
else:
minr = rightd[1]
p... | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n = int(input())
leftd = {0: 0, 1: 0}
rightd = {0: 0, 1: 0}
for i in range(n):
a, b = map(int, input().split())
leftd[a] += 1
rightd[b] += 1
minl = 0
minr = 0
if (leftd[0] < leftd[1]):
minl = leftd[0]
else:
minl = leftd[1]
if (rightd[0] < rightd[1]):
minr = rightd[0]
else:
minr = r... | 3 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,655,233,369 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | stone = ['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind']
color = ['purple', 'green', 'blue', 'orange', 'red', 'yellow']
n = int(input())
for i in range(n):
a = input()
stone.remove(stone[color.index(a)])
print(len(stone))
for i in stone:
print(i)
| Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
stone = ['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind']
color = ['purple', 'green', 'blue', 'orange', 'red', 'yellow']
n = int(input())
for i in range(n):
a = input()
stone.remove(stone[color.index(a)])
print(len(stone))
for i in stone:
print(i)
``` | -1 | |
454 | A | Little Pony and Crystal Mine | PROGRAMMING | 800 | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot... | The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | 500 | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**... | 1,662,398,263 | 2,147,483,647 | Python 3 | OK | TESTS | 12 | 46 | 0 | n=int(input())
l=[]
p=n//2
q=1
for i in range(1,n//2+1):
l.append("*"*(p)+"D"*(q)+"*"*(p))
p-=1
q+=2
l.append("D"*(n))
l+=l[:-1][::-1]
for i in l:
print(i)
| Title: Little Pony and Crystal Mine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You ... | ```python
n=int(input())
l=[]
p=n//2
q=1
for i in range(1,n//2+1):
l.append("*"*(p)+"D"*(q)+"*"*(p))
p-=1
q+=2
l.append("D"*(n))
l+=l[:-1][::-1]
for i in l:
print(i)
``` | 3 | |
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,597,234,813 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 20,172,800 | n_d = input("")
n_d_list = list(n_d.split())
n, d = int(n_d_list[0]), int(n_d_list[1])
time_strng = input("")
time_strng_list = list(time_strng.split())
time = []
for i in range(len(time_strng_list)):
time.append(int(time_strng_list[i]))
j, c = 0, 0
for j in range(n):
if c < d:
c = time[j] ... | 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
n_d = input("")
n_d_list = list(n_d.split())
n, d = int(n_d_list[0]), int(n_d_list[1])
time_strng = input("")
time_strng_list = list(time_strng.split())
time = []
for i in range(len(time_strng_list)):
time.append(int(time_strng_list[i]))
j, c = 0, 0
for j in range(n):
if c < d:
c ... | 0 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,545,114,820 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 0 | n = int(input())
L = []
m = 0
w = str()
for i in range(n):
s = input()
L += [s]
a = L.count(s)
if a > m:
m = a
w = s
print(w)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
L = []
m = 0
w = str()
for i in range(n):
s = input()
L += [s]
a = L.count(s)
if a > m:
m = a
w = s
print(w)
``` | 3.938 |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11)... | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output"... | 1,674,839,228 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 857 | 0 | def main():
s = input()
n = len(s)
indexes = [(0, 0)]
for i in range(n - 4 + 1):
if s[i] == 'b' and s[i + 1] == 'e' and s[i + 2] == 'a' and s[i + 3] == 'r':
indexes.append((i, i + 3))
count = 0
for j in range(1, len(indexes)):
for i in range(n):
... | Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j... | ```python
def main():
s = input()
n = len(s)
indexes = [(0, 0)]
for i in range(n - 4 + 1):
if s[i] == 'b' and s[i + 1] == 'e' and s[i + 2] == 'a' and s[i + 3] == 'r':
indexes.append((i, i + 3))
count = 0
for j in range(1, len(indexes)):
for i in range(n):
... | 3 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,681,145,120 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n, s = map(int, input().split())
prices = list(map(int, input().split()))
prices.sort() # Сортируем массив стоимостей автомобилей
count = 0 # Количество купленных автомобилей
for price in prices:
if price <= s: # Если стоимость автомобиля меньше или равна оставшейся сумме S
s -= price # Уменьш... | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
n, s = map(int, input().split())
prices = list(map(int, input().split()))
prices.sort() # Сортируем массив стоимостей автомобилей
count = 0 # Количество купленных автомобилей
for price in prices:
if price <= s: # Если стоимость автомобиля меньше или равна оставшейся сумме S
s -= price... | -1 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,699,477,244 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | # 160A
# To solve we should sort the list and reverse it such that the
# beginning of the list has the largest numbers.
# We can then iterate over the list of coins such that we compare
# the sum of the coins on the left with those on the right. We stop
# At the coin count that allows our sum of coins on t... | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
# 160A
# To solve we should sort the list and reverse it such that the
# beginning of the list has the largest numbers.
# We can then iterate over the list of coins such that we compare
# the sum of the coins on the left with those on the right. We stop
# At the coin count that allows our sum of ... | 3 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,547,561,317 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 | import math
def f():
a , b, n = map(int,input().split())
i = 1
while True:
n = n - (math.gcd(a, n))
if n <=0:
print("0");break
n = n - (math.gcd(b,n))
if n <=0:
print("1");break
f() | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
import math
def f():
a , b, n = map(int,input().split())
i = 1
while True:
n = n - (math.gcd(a, n))
if n <=0:
print("0");break
n = n - (math.gcd(b,n))
if n <=0:
print("1");break
f()
``` | 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,669,672,796 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | a = list(input())
b = 'hello'
b1 = len(b)
c = 0
for i in range(len(a)):
if a[i] == b[c]:
c+=1
if c >= b1:
break
if c >= b1:
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
a = list(input())
b = 'hello'
b1 = len(b)
c = 0
for i in range(len(a)):
if a[i] == b[c]:
c+=1
if c >= b1:
break
if c >= b1:
print('YES')
else:
print('NO')
``` | 3.969 |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,679,479,191 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | s1,s2,s3=list(map(int,input()))
x=[]
for i in s1:
x.append(ord(i))
for i in s2:
x.append(ord(i))
x.sort()
c=[]
for i in s3:
c.append(ord(i))
c.sort()
if z==c:
print("YES")
else:
print("NO")
| Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
s1,s2,s3=list(map(int,input()))
x=[]
for i in s1:
x.append(ord(i))
for i in s2:
x.append(ord(i))
x.sort()
c=[]
for i in s3:
c.append(ord(i))
c.sort()
if z==c:
print("YES")
else:
print("NO")
``` | -1 | |
542 | C | Idempotent functions | PROGRAMMING | 2,000 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,<=2,<=...,<=*n*} is such function , that for any the formula *g*(*g*(*x*))<==<=*g*(*x*) holds.
Let's denote as *f*(*k*)(*x*) the function *f* applied *k* times to the value *x*. More formally, *f*(1)(*x*)<==<=*f*(*x*),... | In the first line of the input there is a single integer *n* (1<=≤<=*n*<=≤<=200) — the size of function *f* domain.
In the second line follow *f*(1),<=*f*(2),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n* for each 1<=≤<=*i*<=≤<=*n*), the values of a function. | Output minimum *k* such that function *f*(*k*)(*x*) is idempotent. | [
"4\n1 2 2 4\n",
"3\n2 3 3\n",
"3\n2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the first sample test function *f*(*x*) = *f*<sup class="upper-index">(1)</sup>(*x*) is already idempotent since *f*(*f*(1)) = *f*(1) = 1, *f*(*f*(2)) = *f*(2) = 2, *f*(*f*(3)) = *f*(3) = 2, *f*(*f*(4)) = *f*(4) = 4.
In the second sample test:
- function *f*(*x*) = *f*<sup class="upper-index">(1)</sup>(*x*) isn'... | 750 | [
{
"input": "4\n1 2 2 4",
"output": "1"
},
{
"input": "3\n2 3 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "16\n1 4 13 9 11 16 14 6 5 12 7 8 15 2 3 10",
"output": "105"
},
{
"input": "20\n1 ... | 1,430,797,266 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 0 | n = int(input())
f1 = [int(k) for k in input().split()]
setf = set(f1)
f = {i+1:int(k) for i, k in enumerate(f1)}
iden = [i for i in range(1,n+1)]
setiden = set(iden)
cycles = []
if not (setiden - setf):
while setf:
num = setf.pop()
cycle = set()
cycle.add(num)
while f[nu... | Title: Idempotent functions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,<=2,<=...,<=*n*} is such function , that for any the formula *g*(*g*(*x*))<==<=*g*(*x*) holds.
Let's denote as *... | ```python
n = int(input())
f1 = [int(k) for k in input().split()]
setf = set(f1)
f = {i+1:int(k) for i, k in enumerate(f1)}
iden = [i for i in range(1,n+1)]
setiden = set(iden)
cycles = []
if not (setiden - setf):
while setf:
num = setf.pop()
cycle = set()
cycle.add(num)
... | 0 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,673,623,296 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 62 | 0 | no_of_games = int(input())
mishka_win_count = chris_win_count = 0
for i in range(no_of_games):
mishka, chris = map(int, input().split())
if mishka > chris:
mishka_win_count += 1
elif chris > mishka:
chris_win_count += 1
if mishka_win_count > chris_win_count:
print("Mishka")
eli... | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
no_of_games = int(input())
mishka_win_count = chris_win_count = 0
for i in range(no_of_games):
mishka, chris = map(int, input().split())
if mishka > chris:
mishka_win_count += 1
elif chris > mishka:
chris_win_count += 1
if mishka_win_count > chris_win_count:
print("Mis... | 3 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,573,025,561 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 155 | 0 | # cf 669 A 800
n = int(input())
c = 2 * (n // 3)
if n % 3 != 0:
c += 1
print(c)
| Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
# cf 669 A 800
n = int(input())
c = 2 * (n // 3)
if n % 3 != 0:
c += 1
print(c)
``` | 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,679,508,059 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 4 | 124 | 2,764,800 | n, c = [int(i) for i in input().split()]
k = [input() for i in range(n)]
res = []
m = 0
for i in range(c):
if k[i].count(k[i][0]) != c:
m = 1
res.append(k[0])
for i in range(n-1):
if k[i] == k[i+1]:
m = 1
if m == 0:
print("YES")
else:
print("NO") | 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
n, c = [int(i) for i in input().split()]
k = [input() for i in range(n)]
res = []
m = 0
for i in range(c):
if k[i].count(k[i][0]) != c:
m = 1
res.append(k[0])
for i in range(n-1):
if k[i] == k[i+1]:
m = 1
if m == 0:
print("YES")
else:
print("NO")
``` | -1 |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,659,962,172 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x = 1802
i = 0
a = ("Sheldon", "Leonard", "Penny", "Rajesh", "Howard")
while True:
if(x>=5*(2**i)):
x-=5*(2**i)
i+=1
else:
print(a[x//(2**i)])
break | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
x = 1802
i = 0
a = ("Sheldon", "Leonard", "Penny", "Rajesh", "Howard")
while True:
if(x>=5*(2**i)):
x-=5*(2**i)
i+=1
else:
print(a[x//(2**i)])
break
``` | 0 |
107 | A | Dorm Water Supply | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs"
] | A. Dorm Water Supply | 1 | 256 | The German University in Cairo (GUC) dorm houses are numbered from 1 to *n*. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle).
For each house, t... | The first line contains two space-separated integers *n* and *p* (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*p*<=≤<=*n*) — the number of houses and the number of pipes correspondingly.
Then *p* lines follow — the description of *p* pipes. The *i*-th line contains three integers *a**i* *b**i* *d**i*, indicating a pipe of diameter *d... | Print integer *t* in the first line — the number of tank-tap pairs of houses.
For the next *t* lines, print 3 integers per line, separated by spaces: *tank**i*, *tap**i*, and *diameter**i*, where *tank**i*<=≠<=*tap**i* (1<=≤<=*i*<=≤<=*t*). Here *tank**i* and *tap**i* are indexes of tank and tap houses respectively, an... | [
"3 2\n1 2 10\n2 3 20\n",
"3 3\n1 2 20\n2 3 10\n3 1 5\n",
"4 2\n1 2 60\n3 4 50\n"
] | [
"1\n1 3 10\n",
"0\n",
"2\n1 2 60\n3 4 50\n"
] | none | 500 | [
{
"input": "3 2\n1 2 10\n2 3 20",
"output": "1\n1 3 10"
},
{
"input": "3 3\n1 2 20\n2 3 10\n3 1 5",
"output": "0"
},
{
"input": "4 2\n1 2 60\n3 4 50",
"output": "2\n1 2 60\n3 4 50"
},
{
"input": "10 10\n10 3 70\n1 9 98\n9 10 67\n5 2 78\n8 6 71\n4 8 95\n7 1 10\n2 5 73\n6 7 94\... | 1,621,075,467 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | import sys
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
temparr = get_ints()
n = temparr[0]
p = temparr[1]
dicts = {}
visited = [0 for _ in range(n)]
started = []
for pipe in range(p):
temparr = get_ints()
a = temparr[0]
b = temparr[1]
d = temparr[2]
a -= ... | Title: Dorm Water Supply
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
The German University in Cairo (GUC) dorm houses are numbered from 1 to *n*. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa... | ```python
import sys
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
temparr = get_ints()
n = temparr[0]
p = temparr[1]
dicts = {}
visited = [0 for _ in range(n)]
started = []
for pipe in range(p):
temparr = get_ints()
a = temparr[0]
b = temparr[1]
d = temparr[2]
... | 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,688,383,613 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | x=int(input())
if 1<=x<=100 :
s=[]
for i in range(x):
w=input()
s.append(w)
for i in s:
if len(i)> 10:
print(i[0]+str(len(i)-2)+i[-1])
else:
print(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
x=int(input())
if 1<=x<=100 :
s=[]
for i in range(x):
w=input()
s.append(w)
for i in s:
if len(i)> 10:
print(i[0]+str(len(i)-2)+i[-1])
else:
print(i)
``` | 3.969 |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,614,408,582 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 154 | 0 | a = input()
left,right = 0,0
n = len(a)
ans = 0
for i in range(n):
if a[i]=="(":
left+=1
else:
right+=1
if left==right:
ans = max(ans,2*left)
left,right = 0,0
if right>left:
left,right = 0,0
left,right = 0,0
for i in range(n-1,-1,-1):
if a[i]==... | Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
a = input()
left,right = 0,0
n = len(a)
ans = 0
for i in range(n):
if a[i]=="(":
left+=1
else:
right+=1
if left==right:
ans = max(ans,2*left)
left,right = 0,0
if right>left:
left,right = 0,0
left,right = 0,0
for i in range(n-1,-1,-1):
... | 0 |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,699,953,516 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 103 | 1,060 | 14,438,400 | #23n2200017708
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
def find(x):
l, r = 0, n
while l < r:
mid = (l + r) // 2
if a[mid] > x:
r = mid
else:
l = mid + 1
return l
for _ in range(q):
b = int(input())
print(find(b)... | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
#23n2200017708
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
def find(x):
l, r = 0, n
while l < r:
mid = (l + r) // 2
if a[mid] > x:
r = mid
else:
l = mid + 1
return l
for _ in range(q):
b = int(input())
pri... | 3 | |
717 | C | Potions Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of tasks. The next *n* lines contain exactly one integer number *a**i* (1<=≤<=*a**i*<=≤<=100<=000) — both the difficulty of the initial task and the laziness of the *i*-th students. | Print the minimum total time to finish all tasks modulo 10<=007. | [
"2\n1\n3\n"
] | [
"6\n"
] | In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. | 0 | [
{
"input": "2\n1\n3",
"output": "6"
}
] | 1,558,522,019 | 2,147,483,647 | PyPy 3 | OK | TESTS | 11 | 810 | 8,089,600 | n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
a=sorted(a)
sum=0
for j in range(n):
sum = (sum + (a[j])*(a[n-j-1]))%10007
print(sum%10007)
| Title: Potions Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun ... | ```python
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
a=sorted(a)
sum=0
for j in range(n):
sum = (sum + (a[j])*(a[n-j-1]))%10007
print(sum%10007)
``` | 3 | |
108 | A | Palindromic Times | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | A. Palindromic Times | 2 | 256 | Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th... | The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. | Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. | [
"12:21\n",
"23:59\n"
] | [
"13:31\n",
"00:00\n"
] | none | 500 | [
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
... | 1,596,518,964 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 6,963,200 | n=input()
chis=int(n[1]+n[0])
chas=int(n[0]+n[1])
minyt=int(n[3]+n[4])
if chas==23 and minyt>=32:
print('00:00')
exit()
if chis>minyt:
print(chas,':',chis,sep='')
else:
chas2=chas+1
chas2=str(chas2)
chis2=chas2[1]+chas2[0]
print(chas+1,':',int(chis2),sep='') | Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling... | ```python
n=input()
chis=int(n[1]+n[0])
chas=int(n[0]+n[1])
minyt=int(n[3]+n[4])
if chas==23 and minyt>=32:
print('00:00')
exit()
if chis>minyt:
print(chas,':',chis,sep='')
else:
chas2=chas+1
chas2=str(chas2)
chis2=chas2[1]+chas2[0]
print(chas+1,':',int(chis2),sep='')
``` | 0 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,693,397,537 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 |
n = int(input())
m = int(input())
a = int(input())
if n%a == 0:
x = n/a
else:
x = n//a + 1
if m%a == 0:
y = m/a
else:
y = m//a + 1
print (x + y) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n = int(input())
m = int(input())
a = int(input())
if n%a == 0:
x = n/a
else:
x = n//a + 1
if m%a == 0:
y = m/a
else:
y = m//a + 1
print (x + y)
``` | -1 |
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,665,771,035 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,t,k,d=list(map(int,input().split()))
if d<t:
print('YES')
exit()
elif d==t:
print('NO')
exit()
elif d>t:
if k>n:
print('NO')
exit()
else:
print('YES')
| 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
n,t,k,d=list(map(int,input().split()))
if d<t:
print('YES')
exit()
elif d==t:
print('NO')
exit()
elif d>t:
if k>n:
print('NO')
exit()
else:
print('YES')
``` | 0 | |
913 | B | Christmas Spruce | PROGRAMMING | 1,200 | [
"implementation",
"trees"
] | null | null | Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a ... | The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*).
Vertex 1 is the root. It's guaranteed that the root ha... | Print "Yes" if the tree is a spruce and "No" otherwise. | [
"4\n1\n1\n1\n",
"7\n1\n1\n1\n2\n2\n2\n",
"8\n1\n1\n1\n1\n3\n3\n3\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | The first example:
<img class="tex-graphics" src="https://espresso.codeforces.com/8dd976913226df83d535dfa66193f5525f8471bc.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The second example:
<img class="tex-graphics" src="https://espresso.codeforces.com/44dad5804f5290a2e026c9c41a15151562df8682.png" style="max-w... | 750 | [
{
"input": "4\n1\n1\n1",
"output": "Yes"
},
{
"input": "7\n1\n1\n1\n2\n2\n2",
"output": "No"
},
{
"input": "8\n1\n1\n1\n1\n3\n3\n3",
"output": "Yes"
},
{
"input": "3\n1\n1",
"output": "No"
},
{
"input": "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10",
"output": "N... | 1,588,058,602 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 93 | 307,200 | def wczytywanie():
n = int(input())
graf = {}
for i in range(2, n+1):
tata = int(input())
if tata not in graf:
graf[tata] = []
graf[tata].append(i)
return graf
def czy_swierk(graf):
ile_lisci = 0
for w in graf:
for d in graf[w]:
... | Title: Christmas Spruce
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there ex... | ```python
def wczytywanie():
n = int(input())
graf = {}
for i in range(2, n+1):
tata = int(input())
if tata not in graf:
graf[tata] = []
graf[tata].append(i)
return graf
def czy_swierk(graf):
ile_lisci = 0
for w in graf:
for d in graf[w... | 0 | |
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,683,801,216 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 92 | 0 | n, m = map(int, input().split())
containers = []
for i in range(m):
a, b = map(int, input().split())
containers.append((a, b))
# sort the containers in decreasing order of bi
containers.sort(key=lambda x: -x[1])
matches = 0
for a, b in containers:
# take the minimum of a and n, because we can... | 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())
containers = []
for i in range(m):
a, b = map(int, input().split())
containers.append((a, b))
# sort the containers in decreasing order of bi
containers.sort(key=lambda x: -x[1])
matches = 0
for a, b in containers:
# take the minimum of a and n, beca... | 3 |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11)... | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output"... | 1,556,005,936 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 0 | s = input()
res = 0
for i in range(len(s)):
idx = s.find('bear', i)
if idx >= 0:
res += len(s) - idx - 3
print(res)
| Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j... | ```python
s = input()
res = 0
for i in range(len(s)):
idx = s.find('bear', i)
if idx >= 0:
res += len(s) - idx - 3
print(res)
``` | 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,663,107,389 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | w = input()
target = list('hello')
c = 0
for i in w:
if target and i == target[0]:
target.pop(0)
print('YES' if len(target) == 0 else '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
w = input()
target = list('hello')
c = 0
for i in w:
if target and i == target[0]:
target.pop(0)
print('YES' if len(target) == 0 else 'NO')
``` | 3.977 |
990 | D | Graph And Its Complement | PROGRAMMING | 1,700 | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edg... | In a single line, three numbers are given $n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement. | If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes).
Otherwise, on the first line, print "YES"(without quotes). In each of the next $n$ lines, output $n$ digits such that $j$-th digit of $i$-th line must be $1$ if and only if there is an edge between vertices $i$ and $j$... | [
"3 1 2\n",
"3 3 3\n"
] | [
"YES\n001\n001\n110\n",
"NO\n"
] | none | 0 | [
{
"input": "3 1 2",
"output": "YES\n001\n001\n110"
},
{
"input": "3 3 3",
"output": "NO"
},
{
"input": "5 1 1",
"output": "YES\n01000\n10100\n01010\n00101\n00010"
},
{
"input": "123 1 84",
"output": "YES\n0011111111111111111111111111111111111111111111111111111111111111111... | 1,528,879,960 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n,a,b=map(int,input().split())
a,b=min(a,b),max(a,b)
if a!=1 :
print('NO')
else :
print('YES')
for i in range(n-b) :
for j in range(n-1) :
print(0,end='')
print(1)
for i in range(b-1) :
for j in range(n) :
print(0,end='')
print('')
... | Title: Graph And Its Complement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The ma... | ```python
n,a,b=map(int,input().split())
a,b=min(a,b),max(a,b)
if a!=1 :
print('NO')
else :
print('YES')
for i in range(n-b) :
for j in range(n-1) :
print(0,end='')
print(1)
for i in range(b-1) :
for j in range(n) :
print(0,end='')
pr... | 0 | |
725 | B | Food on the Plane | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats... | The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. | Print one integer — the number of seconds Vasya has to wait until he gets his lunch. | [
"1f\n",
"2d\n",
"4a\n",
"5e\n"
] | [
"1\n",
"10\n",
"11\n",
"18\n"
] | In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisl... | 1,000 | [
{
"input": "1f",
"output": "1"
},
{
"input": "2d",
"output": "10"
},
{
"input": "4a",
"output": "11"
},
{
"input": "5e",
"output": "18"
},
{
"input": "2c",
"output": "13"
},
{
"input": "1b",
"output": "5"
},
{
"input": "1000000000000000000d... | 1,551,521,701 | 2,147,483,647 | Python 3 | OK | TESTS | 119 | 109 | 0 | s=input()
l1=['a','b','c']
l2=['f','e','d']
n=int(s[:-1])
r=s[-1]
t=n//4
if n%4==0 :
t-=1
n-=t*4
ans=t*4+t*6*2
if n%2==0 :
ans+=1+6
if r in l2 :
ans+=l2.index(r)+1
else :
ans+=l1.index(r)+4
print(ans)
| Title: Food on the Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' ... | ```python
s=input()
l1=['a','b','c']
l2=['f','e','d']
n=int(s[:-1])
r=s[-1]
t=n//4
if n%4==0 :
t-=1
n-=t*4
ans=t*4+t*6*2
if n%2==0 :
ans+=1+6
if r in l2 :
ans+=l2.index(r)+1
else :
ans+=l1.index(r)+4
print(ans)
``` | 3 | |
717 | C | Potions Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of tasks. The next *n* lines contain exactly one integer number *a**i* (1<=≤<=*a**i*<=≤<=100<=000) — both the difficulty of the initial task and the laziness of the *i*-th students. | Print the minimum total time to finish all tasks modulo 10<=007. | [
"2\n1\n3\n"
] | [
"6\n"
] | In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. | 0 | [
{
"input": "2\n1\n3",
"output": "6"
}
] | 1,574,149,954 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 202 | 1,638,400 | n=int(input())
l=[]
d=[]
count=0
for i in range(n):
p=int(input())
l.append(p)
d.append(p)
d.sort()
l.sort()
d=d[::-1]
for i in range(n):
count+=(d[i]%10007)*(l[i]%10007)
print(count)
| Title: Potions Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun ... | ```python
n=int(input())
l=[]
d=[]
count=0
for i in range(n):
p=int(input())
l.append(p)
d.append(p)
d.sort()
l.sort()
d=d[::-1]
for i in range(n):
count+=(d[i]%10007)*(l[i]%10007)
print(count)
``` | 0 | |
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,389,371,713 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 2 | 702 | 268,390,400 | import itertools
n = int(input())
kangs = []
for cont in range(0,n):
kangs.append(int(input()))
kangs.sort()
ris = 0
perms = list(itertools.permutations(kangs))
for tmp in perms:
tmpris = 0
for cont in range(0,len(tmp),2):
if cont+1 < len(tmp):
if max([tmp[cont], tmp[cont+1]]... | Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ... | ```python
import itertools
n = int(input())
kangs = []
for cont in range(0,n):
kangs.append(int(input()))
kangs.sort()
ris = 0
perms = list(itertools.permutations(kangs))
for tmp in perms:
tmpris = 0
for cont in range(0,len(tmp),2):
if cont+1 < len(tmp):
if max([tmp[cont], tm... | 0 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,666,731,813 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import numpy as np
n,x=map(int,input().split(" "))
M=np.zeros((n,n))
nb=0
for i in range(n):
for j in range(n):
M[i,j]=(i+1)*(j+1)
if M[i,j]==x :
nb+=1
print(nb) | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
import numpy as np
n,x=map(int,input().split(" "))
M=np.zeros((n,n))
nb=0
for i in range(n):
for j in range(n):
M[i,j]=(i+1)*(j+1)
if M[i,j]==x :
nb+=1
print(nb)
``` | -1 | |
1,006 | F | Xor-Paths | PROGRAMMING | 2,100 | [
"bitmasks",
"brute force",
"dp",
"meet-in-the-middle"
] | null | null | There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
- You can move to the right or to ... | The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) — the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$). | Print one integer — the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$. | [
"3 3 11\n2 1 5\n7 10 0\n12 6 4\n",
"3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1\n",
"3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1\n"
] | [
"3\n",
"5\n",
"0\n"
] | All the paths from the first example:
- $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; - $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; - $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the path... | 0 | [
{
"input": "3 3 11\n2 1 5\n7 10 0\n12 6 4",
"output": "3"
},
{
"input": "3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1",
"output": "5"
},
{
"input": "3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1",
"output": "0"
},
{
"input": "1 1 1000000000000000000\n1000000000000000000",
"outpu... | 1,661,890,035 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 3,000 | 261,222,400 | from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import operator
import sys
input = sys.stdin.readline
R, C, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(C)]
l... | Title: Xor-Paths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bot... | ```python
from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import operator
import sys
input = sys.stdin.readline
R, C, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in rang... | 0 | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,567,083,378 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 140 | 0 | a,b,c,d=map(int,input().split())
f=2
res=['Misha','Vasya','Tie']
f=lambda p,t:max(3*p//10,p-p//250*t)
q,w=f(a,c),f(b,d)
if q==w:
print(res[2])
elif q>w:
print(res[0])
else:
print(res[1]) | Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
a,b,c,d=map(int,input().split())
f=2
res=['Misha','Vasya','Tie']
f=lambda p,t:max(3*p//10,p-p//250*t)
q,w=f(a,c),f(b,d)
if q==w:
print(res[2])
elif q>w:
print(res[0])
else:
print(res[1])
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,684,925,847 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 0 | def main():
a, b = map(int, input().split())
fractions = {
1: "1/1",
2: "5/6",
3: "2/3",
4: "1/2",
5: "1/3",
}
max_value = max(a, b)
if max_value in fractions:
print(fractions[max_value])
else:
print("1/6")
if __name__ == "__main... | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
def main():
a, b = map(int, input().split())
fractions = {
1: "1/1",
2: "5/6",
3: "2/3",
4: "1/2",
5: "1/3",
}
max_value = max(a, b)
if max_value in fractions:
print(fractions[max_value])
else:
print("1/6")
if __name__ ... | 3.969 |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,667,747,102 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n, t = map(int, input().split())
l = list(map(int, input().split()))
current_cell = 1
while current_cell < t:
current_cell += l[current_cell - 1]
print(current_cell)
if t == 1:
print("YES")
elif current_cell == t:
print("YES")
else:
print("NO") | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n, t = map(int, input().split())
l = list(map(int, input().split()))
current_cell = 1
while current_cell < t:
current_cell += l[current_cell - 1]
print(current_cell)
if t == 1:
print("YES")
elif current_cell == t:
print("YES")
else:
print("NO")
``` | 0 | |
792 | B | Counting-out Rhyme | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T... | The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109). | Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step. | [
"7 5\n10 4 11 4 1\n",
"3 2\n2 5\n"
] | [
"4 2 5 6 1 \n",
"3 2 \n"
] | Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader... | 0 | [
{
"input": "7 5\n10 4 11 4 1",
"output": "4 2 5 6 1 "
},
{
"input": "3 2\n2 5",
"output": "3 2 "
},
{
"input": "2 1\n1",
"output": "2 "
},
{
"input": "2 1\n2",
"output": "1 "
},
{
"input": "2 1\n3",
"output": "2 "
},
{
"input": "10 7\n5 10 4 3 8 10 6",... | 1,546,681,212 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 93 | 0 | n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = list(range(1, n + 1))
base = 0
for i in range(k):
base = (l[i] + base) % len(ans)
print(ans.pop(base)) | Title: Counting-out Rhyme
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In ... | ```python
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = list(range(1, n + 1))
base = 0
for i in range(k):
base = (l[i] + base) % len(ans)
print(ans.pop(base))
``` | 3 | |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,549,207,422 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 1,090 | 14,643,200 | def mce(v,n):
"""max count element"""
d=dict()
for c in v:
d.setdefault(c,0)
d[c]+=1
return n-max(d.values())
n=int(input())
v=[int(c) for c in input().split()]
print(mce(v,n)) | Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
def mce(v,n):
"""max count element"""
d=dict()
for c in v:
d.setdefault(c,0)
d[c]+=1
return n-max(d.values())
n=int(input())
v=[int(c) for c in input().split()]
print(mce(v,n))
``` | 3.700225 |
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.