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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
513 | B1 | Permutations | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | You are given a permutation *p* of numbers 1,<=2,<=...,<=*n*. Let's define *f*(*p*) as the following sum:
Find the lexicographically *m*-th permutation of length *n* in the set of permutations having the maximum possible value of *f*(*p*). | The single line of input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*cnt**n*), where *cnt**n* is the number of permutations of length *n* with maximum possible value of *f*(*p*).
The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the corr... | Output *n* number forming the required permutation. | [
"2 2\n",
"3 2\n"
] | [
"2 1 \n",
"1 3 2 \n"
] | In the first example, both permutations of numbers {1, 2} yield maximum possible *f*(*p*) which is equal to 4. Among them, (2, 1) comes second in lexicographical order. | 3 | [
{
"input": "2 2",
"output": "2 1 "
},
{
"input": "3 2",
"output": "1 3 2 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "3 1",
"output": "1 2 3 "
},
{
"input": "3 3",
"output": "2 3 1 "
},
{
"input": "3 4",
"output": "3 2 1 "
},
{
"inp... | 1,423,336,964 | 8,564 | Python 3 | OK | TESTS1 | 19 | 935 | 4,812,800 | import itertools
n, m = tuple(int(x) for x in input().split())
lstN = [x for x in range(1,n+1)]
def funcP(seq):
res = 0
for i in range(len(seq)):
for j in range(i, len(seq)):
res += min(seq[i:j+1])
return res
allPerm = [(perm,funcP(perm)) for perm in itertools.permutations(lstN)]
allPerm.sort(key = lambda x: ... | Title: Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation *p* of numbers 1,<=2,<=...,<=*n*. Let's define *f*(*p*) as the following sum:
Find the lexicographically *m*-th permutation of length *n* in the set of permutations having the maximum possible ... | ```python
import itertools
n, m = tuple(int(x) for x in input().split())
lstN = [x for x in range(1,n+1)]
def funcP(seq):
res = 0
for i in range(len(seq)):
for j in range(i, len(seq)):
res += min(seq[i:j+1])
return res
allPerm = [(perm,funcP(perm)) for perm in itertools.permutations(lstN)]
allPerm.sort(key = ... | 3 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,698,079,181 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | A=[int(x) for x in input().split()]
s=A[0]
m=A[0]
count=0
while m%10!=A[1]:
m=m+s
count+=1
print(count+1) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
A=[int(x) for x in input().split()]
s=A[0]
m=A[0]
count=0
while m%10!=A[1]:
m=m+s
count+=1
print(count+1)
``` | 0 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,695,295,766 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 97,996,800 | n, k = map(int, input().split())
list0 = []
for i in range(1, n + 1):
if i % 2 == 1:
list0.append(i)
else:
pass
for i in range(1, n + 1):
if i % 2 == 0:
list0.append(i)
else:
pass
print(list0[k - 1])
| Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
n, k = map(int, input().split())
list0 = []
for i in range(1, n + 1):
if i % 2 == 1:
list0.append(i)
else:
pass
for i in range(1, n + 1):
if i % 2 == 0:
list0.append(i)
else:
pass
print(list0[k - 1])
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,... | The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106). | Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. | [
"3 7\n",
"5 3\n",
"2 3\n"
] | [
"Dasha\n",
"Masha\n",
"Equal\n"
] | Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls ... | 0 | [
{
"input": "3 7",
"output": "Dasha"
},
{
"input": "5 3",
"output": "Masha"
},
{
"input": "2 3",
"output": "Equal"
},
{
"input": "31 88",
"output": "Dasha"
},
{
"input": "8 75",
"output": "Dasha"
},
{
"input": "32 99",
"output": "Dasha"
},
{
... | 1,659,555,270 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 27 | 92 | 512,000 | def gcd(a, b):
if a == b:
return a
if a > b:
return gcd(a-b, b)
else:
return gcd(a, b-a)
def lcm(a, b):
return a/gcd(a, b) * b
def findGF(a, b):
mult = lcm(a, b)
a = mult//a
b = mult//b
if abs(a-b) < 2:
return 'Equ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has so... | ```python
def gcd(a, b):
if a == b:
return a
if a > b:
return gcd(a-b, b)
else:
return gcd(a, b-a)
def lcm(a, b):
return a/gcd(a, b) * b
def findGF(a, b):
mult = lcm(a, b)
a = mult//a
b = mult//b
if abs(a-b) < 2:
r... | -1 | |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 ... | 1,583,120,487 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 216 | 0 | n, m = map(int, input().split())
mydiv = n // m
mymod = n % m
mylist = [ mydiv for _ in range(m) ]
if mymod == 0 :
out = ' '.join(str(i) for i in mylist)
else :
for i in mylist :
mylist[mylist.index(i)] += 1
mymod -= 1
if mymod == 0 :
out = ' '.join(str(i) for i in mylist)
... | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ... | ```python
n, m = map(int, input().split())
mydiv = n // m
mymod = n % m
mylist = [ mydiv for _ in range(m) ]
if mymod == 0 :
out = ' '.join(str(i) for i in mylist)
else :
for i in mylist :
mylist[mylist.index(i)] += 1
mymod -= 1
if mymod == 0 :
out = ' '.join(str(i) for i in... | 3 | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,697,701,240 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=int(input())#number of stones in the row
a=str(input())#R-red G-green B-blue
b=[]
for i in range(0,len(a)-1):
if(a[i]==a[i+1]):
continue
else:
b.append(a[i])
b.append(a[-1])
print(b)
print(n-len(b)) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
n=int(input())#number of stones in the row
a=str(input())#R-red G-green B-blue
b=[]
for i in range(0,len(a)-1):
if(a[i]==a[i+1]):
continue
else:
b.append(a[i])
b.append(a[-1])
print(b)
print(n-len(b))
``` | 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,633,709,488 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 77 | 7,065,600 | from copy import deepcopy
zoz=[]
for i in range(4):
zoz.append(list(input()))
def check(zoz):
for i in range(3):
for j in range(3):
if zoz[i][j]==zoz[i][j+1] and zoz[i+1][j]==zoz[i+1][j+1] and zoz[i+1][j]==zoz[i][j]:
return True
return False
def chan... | 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
from copy import deepcopy
zoz=[]
for i in range(4):
zoz.append(list(input()))
def check(zoz):
for i in range(3):
for j in range(3):
if zoz[i][j]==zoz[i][j+1] and zoz[i+1][j]==zoz[i+1][j+1] and zoz[i+1][j]==zoz[i][j]:
return True
return False
... | 3 | |
980 | C | Posterized | PROGRAMMING | 1,700 | [
"games",
"greedy"
] | null | null | Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.
Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref... | The first line of input contains two integers $n$ and $k$ ($1 \leq n \leq 10^5$, $1 \leq k \leq 256$), the number of pixels in the image, and the maximum size of a group, respectively.
The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ($0 \leq p_i \leq 255$), where $p_i$ is the color of the $i$-th pixel. | Print $n$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter. | [
"4 3\n2 14 3 4\n",
"5 2\n0 2 1 255 254\n"
] | [
"0 12 3 3\n",
"0 1 1 254 254\n"
] | One possible way to group colors and assign keys for the first sample:
Color $2$ belongs to the group $[0,2]$, with group key $0$.
Color $14$ belongs to the group $[12,14]$, with group key $12$.
Colors $3$ and $4$ belong to group $[3, 5]$, with group key $3$.
Other groups won't affect the result so they are not lis... | 1,500 | [
{
"input": "4 3\n2 14 3 4",
"output": "0 12 3 3"
},
{
"input": "5 2\n0 2 1 255 254",
"output": "0 1 1 254 254"
},
{
"input": "10 3\n112 184 161 156 118 231 191 128 91 229",
"output": "110 182 159 154 116 229 189 126 89 229"
},
{
"input": "9 3\n174 149 118 124 166 146 219 233 ... | 1,623,120,037 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 2,048,000 | def solution(n, k, arr):
ret = []
pix, grp = dict(), dict() # pix -> grp, grp_num -> [ll, ul]
for i in arr:
if i in pix:
continue
l = None
for j in range(1, k):
if i - j in pix:
l = i - j
break
if l:
... | Title: Posterized
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.
Their algorithm will be tested on an array of integers, where the $i$-th intege... | ```python
def solution(n, k, arr):
ret = []
pix, grp = dict(), dict() # pix -> grp, grp_num -> [ll, ul]
for i in arr:
if i in pix:
continue
l = None
for j in range(1, k):
if i - j in pix:
l = i - j
break
if l... | -1 | |
370 | A | Rook, Bishop and King | PROGRAMMING | 1,100 | [
"graphs",
"math",
"shortest paths"
] | null | null | Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of... | The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numb... | Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. | [
"4 3 1 6\n",
"5 5 5 6\n"
] | [
"2 1 3\n",
"1 0 1\n"
] | none | 500 | [
{
"input": "4 3 1 6",
"output": "2 1 3"
},
{
"input": "5 5 5 6",
"output": "1 0 1"
},
{
"input": "1 1 8 8",
"output": "2 1 7"
},
{
"input": "1 1 8 1",
"output": "1 0 7"
},
{
"input": "1 1 1 8",
"output": "1 0 7"
},
{
"input": "8 1 1 1",
"output": "... | 1,680,253,537 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 |
def rook(x1, y1, x2, y2):
if x1 == x2 or y1 == y2 :
return 1
else :
return 2
def bish(x1, y1, x2, y2):
if (x1%2==0 and y1%2==0 or x1%2!=0 and y1%2!=0) and (x2%2!=0 and y2%2==0 or x2%2==0 and y2%2!=0):
return 0
elif abs(x2-x1) == abs(y2-y1):
return 1
else :
... | Title: Rook, Bishop and King
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=... | ```python
def rook(x1, y1, x2, y2):
if x1 == x2 or y1 == y2 :
return 1
else :
return 2
def bish(x1, y1, x2, y2):
if (x1%2==0 and y1%2==0 or x1%2!=0 and y1%2!=0) and (x2%2!=0 and y2%2==0 or x2%2==0 and y2%2!=0):
return 0
elif abs(x2-x1) == abs(y2-y1):
return 1
else ... | 0 | |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,650,916,531 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | import math
n, d = list(map(int, input().split()))
t = list(map(int, input().split()))
singtime = 0
dc = d
for i in t:
singtime += i
d-=(n-1)*10+singtime
if d < 0:
print(-1)
else:
dc-=singtime
print(math.floor(dc/5))
| 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
import math
n, d = list(map(int, input().split()))
t = list(map(int, input().split()))
singtime = 0
dc = d
for i in t:
singtime += i
d-=(n-1)*10+singtime
if d < 0:
print(-1)
else:
dc-=singtime
print(math.floor(dc/5))
``` | 3 | |
111 | A | Petya and Inequiations | PROGRAMMING | 1,400 | [
"greedy"
] | A. Petya and Inequiations | 2 | 256 | Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y* | The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator. | Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. | [
"5 15 15\n",
"2 3 2\n",
"1 99 11\n"
] | [
"4\n4\n1\n1\n2\n",
"-1\n",
"11\n"
] | none | 500 | [
{
"input": "5 15 15",
"output": "11\n1\n1\n1\n1"
},
{
"input": "2 3 2",
"output": "-1"
},
{
"input": "1 99 11",
"output": "11"
},
{
"input": "100000 810000099998 1000000",
"output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n... | 1,684,407,695 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 186 | 8,806,400 | n, x, y = map(int,input().split())
if n > y :
print(-1)
else :
ans = (n-1)*1+(y-n+1)**2
if ans < x :
print(-1)
else :
for i in range(n-1):
print(1)
print(y-n+1) | Title: Petya and Inequiations
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<... | ```python
n, x, y = map(int,input().split())
if n > y :
print(-1)
else :
ans = (n-1)*1+(y-n+1)**2
if ans < x :
print(-1)
else :
for i in range(n-1):
print(1)
print(y-n+1)
``` | 3.937097 |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,610,718,815 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 156 | 307,200 | n,m=map(int,input().split())
list1=list(map(int,input().split()))
d=[]
for i in range(len(list1)):
d.append(0)
#for minumum, the people in the ques chooses the best possible thing(greedy)
moneymin=0
minlist=list1.copy()
f=0
minlist.sort()
ans1=True
while(ans1):
if(minlist[0]!=0):
moneymin=moneymin+... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
n,m=map(int,input().split())
list1=list(map(int,input().split()))
d=[]
for i in range(len(list1)):
d.append(0)
#for minumum, the people in the ques chooses the best possible thing(greedy)
moneymin=0
minlist=list1.copy()
f=0
minlist.sort()
ans1=True
while(ans1):
if(minlist[0]!=0):
moneymin... | 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,835,299 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | s = input()
a = "hello"
pos = 0
for i in s:
if i == a[pos]:
pos += 1
if pos == 5:
break
if pos == 5:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
a = "hello"
pos = 0
for i in s:
if i == a[pos]:
pos += 1
if pos == 5:
break
if pos == 5:
print("YES")
else:
print("NO")
``` | 3.977 |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,626,289,934 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 61 | 6,758,400 | d1,d2,d3=map(int,input().split())
a1=d1+d2+d3
a2=2*d1+2*d2
a3=2*d1+2*d3
a4=2*d2+2*d3
ans=min(a1,min(a2,min(a3,a4)))
print(ans) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3=map(int,input().split())
a1=d1+d2+d3
a2=2*d1+2*d2
a3=2*d1+2*d3
a4=2*d2+2*d3
ans=min(a1,min(a2,min(a3,a4)))
print(ans)
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,654,086,259 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | linee = input().split()
lst = [int(a) for a in linee]
# print(lst)
# 4 2 1 3
# 7 2 2 4
# 3 5 9 1
lst.sort(reverse=True)
# print(lst)
if len(lst) < 3:
print("IMPOSSIBLE")
else:
if lst[0] < lst[1] + lst[2]:
print("TRIANGLE")
else:
all = 0
for i in range(1, len(lst)):
... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
linee = input().split()
lst = [int(a) for a in linee]
# print(lst)
# 4 2 1 3
# 7 2 2 4
# 3 5 9 1
lst.sort(reverse=True)
# print(lst)
if len(lst) < 3:
print("IMPOSSIBLE")
else:
if lst[0] < lst[1] + lst[2]:
print("TRIANGLE")
else:
all = 0
for i in range(1, le... | 0 |
553 | A | Kyoya and Colored Balls | PROGRAMMING | 1,500 | [
"combinatorics",
"dp",
"math"
] | null | null | Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of... | The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors.
Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007. | [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n"
] | [
"3\n",
"1680\n"
] | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | 250 | [
{
"input": "3\n2\n2\n1",
"output": "3"
},
{
"input": "4\n1\n2\n3\n4",
"output": "1680"
},
{
"input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "12520708"
},
{
"input": "5\n10\n10\n10\n10\n10",
"output": "425711769"
},
{
"input": "11\n291\n3... | 1,670,344,578 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | from math import comb
mod=10**9+7
k =int(input())
res=1
tot=int(input())
for i in range(1,k,1):
c=int(input())
res=res*comb(tot+c-1,c-1)%mod
tot+=c
print(res) | Title: Kyoya and Colored Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by o... | ```python
from math import comb
mod=10**9+7
k =int(input())
res=1
tot=int(input())
for i in range(1,k,1):
c=int(input())
res=res*comb(tot+c-1,c-1)%mod
tot+=c
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,607,845,880 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 14 | 187 | 2,150,400 | def can_word_be_formed(s):
st = 'hello'
l = list(st)
z = []
ctr = 0
for i in range(len(s)):
if s[i] == l[ctr]:
ctr += 1
z.append(i)
break
for i in range(z[-1]+1, len(s)):
if s[i] == l[ctr]:
ctr += 1
z.append... | 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 can_word_be_formed(s):
st = 'hello'
l = list(st)
z = []
ctr = 0
for i in range(len(s)):
if s[i] == l[ctr]:
ctr += 1
z.append(i)
break
for i in range(z[-1]+1, len(s)):
if s[i] == l[ctr]:
ctr += 1
... | -1 |
437 | B | The Child and Set | PROGRAMMING | 1,500 | [
"bitmasks",
"greedy",
"implementation",
"sortings"
] | null | null | At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set *S*:
- its elements were distinct integers from 1 to *limit*; - the value of wa... | The first line contains two integers: *sum*,<=*limit* (1<=≤<=*sum*,<=*limit*<=≤<=105). | In the first line print an integer *n* (1<=≤<=*n*<=≤<=105), denoting the size of *S*. Then print the elements of set *S* in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1. | [
"5 5\n",
"4 3\n",
"5 1\n"
] | [
"2\n4 5\n",
"3\n2 3 1\n",
"-1\n"
] | In sample test 1: *lowbit*(4) = 4, *lowbit*(5) = 1, 4 + 1 = 5.
In sample test 2: *lowbit*(1) = 1, *lowbit*(2) = 2, *lowbit*(3) = 1, 1 + 2 + 1 = 4. | 1,500 | [
{
"input": "5 5",
"output": "2\n4 5"
},
{
"input": "4 3",
"output": "3\n2 3 1"
},
{
"input": "5 1",
"output": "-1"
},
{
"input": "54321 12345",
"output": "7008\n8958 8925 11009 10808 8221 9771 11269 7017 6416 11723 10324 5654 6569 10454 9164 10754 6069 7913 12154 11111 73... | 1,401,633,514 | 5,914 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 61 | 0 | summ,limit=map(int,input().split())
k=0
var=[]
rezult=[]
while 2**k <= limit:
var.append(2**k)
k+=1
i=len(var)-1
kolvoraz=[0]*len(var)
while summ> 0 and i>=0:
while var[i]>summ and i>=0:
i-=1
if(i<0):break
if(kolvoraz[i]==0):
rezult.append(var[i])
summ-=var... | Title: The Child and Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers some... | ```python
summ,limit=map(int,input().split())
k=0
var=[]
rezult=[]
while 2**k <= limit:
var.append(2**k)
k+=1
i=len(var)-1
kolvoraz=[0]*len(var)
while summ> 0 and i>=0:
while var[i]>summ and i>=0:
i-=1
if(i<0):break
if(kolvoraz[i]==0):
rezult.append(var[i])
... | 0 | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,603,519,244 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 307,200 | from math import gcd
a, b = list(map(int, input().split()))
result = 0
for i in range(int(input())):
first, second = list(map(int, input().split()))
n = [int(i) for i in range(first, second + 1)]
for number in n:
result = gcd(number, b)
if result > 1:
break
if res... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
from math import gcd
a, b = list(map(int, input().split()))
result = 0
for i in range(int(input())):
first, second = list(map(int, input().split()))
n = [int(i) for i in range(first, second + 1)]
for number in n:
result = gcd(number, b)
if result > 1:
break
... | 0 |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,570,915,900 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 249 | 12,288,000 | n, k = map(int, input().split())
lectures = list(map(int, input().split()))
sleeping = list(map(int, input().split()))
dp_ok = [0] * (n - k + 1)
dp_magic = [0] * (n - k + 1)
s1, s2 = 0, 0
for i in range(k):
s1 += lectures[i] * sleeping[i]
s2 += lectures[i]
dp_ok[0] = s1
dp_magic[0] = s2
max_diff, m... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
n, k = map(int, input().split())
lectures = list(map(int, input().split()))
sleeping = list(map(int, input().split()))
dp_ok = [0] * (n - k + 1)
dp_magic = [0] * (n - k + 1)
s1, s2 = 0, 0
for i in range(k):
s1 += lectures[i] * sleeping[i]
s2 += lectures[i]
dp_ok[0] = s1
dp_magic[0] = s2
m... | 3 | |
274 | A | k-Multiple Free Set | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"sortings"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 500 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,644,668,279 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 1 | 154 | 2,150,400 | a, b = map(int, input().split())
r = list(map(int, input().split()))
for i in r:
r.remove(i * b)
print(len(r)) | Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, ... | ```python
a, b = map(int, input().split())
r = list(map(int, input().split()))
for i in r:
r.remove(i * b)
print(len(r))
``` | -1 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,656,933,583 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
c=d=0
for i in range(len(l)):
c+=l[i]
d+=1
if c>=n:
break
print(d) | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
c=d=0
for i in range(len(l)):
c+=l[i]
d+=1
if c>=n:
break
print(d)
``` | 0 | |
95 | B | Lucky Numbers | PROGRAMMING | 1,800 | [
"dp",
"greedy"
] | B. Lucky Numbers | 2 | 256 | Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo... | The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=10100000). This number doesn't have leading zeroes. | Output the least super lucky number that is more than or equal to *n*. | [
"4500\n",
"47\n"
] | [
"4747\n",
"47\n"
] | none | 1,000 | [
{
"input": "4500",
"output": "4747"
},
{
"input": "47",
"output": "47"
},
{
"input": "1",
"output": "47"
},
{
"input": "12",
"output": "47"
},
{
"input": "4587",
"output": "4747"
},
{
"input": "100",
"output": "4477"
},
{
"input": "1007",
... | 1,597,320,759 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 404 | 2,048,000 | import itertools
from itertools import permutations
def ans(x):
l=['4']*(x//2)+['7']*(x//2)
k=''.join(l)
l=sorted(list(set(list(permutations(k)))))
l=[int(''.join(x)) for x in l]
return l
def binsearch(l,m):
low=0
high=len(l)-1
while low<high:
mid=(high+low)//2
... | Title: Lucky Numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky n... | ```python
import itertools
from itertools import permutations
def ans(x):
l=['4']*(x//2)+['7']*(x//2)
k=''.join(l)
l=sorted(list(set(list(permutations(k)))))
l=[int(''.join(x)) for x in l]
return l
def binsearch(l,m):
low=0
high=len(l)-1
while low<high:
mid=(high+low)... | -1 |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,699,281,629 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 61 | 0 | d1, d2, d3 = map(int, input().split())
g = d1 + d2 + d3
s = min(d1, d2) + min(d1 + d2, d3) + min(max(d1, d2), min(d1, d2) + d3)
print(s)
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1, d2, d3 = map(int, input().split())
g = d1 + d2 + d3
s = min(d1, d2) + min(d1 + d2, d3) + min(max(d1, d2), min(d1, d2) + d3)
print(s)
``` | 3 | |
569 | B | Inventory | PROGRAMMING | 1,200 | [
"greedy",
"math"
] | null | null | Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the... | The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items. | Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. | [
"3\n1 3 2\n",
"4\n2 2 3 3\n",
"1\n2\n"
] | [
"1 3 2 \n",
"2 1 3 4 \n",
"1 \n"
] | In the first test the numeration is already a permutation, so there is no need to change anything.
In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
In the third test you need to replace 2 by 1, as the numbering should start from one. | 1,000 | [
{
"input": "3\n1 3 2",
"output": "1 3 2 "
},
{
"input": "4\n2 2 3 3",
"output": "2 1 3 4 "
},
{
"input": "1\n2",
"output": "1 "
},
{
"input": "3\n3 3 1",
"output": "3 2 1 "
},
{
"input": "5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "5\n5 3 4 4 ... | 1,441,954,918 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 140 | 10,137,600 | def main():
n = int(input()) + 1
res, fil, rest = list(map(int, input().split())), [True] * n, []
for i, x in enumerate(res):
if x >= n or not fil[x]:
rest.append(i)
else:
fil[x] = False
for i, x in zip(rest, filter(fil.__getitem__, range(1, n))):
res[i] =... | Title: Inventory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numb... | ```python
def main():
n = int(input()) + 1
res, fil, rest = list(map(int, input().split())), [True] * n, []
for i, x in enumerate(res):
if x >= n or not fil[x]:
rest.append(i)
else:
fil[x] = False
for i, x in zip(rest, filter(fil.__getitem__, range(1, n))):
... | 3 | |
374 | A | Inna and Pink Pony | PROGRAMMING | 2,000 | [
"greedy",
"implementation"
] | null | null | Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an *n*<=×<=*m* chessboard, a very tasty candy and two numbers *a* and *b*.
Dima put the chessboard in front of Inna and placed the candy in position (*i*,<=*j*) on the board.... | The first line of the input contains six integers *n*,<=*m*,<=*i*,<=*j*,<=*a*,<=*b* (1<=≤<=*n*,<=*m*<=≤<=106; 1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*; 1<=≤<=*a*,<=*b*<=≤<=106).
You can assume that the chessboard rows are numbered from 1 to *n* from top to bottom and the columns are numbered from 1 to *m* from left to rig... | In a single line print a single integer — the minimum number of moves needed to get the candy.
If Inna and the pony cannot get the candy playing by Dima's rules, print on a single line "Poor Inna and pony!" without the quotes. | [
"5 7 1 3 2 2\n",
"5 5 2 3 1 1\n"
] | [
"2\n",
"Poor Inna and pony!\n"
] | Note to sample 1:
Inna and the pony can move the candy to position (1 + 2, 3 + 2) = (3, 5), from there they can move it to positions (3 - 2, 5 + 2) = (1, 7) and (3 + 2, 5 + 2) = (5, 7). These positions correspond to the corner squares of the chess board. Thus, the answer to the test sample equals two. | 500 | [
{
"input": "5 7 1 3 2 2",
"output": "2"
},
{
"input": "5 5 2 3 1 1",
"output": "Poor Inna and pony!"
},
{
"input": "1 1 1 1 1 1",
"output": "0"
},
{
"input": "23000 15500 100 333 9 1",
"output": "15167"
},
{
"input": "33999 99333 33000 99000 3 9",
"output": "3... | 1,645,481,646 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,048,000 | {
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "6d4e03b7-0200-4344-9401-52f6cf714db5",
"metadata": {},
"outputs": [],
"source": [
"n,m,i,j,a,b=map(int,input.split()) \n",
"inf=10**7\n",
"def nstep(x,y):\n",
" global alx,aly\n",
" if x%a!=0 or y%b!=0:\... | Title: Inna and Pink Pony
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an *n*<=×<=*m* chessboard, a very tasty candy and two numbers *a* and *... | ```python
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "6d4e03b7-0200-4344-9401-52f6cf714db5",
"metadata": {},
"outputs": [],
"source": [
"n,m,i,j,a,b=map(int,input.split()) \n",
"inf=10**7\n",
"def nstep(x,y):\n",
" global alx,aly\n",
" if x%a!=0 o... | -1 | |
660 | A | Co-prime Array | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values shoul... | [
"3\n2 7 28\n"
] | [
"1\n2 7 9 28\n"
] | none | 0 | [
{
"input": "3\n2 7 28",
"output": "1\n2 7 1 28"
},
{
"input": "1\n1",
"output": "0\n1"
},
{
"input": "1\n548",
"output": "0\n548"
},
{
"input": "1\n963837006",
"output": "0\n963837006"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0\n1 1 1 1 1 1 1 1 1 1"... | 1,608,640,181 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 109 | 307,200 | # cook your dish here
import math
n = int(input())
a = list(map(int, input().split()))
b = []
b.append(a[0])
c = 0
i = 1
while(i<n):
if math.gcd(a[i],a[i-1])==1:
b.append(a[i])
else:
c+=1
if math.gcd(2,a[i-1])==1 and math.gcd(2,a[i])==1:
b.append(2)
... | Title: Co-prime Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
A... | ```python
# cook your dish here
import math
n = int(input())
a = list(map(int, input().split()))
b = []
b.append(a[0])
c = 0
i = 1
while(i<n):
if math.gcd(a[i],a[i-1])==1:
b.append(a[i])
else:
c+=1
if math.gcd(2,a[i-1])==1 and math.gcd(2,a[i])==1:
b.append(2)
... | 3 | |
690 | E2 | Photographs (II) | PROGRAMMING | 2,600 | [] | null | null | Zombies seem to have become much more intelligent lately – a few have somehow wandered into the base through the automatic gate. Heidi has had to beef up security, and a new gate has been installed. Unfortunately, now the questions being asked are more complicated, and even humans have trouble answering them. Can you s... | The input format is the same as in the previous version, except that the first line of every question now contains three space-separated numbers *h*, *w* and *k* (1<=≤<=*h*,<=*w*<=≤<=600, 2<=≤<=*k*<=≤<=16) – the height (number of rows) and width (number of columns) of the photograph and the number of pieces, respective... | Your program should print *q* lines. The *i*-th line should contain your answer for the *i*-th question: a space-separated sequence of *k* numbers π1,<=π2,<=...,<=π*k* such that:
- π is a permutation of {1,<=2,<=...,<=*k*}, that is, each number from 1 to *k* appears exactly once in π, - for each *j*<==<=1,<=...,<=*... | [] | [] | The link to download all the necessary materials is http://assets.codeforces.com/files/690/medium_contestant_package.zip | 0 | [] | 1,616,357,476 | 11,176 | Python 3 | OK | TESTS | 1 | 46 | 0 | print("""2 1
2 3 1
4 3 2 1
1 3 4 2 5
1 6 11 3 10 9 15 12 7 13 2 5 4 14 8
5 1 3 11 10 7 6 9 13 15 12 4 14 2 8
9 7 2 5 1 10 8 3 4 6
2 1 4 3
4 12 8 2 9 14 5 7 1 6 10 13 15 3 11
11 5 6 8 10 12 7 2 1 4 9 3 13 14 15
11 7 8 4 5 15 13 14 3 9 12 2 1 10 6
12 7 11 4 10 2 5 14 13 1 6 3 9 8 15 16
3 2 1
4 2 1 3 5
1 8 1... | Title: Photographs (II)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zombies seem to have become much more intelligent lately – a few have somehow wandered into the base through the automatic gate. Heidi has had to beef up security, and a new gate has been installed. Unfortunately, now ... | ```python
print("""2 1
2 3 1
4 3 2 1
1 3 4 2 5
1 6 11 3 10 9 15 12 7 13 2 5 4 14 8
5 1 3 11 10 7 6 9 13 15 12 4 14 2 8
9 7 2 5 1 10 8 3 4 6
2 1 4 3
4 12 8 2 9 14 5 7 1 6 10 13 15 3 11
11 5 6 8 10 12 7 2 1 4 9 3 13 14 15
11 7 8 4 5 15 13 14 3 9 12 2 1 10 6
12 7 11 4 10 2 5 14 13 1 6 3 9 8 15 16
3 2 1
4 2 1 ... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,693,233,024 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | def check_equilibrium(n, vectors):
total_x = 0
total_y = 0
total_z = 0
for vector in vectors:
x, y, z = vector
total_x += x
total_y += y
total_z += z
if total_x == 0 and total_y == 0 and total_z == 0:
return "YES"
else:
return "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
def check_equilibrium(n, vectors):
total_x = 0
total_y = 0
total_z = 0
for vector in vectors:
x, y, z = vector
total_x += x
total_y += y
total_z += z
if total_x == 0 and total_y == 0 and total_z == 0:
return "YES"
else:
re... | 3.977 |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,600,961,238 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 |
n = int(input())
t = list(map(int,input().split()))
n1=[]
for k in range(n):
if t[k]<0:
n1.append(t[k])
break
n2=[]
u=1
for j in range(k+1,n):
u*=t[j]
n2.append(t[j])
if u>0:
break
n3 = t[j+1:]
print(len(n1),*n1)
print(len(n2),*n2)
print(... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
n = int(input())
t = list(map(int,input().split()))
n1=[]
for k in range(n):
if t[k]<0:
n1.append(t[k])
break
n2=[]
u=1
for j in range(k+1,n):
u*=t[j]
n2.append(t[j])
if u>0:
break
n3 = t[j+1:]
print(len(n1),*n1)
print(len(n2),*n... | 0 | |
426 | B | Sereja and Mirroring | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Let's assume that we are given a matrix *b* of size *x*<=×<=*y*, let's determine the operation of mirroring matrix *b*. The mirroring of matrix *b* is a 2*x*<=×<=*y* matrix *c* which has the following properties:
- the upper half of matrix *c* (rows with numbers from 1 to *x*) exactly matches *b*; - the lower half o... | The first line contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains *m* integers — the elements of matrix *a*. The *i*-th line contains integers *a**i*1,<=*a**i*2,<=...,<=*a**im* (0<=≤<=*a**ij*<=≤<=1) — the *i*-th row of the matrix *a*. | In the single line, print the answer to the problem — the minimum number of rows of matrix *b*. | [
"4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1\n",
"3 3\n0 0 0\n0 0 0\n0 0 0\n",
"8 1\n0\n1\n1\n0\n0\n1\n1\n0\n"
] | [
"2\n",
"3\n",
"2\n"
] | In the first test sample the answer is a 2 × 3 matrix *b*:
If we perform a mirroring operation with this matrix, we get the matrix *a* that is given in the input: | 1,000 | [
{
"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 0",
"output": "3"
},
{
"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0",
"output": "2"
},
{
"input": "10 4\n0 0 1 0\n0 0 1 0\n1 1 0 1\n0 0 1 1\n1 0 1 0\n1 0 1 0\n0 0 1 1\n1 1 0 1\n0 0 1 0\... | 1,490,117,964 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 5,222,400 | # @Author: Justin Hershberger
# @Date: 21-03-2017
# @Filename: 426B.py
# @Last modified by: Justin Hershberger
# @Last modified time: 21-03-2017
#Justin Hershberger
#Py3.5
import fileinput
def check_matrix(m):
first_half = []
second_half = []
for i in range(len(m) // 2):
first_half.a... | Title: Sereja and Mirroring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's assume that we are given a matrix *b* of size *x*<=×<=*y*, let's determine the operation of mirroring matrix *b*. The mirroring of matrix *b* is a 2*x*<=×<=*y* matrix *c* which has the following properties:
... | ```python
# @Author: Justin Hershberger
# @Date: 21-03-2017
# @Filename: 426B.py
# @Last modified by: Justin Hershberger
# @Last modified time: 21-03-2017
#Justin Hershberger
#Py3.5
import fileinput
def check_matrix(m):
first_half = []
second_half = []
for i in range(len(m) // 2):
fi... | 0 | |
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,696,251,599 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | s1 = input()
str1 = list(s1)
s2 = input()
str2= list(s2)
if all(char.isupper() for char in str1):
str1.sort()
sort1 = "".join(str1)
if all(char.isupper() for char in str2):
str2.sort()
sort2 = "".join(str2)
s3=input()
str3 = list(s3)
if all(char.isupper() for char in str3):
str3.sort()
... | 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 = input()
str1 = list(s1)
s2 = input()
str2= list(s2)
if all(char.isupper() for char in str1):
str1.sort()
sort1 = "".join(str1)
if all(char.isupper() for char in str2):
str2.sort()
sort2 = "".join(str2)
s3=input()
str3 = list(s3)
if all(char.isupper() for char in str3):
st... | 3 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,667,140,072 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | c, n = list(map(int, input().split()))
count = c
while c >= n:
count += c/n
c = c/n
print(int(count)) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
c, n = list(map(int, input().split()))
count = c
while c >= n:
count += c/n
c = c/n
print(int(count))
``` | 0 | |
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,641,629,809 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 5,324,800 | n = int(input())
arr = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
for i in range(n-1):
x = arr.pop(0)
arr.append(x)
arr.append(x)
print(arr[0]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n = int(input())
arr = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
for i in range(n-1):
x = arr.pop(0)
arr.append(x)
arr.append(x)
print(arr[0])
``` | 0 |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,687,850,734 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | import math
n,t,k,d = map(int, input().split())
lo1 = math.ceil(n/k)*t
sobanh = math.ceil(d/t)*k
sobanhconlai = n-sobanh
if sobanhconlai <= 0:
lo2 = d
else:
lo2 = d + math.ceil(sobanhconlai/8)*t
if lo1 <= lo2:
print('NO')
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
import math
n,t,k,d = map(int, input().split())
lo1 = math.ceil(n/k)*t
sobanh = math.ceil(d/t)*k
sobanhconlai = n-sobanh
if sobanhconlai <= 0:
lo2 = d
else:
lo2 = d + math.ceil(sobanhconlai/8)*t
if lo1 <= lo2:
print('NO')
else:
print('YES')
``` | 0 | |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,490,629,988 | 4,688 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 12,902,400 | i = input()
x = list(map(int, input().split()))
min = abs(x[0] - x[1])
acc = 0
spl = 1
for y in x:
for z in x[spl:]:
if abs(y - z) < min:
min = abs(y - z)
acc = 0
if abs(y - z) == min:
acc += 1
spl +=1
print(min,acc) | Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
i = input()
x = list(map(int, input().split()))
min = abs(x[0] - x[1])
acc = 0
spl = 1
for y in x:
for z in x[spl:]:
if abs(y - z) < min:
min = abs(y - z)
acc = 0
if abs(y - z) == min:
acc += 1
spl +=1
print(min,acc)
``` | 0 | |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,644,068,802 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = input()
a = [[],[]]
f = False
for i in xrange(n):
t = input()
f = t < 0
a[f] += [-t if f else t]
x,y=[sum(a[0])]+a[0], [sum(a[1])]+a[1]
if x<y or (x==y and f):
print "second"
else:
print "first" | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
n = input()
a = [[],[]]
f = False
for i in xrange(n):
t = input()
f = t < 0
a[f] += [-t if f else t]
x,y=[sum(a[0])]+a[0], [sum(a[1])]+a[1]
if x<y or (x==y and f):
print "second"
else:
print "first"
``` | -1 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,631,772,113 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 8,601,600 | n = int(input())
s = list(map(int,input()))
i,j = 0,1
while j<len(s):
if s[i] != s[j]:
del(s[i:(j+1)])
i,j = 0,1
else:
i+=1
j+=1
print(len(s)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n = int(input())
s = list(map(int,input()))
i,j = 0,1
while j<len(s):
if s[i] != s[j]:
del(s[i:(j+1)])
i,j = 0,1
else:
i+=1
j+=1
print(len(s))
``` | 0 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,677,494,799 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | s = input()
t = input()
m = abs(ord(s[0]) - ord(t[0]))
n = abs(ord(s[1]) - ord(t[1]))
print(max(m, n))
while m != 0 or n != 0:
if m != 0:
if m > 0:
print('L')
m -= 1
else:
print('R')
m += 1
if n != 0:
if n > 0:
print('D')
n -= 1
else:
print('U')
n += 1
| Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
s = input()
t = input()
m = abs(ord(s[0]) - ord(t[0]))
n = abs(ord(s[1]) - ord(t[1]))
print(max(m, n))
while m != 0 or n != 0:
if m != 0:
if m > 0:
print('L')
m -= 1
else:
print('R')
m += 1
if n != 0:
if n > 0:
print('D')
n -= 1
else:
print('U')
n += 1
... | 0 |
645 | A | Amity Assessment | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the ... | The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaran... | Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes). | [
"AB\nXC\nXB\nAC\n",
"AB\nXC\nAC\nBX\n"
] | [
"YES\n",
"NO\n"
] | The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... | 500 | [
{
"input": "AB\nXC\nXB\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nAC\nBX",
"output": "NO"
},
{
"input": "XC\nBA\nCB\nAX",
"output": "NO"
},
{
"input": "AB\nXC\nAX\nCB",
"output": "YES"
},
{
"input": "CB\nAX\nXA\nBC",
"output": "YES"
},
{
"input": "BC... | 1,458,320,413 | 1,513 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 0 | count = 12
ans = False
first = [list(input())]
first.append(list(input()))
second = [list(input())]
second.append(list(input()))
for i in range(count):
if first == second:
ans = True
break
if first[0][0] == 'X':
first[0][0], first[0][1] = first[0][1], first[0][0]
elif fir... | Title: Amity Assessment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one ... | ```python
count = 12
ans = False
first = [list(input())]
first.append(list(input()))
second = [list(input())]
second.append(list(input()))
for i in range(count):
if first == second:
ans = True
break
if first[0][0] == 'X':
first[0][0], first[0][1] = first[0][1], first[0][0]
... | 0 | |
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,490,629 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | guest = input().split()
host = input().split()
letters = input().split()
if guest in letters and host in letters:
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
guest = input().split()
host = input().split()
letters = input().split()
if guest in letters and host in letters:
print("YES")
else:
print("NO")
``` | 0 | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,510,315,466 | 746 | Python 3 | WRONG_ANSWER | TESTS | 25 | 62 | 0 | from math import *
l, r, x, y, k = map(int, input().split())
l //= k
r //= k
print("YES" if (x <= r and y >= l) else "NO")
| Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
from math import *
l, r, x, y, k = map(int, input().split())
l //= k
r //= k
print("YES" if (x <= r and y >= l) else "NO")
``` | 0 | |
846 | A | Curriculum Vitae | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. | Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | 0 | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,504,641,220 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 0 | def main():
n = int(input())
a = map(int, input().split())
s = sum(a)
ans = max(s, n - s)
zeros = 0
for i, x in enumerate(a):
if x == 0:
zeros += 1
else:
ans = max(ans, zeros + sum(a[i:]))
print(ans)
main()
| Title: Curriculum Vitae
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* g... | ```python
def main():
n = int(input())
a = map(int, input().split())
s = sum(a)
ans = max(s, n - s)
zeros = 0
for i, x in enumerate(a):
if x == 0:
zeros += 1
else:
ans = max(ans, zeros + sum(a[i:]))
print(ans)
main()
``` | 0 | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,494,330,301 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 204,800 | # Dijkstra's Algorithm
import heapq
import sys
import math
# Wrapper for Python's min-heap functions
class priority_queue:
def __init__(self):
self.pq = []
def push(self, item):
heapq.heappush(self.pq, item)
def pop(self):
return heapq.heappop(self.pq)
def empty(self):
... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
# Dijkstra's Algorithm
import heapq
import sys
import math
# Wrapper for Python's min-heap functions
class priority_queue:
def __init__(self):
self.pq = []
def push(self, item):
heapq.heappush(self.pq, item)
def pop(self):
return heapq.heappop(self.pq)
def empty(se... | 0 |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,629,378,650 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 6,963,200 | t,v=map(int,input().split())
ans=[]
for i in range(1,t+1):
a=list(map(int,input().split()))
if(min(a[1:])<v):
ans.append(i)
print(len(ans))
for i in range(len(ans)):
print(ans[i],end=" ")
| Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
t,v=map(int,input().split())
ans=[]
for i in range(1,t+1):
a=list(map(int,input().split()))
if(min(a[1:])<v):
ans.append(i)
print(len(ans))
for i in range(len(ans)):
print(ans[i],end=" ")
``` | 3 | |
265 | B | Roadside Trees (Simplified Edition) | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol... | The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. | Print a single integer — the minimal time required to eat all nuts in seconds. | [
"2\n1\n2\n",
"5\n2\n1\n2\n1\n1\n"
] | [
"5\n",
"14\n"
] | none | 1,000 | [
{
"input": "2\n1\n2",
"output": "5"
},
{
"input": "5\n2\n1\n2\n1\n1",
"output": "14"
},
{
"input": "1\n1",
"output": "2"
}
] | 1,597,637,843 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 434 | 3,379,200 | n=int(input())
L=[]
for i in range(n):
k=int(input())
L.append(k)
time=L[0]+1
for i in range(n-1):
time+=1
if(L[i]<=L[i+1]):
time+=(L[i+1]-L[i]+1)
else:
time+=L[i+1]+1
print(time)
| Title: Roadside Trees (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wan... | ```python
n=int(input())
L=[]
for i in range(n):
k=int(input())
L.append(k)
time=L[0]+1
for i in range(n-1):
time+=1
if(L[i]<=L[i+1]):
time+=(L[i+1]-L[i]+1)
else:
time+=L[i+1]+1
print(time)
``` | 0 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,688,833,648 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 614,400 |
k =int(input())
l =int(input())
m =int(input())
n =int(input())
d =int(input())
dp=[0]*d
for i in range(1,d+1):
if i %k ==0 or i % l == 0 or i % m == 0 or i % n == 0:
dp[i-1] = 1
print(sum(dp)) | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
k =int(input())
l =int(input())
m =int(input())
n =int(input())
d =int(input())
dp=[0]*d
for i in range(1,d+1):
if i %k ==0 or i % l == 0 or i % m == 0 or i % n == 0:
dp[i-1] = 1
print(sum(dp))
``` | 3 | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,686,985,308 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 46 | 512,000 | n = int(input())
arr = [0]
arr += list(map(int,input().split()))
flag = False
for i in range(1,n):
temp_arr = [i]
current = arr[i]
for j in range(3):
temp_arr.append(current)
current = arr[current]
if temp_arr[0] == temp_arr[3]:
print("YES")
flag = True
break
if ... | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
n = int(input())
arr = [0]
arr += list(map(int,input().split()))
flag = False
for i in range(1,n):
temp_arr = [i]
current = arr[i]
for j in range(3):
temp_arr.append(current)
current = arr[current]
if temp_arr[0] == temp_arr[3]:
print("YES")
flag = True
... | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,696,780,388 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 184 | 2,560,000 | count=int(input())
t=[]
for i in range(count):
k=list(map(int, input().split()))
t.append(k)
main=0
for i in t:
count=0
for j in i:
if j==1:
count+=1
else:
pass
if count>=2:
main+=1
print(main)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
count=int(input())
t=[]
for i in range(count):
k=list(map(int, input().split()))
t.append(k)
main=0
for i in t:
count=0
for j in i:
if j==1:
count+=1
else:
pass
if count>=2:
main+=1
print(main)
``` | 3 | |
53 | D | Physical Education | PROGRAMMING | 1,500 | [
"sortings"
] | D. Physical Education | 2 | 256 | Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the height of the *i*-th student in the line and *n* is the number of s... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=300) which is the number of students. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) which represent the height of the student occupying the *i*-th place must possess. The third line contains *n* space-separated integers *b**i* (... | In the first line print an integer *k* (0<=≤<=*k*<=≤<=106) which is the number of moves. It is not required to minimize *k* but it must not exceed 106. Then print *k* lines each containing two space-separated integers. Line *p**i*, *p**i*<=+<=1 (1<=≤<=*p**i*<=≤<=*n*<=-<=1) means that Vasya should swap students occupyin... | [
"4\n1 2 3 2\n3 2 1 2\n",
"2\n1 100500\n1 100500\n"
] | [
"4\n2 3\n1 2\n3 4\n2 3\n",
"0\n"
] | none | 2,000 | [
{
"input": "4\n1 2 3 2\n3 2 1 2",
"output": "4\n2 3\n1 2\n3 4\n2 3"
},
{
"input": "2\n1 100500\n1 100500",
"output": "0"
},
{
"input": "3\n652586118 652586118 652586118\n652586118 652586118 652586118",
"output": "3\n2 3\n1 2\n2 3"
},
{
"input": "4\n681106577 681106577 6750771... | 1,652,269,688 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 512,000 | def vasya_and_physcult(count, a_str, b_str):
size = int(count)
a = list(map(int, a_str.split()))
b = list(map(int, b_str.split()))
changes_count = 0
result = ""
for i in range(size):
current_index = i
for j in range(i,size):
if b[j] == a[i]:
c... | Title: Physical Education
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=.... | ```python
def vasya_and_physcult(count, a_str, b_str):
size = int(count)
a = list(map(int, a_str.split()))
b = list(map(int, b_str.split()))
changes_count = 0
result = ""
for i in range(size):
current_index = i
for j in range(i,size):
if b[j] == a[i]:
... | 3.968046 |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,692,610,428 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | '''
==TEST CASE==
Input:
1 7 3 3
Output:
1
'''
s=list(map(int, input().split()))
sum=0
for x in range(len(s)-1):
if s[x+1] == s[x]:
sum+=1
print(sum) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
'''
==TEST CASE==
Input:
1 7 3 3
Output:
1
'''
s=list(map(int, input().split()))
sum=0
for x in range(len(s)-1):
if s[x+1] == s[x]:
sum+=1
print(sum)
``` | 0 | |
276 | A | Lunch Rush | PROGRAMMING | 900 | [
"implementation"
] | null | null | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break.
The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rab... | The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) an... | In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. | [
"2 5\n3 3\n4 5\n",
"4 6\n5 8\n3 6\n2 3\n2 2\n",
"1 5\n1 7\n"
] | [
"4\n",
"3\n",
"-1\n"
] | none | 500 | [
{
"input": "2 5\n3 3\n4 5",
"output": "4"
},
{
"input": "4 6\n5 8\n3 6\n2 3\n2 2",
"output": "3"
},
{
"input": "1 5\n1 7",
"output": "-1"
},
{
"input": "4 9\n10 13\n4 18\n13 3\n10 6",
"output": "13"
},
{
"input": "1 1\n1 1000000000",
"output": "-999999998"
}... | 1,681,585,686 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 186 | 0 | #Keshika Patwari
#Indian Institute Of Technology, Jodhpur
# 2022
import sys
input=sys.stdin.readline
def exe():
return max(l)
n,k=map(int,input().split())
l=[]
for i in range(n):
f,t=map(int,input().split())
if(t>k):
a=f-(t-k)
else:
a=f
l.append(a)
print(exe()) | Title: Lunch Rush
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break.
The Rabbits have a list of *n* restaurants to lunch in: the *i*-th re... | ```python
#Keshika Patwari
#Indian Institute Of Technology, Jodhpur
# 2022
import sys
input=sys.stdin.readline
def exe():
return max(l)
n,k=map(int,input().split())
l=[]
for i in range(n):
f,t=map(int,input().split())
if(t>k):
a=f-(t-k)
else:
a=f
l.append(a)
pr... | 3 | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,638,992,771 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 108 | 0 | n, m = input().split(' ')
n, m = [int(n), int(m)]
days = 0
while True:
if days % m == 0: n+=1
n-=1
if n == 0: break
days+=1
print(days)
| Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
n, m = input().split(' ')
n, m = [int(n), int(m)]
days = 0
while True:
if days % m == 0: n+=1
n-=1
if n == 0: break
days+=1
print(days)
``` | 3 | |
962 | C | Make a Square | PROGRAMMING | 1,400 | [
"brute force",
"implementation",
"math"
] | null | null | You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently ... | The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes. | If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it. | [
"8314\n",
"625\n",
"333\n"
] | [
"2\n",
"0\n",
"-1\n"
] | In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$.
In the second example the given $625$ is the square of the integer $25$, so you should not delete anything.
In the third example it is impossible to make the squa... | 0 | [
{
"input": "8314",
"output": "2"
},
{
"input": "625",
"output": "0"
},
{
"input": "333",
"output": "-1"
},
{
"input": "1881388645",
"output": "6"
},
{
"input": "1059472069",
"output": "3"
},
{
"input": "1354124829",
"output": "4"
},
{
"inpu... | 1,605,779,316 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 545 | 1,331,200 | n = int(input())
d = []
i = 1
ns =str(n)
while i*i<=n:
d.append(i*i)
i+=1
for j in d[::-1]:
if j==n:
print(0)
exit()
else:
c=0
for k in range(len(ns)):
if ns[k]==str(j)[c]:
c+=1
if c==len(str(j)):
... | Title: Make a Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive intege... | ```python
n = int(input())
d = []
i = 1
ns =str(n)
while i*i<=n:
d.append(i*i)
i+=1
for j in d[::-1]:
if j==n:
print(0)
exit()
else:
c=0
for k in range(len(ns)):
if ns[k]==str(j)[c]:
c+=1
if c==len(str(j)):
... | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,593,851,555 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 124 | 0 | import math
n=int(input())
na= ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
e=(int(math.log(math.ceil(n/5),2)))
lo = int(math.ceil((n - 5*(pow(2, e) - 1))/pow(2, e)))
print(na[lo-1]) | 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
import math
n=int(input())
na= ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
e=(int(math.log(math.ceil(n/5),2)))
lo = int(math.ceil((n - 5*(pow(2, e) - 1))/pow(2, e)))
print(na[lo-1])
``` | 3.938 |
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,631,549,424 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 109 | 20,172,800 | s=input()
stack=[]
l=["h","e","l","l","o"]
lcount=2
c=0
for i in s:
if i==l[c]:
if i=="l":
if lcount>0:
stack.append(i)
lcount-=1
if lcount==0:
c+=2
elif (i not in stack):
... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
stack=[]
l=["h","e","l","l","o"]
lcount=2
c=0
for i in s:
if i==l[c]:
if i=="l":
if lcount>0:
stack.append(i)
lcount-=1
if lcount==0:
c+=2
elif (i not in sta... | 3.907925 |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,572,586,442 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 140 | 0 | def jumps(t, s, a):
p=1
j=0
i=0
while i < s:
if p+s-i<=t and int(a[p+s-i-1])==1:
p=p+s-i
j+=1
i=-1
if p==t:
print(j)
return
i+=1
print(-1)
def main():
try:
k=[int(x) for x in input().split('... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
def jumps(t, s, a):
p=1
j=0
i=0
while i < s:
if p+s-i<=t and int(a[p+s-i-1])==1:
p=p+s-i
j+=1
i=-1
if p==t:
print(j)
return
i+=1
print(-1)
def main():
try:
k=[int(x) for x in input... | 3 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,683,530,025 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a , n = map(int , input().split())
s = [""] * a
y = 0
for i in range(a):
if(i % 2 == 0):
s[i] = ['#'] * n
else:
if(y % 2 == 0):
s[i] = ['.'] * (n-1) + ['#']
y+=1
else:
s[i] = ['#'] + ['.'] * (n-1)
y += 1
for i in range(a):
... | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
a , n = map(int , input().split())
s = [""] * a
y = 0
for i in range(a):
if(i % 2 == 0):
s[i] = ['#'] * n
else:
if(y % 2 == 0):
s[i] = ['.'] * (n-1) + ['#']
y+=1
else:
s[i] = ['#'] + ['.'] * (n-1)
y += 1
for i in rang... | 0 | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,606,373,124 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 404 | 2,150,400 | n,m,d=map(int,input().split())
arr=[0]*(n*m)
count=0
for _ in range(n):
a,b=map(int,input().split())
arr[count]=a
arr[count+1]=b
count+=2
arr.sort()
mid=int(len(arr)//2)
steps=0
printed=False
for i in range(n*m):
if i!=mid-1:
if abs(arr[i]-arr[mid-1])%d==0:
steps+=... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
n,m,d=map(int,input().split())
arr=[0]*(n*m)
count=0
for _ in range(n):
a,b=map(int,input().split())
arr[count]=a
arr[count+1]=b
count+=2
arr.sort()
mid=int(len(arr)//2)
steps=0
printed=False
for i in range(n*m):
if i!=mid-1:
if abs(arr[i]-arr[mid-1])%d==0:
... | -1 | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,563,819,358 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | n=int(input())
l=list(map(int,input().split()))
temp=[]
s=sum(l)//(n//2)
i=0
while i<n:
if i in temp:
i+=1
else:
for j in range(i+1,n):
if l[i]+l[j]==s:
print(i+1,j+1,sep=" ")
temp.append(j)
break
i+=1
... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
n=int(input())
l=list(map(int,input().split()))
temp=[]
s=sum(l)//(n//2)
i=0
while i<n:
if i in temp:
i+=1
else:
for j in range(i+1,n):
if l[i]+l[j]==s:
print(i+1,j+1,sep=" ")
temp.append(j)
break
i+=1
... | 0 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,512,823,281 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 156 | 8,089,600 | n = int(input())
lst = map(int, input().split())
anes = sum(lst)
if anes % n:
n -= 1
print(n)
| Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
n = int(input())
lst = map(int, input().split())
anes = sum(lst)
if anes % n:
n -= 1
print(n)
``` | 3 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,694,902,678 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 122 | 0 | n = int(input())
s = list(map(int, input().split()))
g = 0
for i in range(n):
g += s[i]
print(g/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n = int(input())
s = list(map(int, input().split()))
g = 0
for i in range(n):
g += s[i]
print(g/n)
``` | 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,661,966,515 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | a = list(map(int, input().split()))
chance = []
for i in range(7):
if i >= max(a):
chance.append(i)
if len(chance) == 1:
print("0/1")
else:
res = (len(chance)/6).as_integer_ratio()
print(f'{res[0]}/{res[1]}') | 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
a = list(map(int, input().split()))
chance = []
for i in range(7):
if i >= max(a):
chance.append(i)
if len(chance) == 1:
print("0/1")
else:
res = (len(chance)/6).as_integer_ratio()
print(f'{res[0]}/{res[1]}')
``` | 0 |
909 | B | Segments | PROGRAMMING | 1,300 | [
"constructive algorithms",
"math"
] | null | null | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoin... | The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). | Output a single integer - the minimal number of layers required to draw the segments for the given *N*. | [
"2\n",
"3\n",
"4\n"
] | [
"2\n",
"4\n",
"6\n"
] | As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | 1,000 | [
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "4"
},
{
"input": "4",
"output": "6"
},
{
"input": "21",
"output": "121"
},
{
"input": "100",
"output": "2550"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
... | 1,667,312,254 | 454 | PyPy 3 | OK | TESTS | 102 | 93 | 1,433,600 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x = [0] * (n + 1)
for l in range(n):
for r in range(l + 1, n + 1):
x[l] += 1
x[r] -= 1
for i in range(1, n + 1):
x[i] += x[i - 1]
ans = max(x)
print(ans) | Title: Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in se... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x = [0] * (n + 1)
for l in range(n):
for r in range(l + 1, n + 1):
x[l] += 1
x[r] -= 1
for i in range(1, n + 1):
x[i] += x[i - 1]
ans = max(x)
print(ans)
``` | 3 | |
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab... | 1,464,619,435 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 4,608,000 | n = int(input())
c = []
s = 0
p = ''
for i in range(n):
u = input()
c.append([u,len(u)])
if len(u) >= s:
s = len(u)
for i in range(n):
left = s - c[i][1]
c[i].append(c[i][0] + c[i][0][0] * left)
c.sort(key = lambda x:x[2])
for i in range(n):
p += c[i][0]
print(p)
| Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list ... | ```python
n = int(input())
c = []
s = 0
p = ''
for i in range(n):
u = input()
c.append([u,len(u)])
if len(u) >= s:
s = len(u)
for i in range(n):
left = s - c[i][1]
c[i].append(c[i][0] + c[i][0][0] * left)
c.sort(key = lambda x:x[2])
for i in range(n):
p += c[i][0]
print(p)... | 0 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,691,770,292 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | import math
def candle(a, b):
k = a % b
l = a // b
if(a < b):
return a
else:
return a + candle(k + l, b)
if __name__ == '__main__':
_ = input().split()
a = int(_[0])
b = int(_[1])
print(candle(a, b)) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
import math
def candle(a, b):
k = a % b
l = a // b
if(a < b):
return a
else:
return a + candle(k + l, b)
if __name__ == '__main__':
_ = input().split()
a = int(_[0])
b = int(_[1])
print(candle(a, b))
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths betwe... | The first line of input contains the only positive integer *n* (1<=≤<=*n*<=≤<=2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of *n* letters, each being equal either L, or R, or U, or D. *k*-th letter stands for the direction which Robo... | The only line of input should contain the minimum possible length of the sequence. | [
"4\nRURD\n",
"6\nRRULDD\n",
"26\nRRRULURURUULULLLDLDDRDRDLD\n",
"3\nRLL\n",
"4\nLRLR\n"
] | [
"2\n",
"2\n",
"7\n",
"2\n",
"4\n"
] | The illustrations to the first three tests are given below.
<img class="tex-graphics" src="https://espresso.codeforces.com/832fb8f97a482be815e0f87edde26c9791a0d330.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/119a8ba68772b2c2bf76f2acdc58027f6c5cde1... | 0 | [
{
"input": "4\nRURD",
"output": "2"
},
{
"input": "6\nRRULDD",
"output": "2"
},
{
"input": "26\nRRRULURURUULULLLDLDDRDRDLD",
"output": "7"
},
{
"input": "3\nRLL",
"output": "2"
},
{
"input": "4\nLRLR",
"output": "4"
},
{
"input": "5\nLRDLR",
"outpu... | 1,482,658,091 | 1,391 | Python 3 | OK | TESTS | 32 | 124 | 5,222,400 | n = int(input())
s = input()
l = 0
r = 0
u = 0
d = 0
c = 1
for x in s:
if(x=='L'):
if(r==0):
l += 1
else:
c += 1
l = 1
r = 0
u = 0
d = 0
elif(x=='R'):
if(l==0):
r += 1
else:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location b... | ```python
n = int(input())
s = input()
l = 0
r = 0
u = 0
d = 0
c = 1
for x in s:
if(x=='L'):
if(r==0):
l += 1
else:
c += 1
l = 1
r = 0
u = 0
d = 0
elif(x=='R'):
if(l==0):
r += 1
... | 3 | |
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
... | 1,580,401,172 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 124 | 0 | n=int(input())
s=input()
x=[]
c=0
for i in s:
if(i=="B"):
c+=1
else:
if(c!=0):
x.append(c)
c=0
if(c>0):
x.append(c)
if(len(x)>0):
print(len(x))
print(*x)
else:
print(0) | Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the... | ```python
n=int(input())
s=input()
x=[]
c=0
for i in s:
if(i=="B"):
c+=1
else:
if(c!=0):
x.append(c)
c=0
if(c>0):
x.append(c)
if(len(x)>0):
print(len(x))
print(*x)
else:
print(0)
``` | 3 | |
796 | B | Find The Bone | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*.
The problematic bone is initially at the position *x*<==<=1. Zane will co... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.
The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*... | Print one integer — the final position along the *x*-axis of the bone. | [
"7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"5 1 2\n2\n1 2\n2 4\n"
] | [
"1",
"2"
] | In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively.
In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground. | 750 | [
{
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1",
"output": "1"
},
{
"input": "5 1 2\n2\n1 2\n2 4",
"output": "2"
},
{
"input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11",
"output": "55"
},
{
"input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5... | 1,641,860,636 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | str1 = str(input())
n = int(str1.split(' ')[0])
m = int(str1.split(' ')[1])
k = int(str1.split(' ')[2])
str2 = str(input())
Bone = 1
for i in range(k):
if Bone == int(str(input()).split(' ')[0]):
Bone == int(str(input()).split(' ')[1])
if str(Bone) in str2.split(' '):
break
print(Bone) | Title: Find The Bone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t... | ```python
str1 = str(input())
n = int(str1.split(' ')[0])
m = int(str1.split(' ')[1])
k = int(str1.split(' ')[2])
str2 = str(input())
Bone = 1
for i in range(k):
if Bone == int(str(input()).split(' ')[0]):
Bone == int(str(input()).split(' ')[1])
if str(Bone) in str2.split(' '):
break
pr... | -1 | |
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
Ther... | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50... | 1,492,966,281 | 381 | Python 3 | OK | TESTS | 88 | 124 | 14,438,400 | n, k=map(int, input().split())
a=list(map(int, input().split()))
m=min(a)
if any((p-m)%k!=0 for p in a):
print(-1)
else:
print(sum((p-m)//k for p in a))
| Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o... | ```python
n, k=map(int, input().split())
a=list(map(int, input().split()))
m=min(a)
if any((p-m)%k!=0 for p in a):
print(-1)
else:
print(sum((p-m)//k for p in a))
``` | 3 | |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and t... | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he ... | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"outpu... | 1,454,847,685 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | mon=eval(input())
pla=eval(input())
glass=eval(input())
rem=eval(input())
c=0
diff=glass-rem
if(glass<pla):
while(mon>=glass):
c+=1
mon=mon-diff
else:
c=mon//pla
print(c)
| Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much mor... | ```python
mon=eval(input())
pla=eval(input())
glass=eval(input())
rem=eval(input())
c=0
diff=glass-rem
if(glass<pla):
while(mon>=glass):
c+=1
mon=mon-diff
else:
c=mon//pla
print(c)
``` | 0 | |
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicograph... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 ... | 1,617,711,363 | 963 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n,k=map(int, input().split())
a=[[0]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if k>=2 and a[i][j]==0 and i!=j:
a[i][j]=1
a[j][i]=1
k-=2
elif k==1 and i==j:
a[i][j]=1
k-=1
if k!=0:
print(-1)
for l in a:
... | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes... | ```python
n,k=map(int, input().split())
a=[[0]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if k>=2 and a[i][j]==0 and i!=j:
a[i][j]=1
a[j][i]=1
k-=2
elif k==1 and i==j:
a[i][j]=1
k-=1
if k!=0:
print(-1)
for l... | 0 | |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,676,745,251 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 92 | 0 | n=int(input())
j=1
k=n
for i in range(n):
if i%2 ==0:
print(j,end=" ")
j +=1
else:
print(k,end=" ")
k-=1
print("") | Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ... | ```python
n=int(input())
j=1
k=n
for i in range(n):
if i%2 ==0:
print(j,end=" ")
j +=1
else:
print(k,end=" ")
k-=1
print("")
``` | 3.977 |
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,626,603,915 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 6,758,400 | # read a string from input:
s = input()
#initialize a counter:
countU = 0
countL = 0
for c in s:
# check if a character is uppercase:
if c.isupper():
countU += 1
# check if a character is lowercase:
if c.islower():
countL += 1
if countU > countL:
print(s.upper())
else:
print(s... | 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
# read a string from input:
s = input()
#initialize a counter:
countU = 0
countL = 0
for c in s:
# check if a character is uppercase:
if c.isupper():
countU += 1
# check if a character is lowercase:
if c.islower():
countL += 1
if countU > countL:
print(s.upper())
else:
... | 3.956411 |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,563,045,375 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | nmStr = input()
nm = nmStr.split()
n = int(nm[0])
m = int(nm[1])
s = input()
for i in range(m):
lrcStr = input()
lrc = lrcStr.split()
l = int(lrc[0])
r = int(lrc[1])
c1 = lrc[2][0]
c2 = lrc[3][0]
print(l, r, c1, c2)
for j in range(l-1,r):
if s[j] == c1:
s = s[:j] + c... | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
nmStr = input()
nm = nmStr.split()
n = int(nm[0])
m = int(nm[1])
s = input()
for i in range(m):
lrcStr = input()
lrc = lrcStr.split()
l = int(lrc[0])
r = int(lrc[1])
c1 = lrc[2][0]
c2 = lrc[3][0]
print(l, r, c1, c2)
for j in range(l-1,r):
if s[j] == c1:
s =... | 0 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,668,571,403 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 46 | 0 | n,m=map(int, input().split())
temp=""
for i in range(n):
temp=temp+input()
if temp.count('C')>0 or temp.count('M')>0 or temp.count('Y')>0:
print('#Color')
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n,m=map(int, input().split())
temp=""
for i in range(n):
temp=temp+input()
if temp.count('C')>0 or temp.count('M')>0 or temp.count('Y')>0:
print('#Color')
else:
print("#Black&White")
``` | 3 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,651,706,121 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 7,372,800 | n, b, d = list(map(int, input().split()))
sizes = list(map(int, input().split()))
c = 0
p = 0
for i in sizes:
if i < b:
c+=i
if c> d:
c=0
p+=1
print(p) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = list(map(int, input().split()))
sizes = list(map(int, input().split()))
c = 0
p = 0
for i in sizes:
if i < b:
c+=i
if c> d:
c=0
p+=1
print(p)
``` | 0 | |
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,691,357,244 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 5,324,800 | import itertools
n = int(input()) # n = number of stones
v = [int(x) for x in input().split()] # [v] contains n costs of the n stones, cost(i) <- v[i]
v_sorted = v.copy()
v_sorted.sort()
m = int(input()) # m = number of test cases = the number of the next last lines
cumulative_sum = list(itertools.accumulate(v... | 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 itertools
n = int(input()) # n = number of stones
v = [int(x) for x in input().split()] # [v] contains n costs of the n stones, cost(i) <- v[i]
v_sorted = v.copy()
v_sorted.sort()
m = int(input()) # m = number of test cases = the number of the next last lines
cumulative_sum = list(itertools.ac... | 0 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,649,674,662 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 102,400 | from collections import Counter
n=int(input())
s=list(map(int,input().split()))
lst=Counter(s)
print(max(lst.values()),len(lst)) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
from collections import Counter
n=int(input())
s=list(map(int,input().split()))
lst=Counter(s)
print(max(lst.values()),len(lst))
``` | 3.976809 |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,674,823,453 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | number = list(input())
point = 0
count =0
value = 'YES'
while point < len(number):
if number[point] == '1':
point +=1
continue
elif number[point] == '4':
point += 1
count += 1
if count > 2:
value = 'NO'
break
continue
e... | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
number = list(input())
point = 0
count =0
value = 'YES'
while point < len(number):
if number[point] == '1':
point +=1
continue
elif number[point] == '4':
point += 1
count += 1
if count > 2:
value = 'NO'
break
conti... | 0 | |
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,611,651,385 | 2,485 | Python 3 | OK | TESTS | 27 | 249 | 16,588,800 | n=int(input())
a=[int(x) for x in input().split(" ")]
prev,sum1,sum2,l,r=0,0,0,0,n-1
while l<=r:
if sum1<sum2:
sum1+=a[l]
l+=1
elif sum1>sum2:
sum2+=a[r]
r-=1
else:
if l<r:
sum1+=a[l]
sum2+=a[r]
l+=1
r-=1
... | 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())
a=[int(x) for x in input().split(" ")]
prev,sum1,sum2,l,r=0,0,0,0,n-1
while l<=r:
if sum1<sum2:
sum1+=a[l]
l+=1
elif sum1>sum2:
sum2+=a[r]
r-=1
else:
if l<r:
sum1+=a[l]
sum2+=a[r]
l+=1
... | 3 | |
794 | B | Cutting Carrot | PROGRAMMING | 1,200 | [
"geometry",
"math"
] | null | null | Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area.
Formally, the carrot can be viewed as an isosceles tri... | The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105). | The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=<<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=-<=1<=<<=*h* must hold.
Your output will be considered correc... | [
"3 2\n",
"2 100000\n"
] | [
"1.154700538379 1.632993161855\n",
"70710.678118654752\n"
] | Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle). | 1,000 | [
{
"input": "3 2",
"output": "1.154700538379 1.632993161855"
},
{
"input": "2 100000",
"output": "70710.678118654752"
},
{
"input": "1000 100000",
"output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8... | 1,667,015,624 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | from cmath import sqrt
n=int(input())
h=float(input())
for i in range (1,n):
result = h*(i/(sqrt(n)))
print(result)
print("\n")
| Title: Cutting Carrot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cu... | ```python
from cmath import sqrt
n=int(input())
h=float(input())
for i in range (1,n):
result = h*(i/(sqrt(n)))
print(result)
print("\n")
``` | -1 | |
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,582,882,366 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 0 | n = int(input())
x = 0
y = 0
z = 0
for i in range(0,n,1):
a,b,c = input().split()
x = x + int(a)
y = y + int(b)
z = z + int(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
n = int(input())
x = 0
y = 0
z = 0
for i in range(0,n,1):
a,b,c = input().split()
x = x + int(a)
y = y + int(b)
z = z + int(c)
if x==0 and y==0 and z==0:
print("YES")
else:
print("NO")
``` | 3.9455 |
357 | B | Flag Day | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
- overall, there must be *m* dances;- exactly three people must take part in each dance;- each d... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dan... | Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists. | [
"7 3\n1 2 3\n1 4 5\n4 6 7\n",
"9 3\n3 6 9\n2 5 8\n1 4 7\n",
"5 2\n4 1 5\n3 1 2\n"
] | [
"1 2 3 3 2 2 1 \n",
"1 1 1 2 2 2 3 3 3 \n",
"2 3 1 1 3 \n"
] | none | 1,000 | [
{
"input": "7 3\n1 2 3\n1 4 5\n4 6 7",
"output": "1 2 3 3 2 2 1 "
},
{
"input": "9 3\n3 6 9\n2 5 8\n1 4 7",
"output": "1 1 1 2 2 2 3 3 3 "
},
{
"input": "5 2\n4 1 5\n3 1 2",
"output": "2 3 1 1 3 "
},
{
"input": "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12",
"output": "1 ... | 1,381,844,044 | 5,644 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 31 | 307,200 | #FlagDay
data = input().split(" ")
dances = int(data[1])
totalDancers = int(data[0])
dict = {}
for d in range(dances):
dancers = input().split(" ")
dancers = [int(x) for x in dancers]
i = 0
while i<3:
dict.setdefault(dancers[i], i)
if dancers[i] in dict:
if dict[dancers[i]] != i:
print(d... | Title: Flag Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
- ov... | ```python
#FlagDay
data = input().split(" ")
dances = int(data[1])
totalDancers = int(data[0])
dict = {}
for d in range(dances):
dancers = input().split(" ")
dancers = [int(x) for x in dancers]
i = 0
while i<3:
dict.setdefault(dancers[i], i)
if dancers[i] in dict:
if dict[dancers[i]] != i:
... | 0 | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,445,764,205 | 605 | Python 3 | OK | TESTS | 45 | 62 | 0 | l, p , q = int(input()), int(input()), int(input())
print(l * p / (p + q)) | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
l, p , q = int(input()), int(input()), int(input())
print(l * p / (p + q))
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,679,741,295 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | v = int(input())
givers = list(map(int, input().split()))
receivers = [0] * v
for i in range(v):
receivers[givers[i] - 1] = i + 1
print(*receivers)
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
v = int(input())
givers = list(map(int, input().split()))
receivers = [0] * v
for i in range(v):
receivers[givers[i] - 1] = i + 1
print(*receivers)
``` | 3 | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,634,022,950 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 20,172,800 | n=int(input())
ahead=[int(i) for i in range(1,n+1)]
behind=[int(i) for i in range(n,0,-1)]
final=[]
i,j=0,0
while(n!=0):
if n==1:
final.append(behind[i])
i+=1
n-=1
else:
final.append(behind[i])
i+=1
final.append(ahead[j])
j+=1
n-=2
... | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
n=int(input())
ahead=[int(i) for i in range(1,n+1)]
behind=[int(i) for i in range(n,0,-1)]
final=[]
i,j=0,0
while(n!=0):
if n==1:
final.append(behind[i])
i+=1
n-=1
else:
final.append(behind[i])
i+=1
final.append(ahead[j])
j+=1
... | 0 | |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,588,553,851 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 216 | 0 | import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
while m > 0:
flag = False
for i in range(1, n+1):
if m < i:
flag = True
break
m -= i
if flag:
break
print(m) | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
while m > 0:
flag = False
for i in range(1, n+1):
if m < i:
flag = True
break
m -= i
if flag:
break
print(m)
``` | 3.946 |
724 | B | Batch Sort | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | You are given a table consisting of *n* rows and *m* columns.
Numbers in each row form a permutation of integers from 1 to *m*.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are al... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=20) — the number of rows and the number of columns in the given table.
Each of next *n* lines contains *m* integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to *m*. | If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). | [
"2 4\n1 3 2 4\n1 3 4 2\n",
"4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n",
"3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, one can act in the following way:
1. Swap second and third columns. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 4 3 2</center> 1. In the second row, swap the second and the fourth elements. Now the table is <center class="tex-equation">1 2 3 4</... | 1,000 | [
{
"input": "2 4\n1 3 2 4\n1 3 4 2",
"output": "YES"
},
{
"input": "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3",
"output": "NO"
},
{
"input": "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5",
"output": "YES"
},
{
"input": "3 10\n1 2 3 4 5 6 7 10 9 8\n5 2 3 4 1 6 7 8 9 10\n1 2 3 4 5 6... | 1,475,938,861 | 9,961 | Python 3 | OK | TESTS | 86 | 109 | 4,915,200 | from sys import stdin
from sys import stdout
from sys import exit
nm = [int(x) for x in stdin.readline()[:-1].split(' ')]
n = nm[0]
m = nm[1]
matrice = [[] for z in range(n)]
for i in range(n):
matrice[i] = [int(x) for x in stdin.readline()[:-1].split(' ')]
cancomplete = False
a = [[0 for i in range(n)] for j in ra... | Title: Batch Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a table consisting of *n* rows and *m* columns.
Numbers in each row form a permutation of integers from 1 to *m*.
You are allowed to pick two elements in one row and swap them, but no more than once for each ... | ```python
from sys import stdin
from sys import stdout
from sys import exit
nm = [int(x) for x in stdin.readline()[:-1].split(' ')]
n = nm[0]
m = nm[1]
matrice = [[] for z in range(n)]
for i in range(n):
matrice[i] = [int(x) for x in stdin.readline()[:-1].split(' ')]
cancomplete = False
a = [[0 for i in range(n)] f... | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,636,383,326 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 122 | 4,300,800 | n = int(input())
even,odd=0,0
x=[int(i) for i in input().split()]
for i in x:
if i%2==0:
even+=1
else :
odd+=1
print(odd if odd%2==1 else even)
| Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n = int(input())
even,odd=0,0
x=[int(i) for i in input().split()]
for i in x:
if i%2==0:
even+=1
else :
odd+=1
print(odd if odd%2==1 else even)
``` | 3 | |
977 | C | Less or Equal | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$.
Note that the sequence can contain equal elements.
If there is no suc... | The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the sequence itself. | Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$.
If there is no such $x$, print "-1" (without quotes). | [
"7 4\n3 7 5 1 10 3 20\n",
"7 2\n3 7 5 1 10 3 20\n"
] | [
"6",
"-1\n"
] | In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$.
In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ el... | 0 | [
{
"input": "7 4\n3 7 5 1 10 3 20",
"output": "5"
},
{
"input": "7 2\n3 7 5 1 10 3 20",
"output": "-1"
},
{
"input": "1 0\n1",
"output": "-1"
},
{
"input": "1 0\n2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "3 ... | 1,698,404,374 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | il = lambda: map(int, input().split())
def f(n, k, l):
return -1 if l[k-1] == l[k] else l[k-1]
print(f(*il(), sorted(il()))) | Title: Less or Equal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are... | ```python
il = lambda: map(int, input().split())
def f(n, k, l):
return -1 if l[k-1] == l[k] else l[k-1]
print(f(*il(), sorted(il())))
``` | 0 | |
526 | D | Om Nom and Necklace | PROGRAMMING | 2,200 | [
"hashing",
"string suffix structures",
"strings"
] | null | null | One day Om Nom found a thread with *n* beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.
Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular patt... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1<=000<=000) — the number of beads on the thread that Om Nom found and number *k* from the definition of the regular sequence above.
The second line contains the sequence of *n* lowercase Latin letters that represent the colors of the beads. Each color... | Print a string consisting of *n* zeroes and ones. Position *i* (1<=≤<=*i*<=≤<=*n*) must contain either number one if the first *i* beads on the thread form a regular sequence, or a zero otherwise. | [
"7 2\nbcabcab\n",
"21 2\nababaababaababaababaa\n"
] | [
"0000011",
"000110000111111000011"
] | In the first sample test a regular sequence is both a sequence of the first 6 beads (we can take *A* = "", *B* = "bca"), and a sequence of the first 7 beads (we can take *A* = "b", *B* = "ca").
In the second sample test, for example, a sequence of the first 13 beads is regular, if we take *A* = "aba", *B* = "ba". | 1,750 | [
{
"input": "7 2\nbcabcab",
"output": "0000011"
},
{
"input": "21 2\nababaababaababaababaa",
"output": "000110000111111000011"
},
{
"input": "321 2\nabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaab... | 1,694,681,935 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 57 | 140 | 22,528,000 |
def prefix_function(s: str):
n = len(s)
pi = [0] * n
k = 0
for i in range(1, n):
while k > 0 and s[i] != s[k]:
k = pi[k - 1]
if s[i] == s[k]:
k += 1
pi[i] = k
return pi
def z_function(s: str):
n = len(s)
z = [0] * n
l, r = 0, 0
for i in range(1, n):
z[i] = 0 if i >= r els... | Title: Om Nom and Necklace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Om Nom found a thread with *n* beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.
Om Nom knows that his ... | ```python
def prefix_function(s: str):
n = len(s)
pi = [0] * n
k = 0
for i in range(1, n):
while k > 0 and s[i] != s[k]:
k = pi[k - 1]
if s[i] == s[k]:
k += 1
pi[i] = k
return pi
def z_function(s: str):
n = len(s)
z = [0] * n
l, r = 0, 0
for i in range(1, n):
z[i] = 0 if ... | 3 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,660,294,328 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 409,600 | # Coded By Block_Cipher
import math
import os
import random
import re
import sys
from math import gcd
from math import sqrt
from collections import Counter
# def solve():
n = int(input())
arr = list(map(int,input().split()))
print(len(set(arr)))
# solve() | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
# Coded By Block_Cipher
import math
import os
import random
import re
import sys
from math import gcd
from math import sqrt
from collections import Counter
# def solve():
n = int(input())
arr = list(map(int,input().split()))
print(len(set(arr)))
# solve()
``` | 0 | |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,425,825,567 | 85,167 | Python 3 | OK | TESTS | 36 | 46 | 0 | d = {'polycarp': 1}
n = int(input())
for i in range(n):
s = input().split()
name1, name2 = s[0].lower(), s[2].lower()
x = d[name2]
d[name1] = x + 1
print(max(d.values())) | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
d = {'polycarp': 1}
n = int(input())
for i in range(n):
s = input().split()
name1, name2 = s[0].lower(), s[2].lower()
x = d[name2]
d[name1] = x + 1
print(max(d.values()))
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,607,025,051 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | alphabet = "abcdefghijklmnopqrstuvwxyz"
word = str(input())
if sum([c in alphabet for c in word]) < (len(word)+1) / 2:
print(word.upper())
else:
print(word.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
alphabet = "abcdefghijklmnopqrstuvwxyz"
word = str(input())
if sum([c in alphabet for c in word]) < (len(word)+1) / 2:
print(word.upper())
else:
print(word.lower())
``` | 0 |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,542,808,085 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 3,000 | 512,000 | n = int(input())
lrange = range(1, n + 1)
squares = {x ** 2: x for x in lrange}
res = 0
for x in lrange:
for y in range(x + 1, n + 1):
if (x * x + y * y) in squares:
res += 1
print(res)
| Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
n = int(input())
lrange = range(1, n + 1)
squares = {x ** 2: x for x in lrange}
res = 0
for x in lrange:
for y in range(x + 1, n + 1):
if (x * x + y * y) in squares:
res += 1
print(res)
``` | 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,633,422,535 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 216 | 20,172,800 | s=input()
lower=0
upper=0
for i in s:
if ord(i)<=91:
upper+=1
elif ord(i)<=122:
lower+=1
if upper>lower :
print(s.upper())
else:
print(s.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
lower=0
upper=0
for i in s:
if ord(i)<=91:
upper+=1
elif ord(i)<=122:
lower+=1
if upper>lower :
print(s.upper())
else:
print(s.lower())
``` | 3.908425 |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,679,225,940 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n=input()
c=0
d=0
for i in range(0,len(n)):
if(n[i]=='1'):
if(n[i]!=n[i-1]):
break
c+=1
else:
d+=1
if c>=7 or d>=7 :
print("YES")
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
n=input()
c=0
d=0
for i in range(0,len(n)):
if(n[i]=='1'):
if(n[i]!=n[i-1]):
break
c+=1
else:
d+=1
if c>=7 or d>=7 :
print("YES")
else:
print("NO")
``` | 0 |
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of hi... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be... | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before... | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342... | 1,591,218,549 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 140 | 0 | n = int(input())
ans = 'NO'
for _ in range(n):
a = input().split()
if int(a[1]) >= 2400 and int(a[2]) > int(a[1]):
ans = 'YES'
print(ans) | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ... | ```python
n = int(input())
ans = 'NO'
for _ in range(n):
a = input().split()
if int(a[1]) >= 2400 and int(a[2]) > int(a[1]):
ans = 'YES'
print(ans)
``` | 3 | |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,618,512,615 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 62 | 0 | import sys
input()
s = sys.stdin.read()
x = s.find('OO')
print('NO' if x < 0 else 'YES\n'+s[:x]+'++'+s[x+2:]) | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
import sys
input()
s = sys.stdin.read()
x = s.find('OO')
print('NO' if x < 0 else 'YES\n'+s[:x]+'++'+s[x+2:])
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.