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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,668,339,270 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | n = int(input())
s = list(input())
v = "aeiouy"
def vowel(c):
return not v.find(c) != -1
ans = s[0]
for i in range(1, n):
if vowel(s[i-1]) or vowel(s[i]):
ans += s[i]
print(ans)
| Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
n = int(input())
s = list(input())
v = "aeiouy"
def vowel(c):
return not v.find(c) != -1
ans = s[0]
for i in range(1, n):
if vowel(s[i-1]) or vowel(s[i]):
ans += s[i]
print(ans)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,... | In the first line print single integer — the maximum possible minimum mex.
In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109.
If there are multiple solutio... | [
"5 3\n1 3\n2 5\n4 5\n",
"4 2\n1 4\n2 4\n"
] | [
"2\n1 0 2 1 0\n",
"3\n5 2 0 1"
] | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | 0 | [
{
"input": "5 3\n1 3\n2 5\n4 5",
"output": "2\n0 1 0 1 0"
},
{
"input": "4 2\n1 4\n2 4",
"output": "3\n0 1 2 0"
},
{
"input": "1 1\n1 1",
"output": "1\n0"
},
{
"input": "2 1\n2 2",
"output": "1\n0 0"
},
{
"input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3",
"output":... | 1,639,548,290 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def solve(n,m):
res=n
for i in range(m):
l,r=map(int,input().split())
res=min(res,r-l+1)
ans=[i for i in range(res)]*(n//res+1)
print(res)
print(*ans)
n,m=map(int,input().split())
solve(n,m) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some... | ```python
def solve(n,m):
res=n
for i in range(m):
l,r=map(int,input().split())
res=min(res,r-l+1)
ans=[i for i in range(res)]*(n//res+1)
print(res)
print(*ans)
n,m=map(int,input().split())
solve(n,m)
``` | 0 | |
618 | A | Slime Combining | PROGRAMMING | 800 | [
"implementation"
] | null | null | Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of... | The first line of the input will contain a single integer, *n* (1<=≤<=*n*<=≤<=100<=000). | Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left. | [
"1\n",
"2\n",
"3\n",
"8\n"
] | [
"1\n",
"2\n",
"2 1\n",
"4\n"
] | In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. S... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "8",
"output": "4"
},
{
"input": "100000",
"output": "17 16 11 10 8 6"
},
{
"input": "12345",
"output": "14 13 6 5 4 1"
},
{
"in... | 1,549,692,527 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | f=lambda:map(int,input().split())
n=int(input())
s='1 '*n
for i in range(1,n//2):
s=s.replace(str(i)+' '+str(i),str(i+1))
print(s) | Title: Slime Combining
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, y... | ```python
f=lambda:map(int,input().split())
n=int(input())
s='1 '*n
for i in range(1,n//2):
s=s.replace(str(i)+' '+str(i),str(i+1))
print(s)
``` | 0 | |
121 | A | Lucky Sum | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested ... | The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. | In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2 7\n",
"7 7\n"
] | [
"33\n",
"7\n"
] | In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | 500 | [
{
"input": "2 7",
"output": "33"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "1 9",
"output": "125"
},
{
"input": "4 7",
"output": "25"
},
{
"input": "12 47",
"output": "1593"
},
{
"input": "6 77",
"output": "4012"
},
{
"input": "1 100... | 1,512,192,091 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 62 | 5,632,000 | # your code goes here
arr = input().split()
l = int(arr[0])
r = int(arr[1])
num = '4'
lucky = []
while 1:
lucky.append(int(num))
if int(num) > r:
break
n = len(num)
flag = 0
arr = list(num)
for i in range(n):
if arr[n-i-1] == '4':
flag = 1
i = n-i-1
break
if flag == 1:... | Title: Lucky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *... | ```python
# your code goes here
arr = input().split()
l = int(arr[0])
r = int(arr[1])
num = '4'
lucky = []
while 1:
lucky.append(int(num))
if int(num) > r:
break
n = len(num)
flag = 0
arr = list(num)
for i in range(n):
if arr[n-i-1] == '4':
flag = 1
i = n-i-1
break
if ... | 3 | |
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,610,853,050 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 1,331,200 | import math as m
#from math import comb as nCr
t=input
'''
for _ in range(int(t())):
n=int(t())
a,b=map(int,t().split())
a=list(map(int,t().split()))
'''
ans=[]
n,v=map(int,t().split())
for _ in range(n):
a=list(map(int,t().split()))
cnt=sum(i < v for i in a[1:])
if cnt>0: ans.appe... | 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
import math as m
#from math import comb as nCr
t=input
'''
for _ in range(int(t())):
n=int(t())
a,b=map(int,t().split())
a=list(map(int,t().split()))
'''
ans=[]
n,v=map(int,t().split())
for _ in range(n):
a=list(map(int,t().split()))
cnt=sum(i < v for i in a[1:])
if cnt>0... | 0 | |
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,682,356,116 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n=input()
co=0
if i=='H' or i=='Q' or i=='9' :
print("YES")
else:
print("NO") | 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
n=input()
co=0
if i=='H' or i=='Q' or i=='9' :
print("YES")
else:
print("NO")
``` | -1 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,612,089,878 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 186 | 0 | s = input()
t = input()
i = 0
for x in t:
if s[i] == x:
i += 1
print(i+1)
| Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s = input()
t = input()
i = 0
for x in t:
if s[i] == x:
i += 1
print(i+1)
``` | 3 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,670,848,024 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 186 | 13,312,000 | n,t=map(int,input().split())
l=list(map(int,input().split()))
sm=0
a=0
j=0
for i in range(n):
while j<n and sm+l[j]<=t:
sm+=l[j]
j+=1
a=max(a,j-i)
sm-=l[i]
print(a)
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n,t=map(int,input().split())
l=list(map(int,input().split()))
sm=0
a=0
j=0
for i in range(n):
while j<n and sm+l[j]<=t:
sm+=l[j]
j+=1
a=max(a,j-i)
sm-=l[i]
print(a)
``` | 3 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,652,541,529 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n, x = map(int, input().split())
c = 0
for i in range(int(x**0.5), 0, -1):
if x % i == 0:
if x / i <= n:
c += 1
else:
break
if x == 1 and x == n ** 2:
print(1)
elif int(x ** 0.5) != x ** 0.5:
print(c*2 - 1)
else:
print(c * 2)
| Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
n, x = map(int, input().split())
c = 0
for i in range(int(x**0.5), 0, -1):
if x % i == 0:
if x / i <= n:
c += 1
else:
break
if x == 1 and x == n ** 2:
print(1)
elif int(x ** 0.5) != x ** 0.5:
print(c*2 - 1)
else:
print(c * 2)
``` | 0 | |
670 | D2 | Magic Powder - 2 | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | The term of this problem is the same as the previous one, the only exception — increased restrictions. | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=109) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where the *i*-th number is equal to the number of gram... | Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. | [
"1 1000000000\n1\n1000000000\n",
"10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1 1 1 1 1\n",
"3 1\n2 1 4\n11 3 16\n",
"4 3\n4 3 5 6\n11 12 14 20\n"
] | [
"2000000000\n",
"0\n",
"4\n",
"3\n"
] | none | 500 | [
{
"input": "1 1000000000\n1\n1000000000",
"output": "2000000000"
},
{
"input": "10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3 1\n2 1 4\n11 3 16",
"output": "4"
... | 1,678,051,381 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 873 | 11,673,600 | def f(x):
L=k
for i in range(n):
if(B[i]//A[i]<x):
L=L-(A[i]*x-B[i])
if(L<0):
return True
return False
p=input()
p=p.split()
n=int(p[0])
k=int(p[1])
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
left=0
right=2*(10**9)+1
while(... | Title: Magic Powder - 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The term of this problem is the same as the previous one, the only exception — increased restrictions.
Input Specification:
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*... | ```python
def f(x):
L=k
for i in range(n):
if(B[i]//A[i]<x):
L=L-(A[i]*x-B[i])
if(L<0):
return True
return False
p=input()
p=p.split()
n=int(p[0])
k=int(p[1])
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
left=0
right=2*(10**9)... | 3 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,608,618,419 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 248 | 0 | import sys
input = sys.stdin.readline
a,b,c = map(int, input().split())
z = int((b*c/a)**0.5)
x = b//z
y = a//x
print(4*(x+y+z))
| Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import sys
input = sys.stdin.readline
a,b,c = map(int, input().split())
z = int((b*c/a)**0.5)
x = b//z
y = a//x
print(4*(x+y+z))
``` | 3 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,656,180,475 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 140 | 4,505,600 | n = int(input()) * 2
kaya = sorted(list(map(int, input().split())))
diff = float('inf')
for a in range(n):
for b in range(a+1, n):
k = [kaya[x] for x in range(n) if x != a and x != b]
s = sum([k[y+1] - k[y] for y in range(0, n - 2, 2)])
diff = min(diff, s)
print(diff) | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
n = int(input()) * 2
kaya = sorted(list(map(int, input().split())))
diff = float('inf')
for a in range(n):
for b in range(a+1, n):
k = [kaya[x] for x in range(n) if x != a and x != b]
s = sum([k[y+1] - k[y] for y in range(0, n - 2, 2)])
diff = min(diff, s)
print(diff)
``` | 3 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,598,620,499 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 109 | 307,200 | nm = list(map(int, input().split()))
house = []
for k in range(nm[0]):
house.append(list(map(int, input().split())))
count = 0
for i in range(nm[0]):
for j in range(0, (2 * nm[1]), 2):
if house[i][j] == 1 or house[i][j + 1]:
count += 1
print(count) | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
nm = list(map(int, input().split()))
house = []
for k in range(nm[0]):
house.append(list(map(int, input().split())))
count = 0
for i in range(nm[0]):
for j in range(0, (2 * nm[1]), 2):
if house[i][j] == 1 or house[i][j + 1]:
count += 1
print(count)
``` | 3 | |
514 | C | Watto and Mechanism | PROGRAMMING | 2,000 | [
"binary search",
"data structures",
"hashing",
"string suffix structures",
"strings"
] | null | null | Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism should be able to process queries of the following type: "Given string *s*, determine if the memory of the ... | The first line contains two non-negative numbers *n* and *m* (0<=≤<=*n*<=≤<=3·105, 0<=≤<=*m*<=≤<=3·105) — the number of the initial strings and the number of queries, respectively.
Next follow *n* non-empty strings that are uploaded to the memory of the mechanism.
Next follow *m* non-empty strings that are the querie... | For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes). | [
"2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n"
] | [
"YES\nNO\nNO\n"
] | none | 2,000 | [
{
"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac",
"output": "YES\nNO\nNO"
},
{
"input": "1 5\nacbacbacb\ncbacbacb\nacbacbac\naacbacbacb\nacbacbacbb\nacbaabacb",
"output": "NO\nNO\nNO\nNO\nYES"
},
{
"input": "5 4\nab\ncacab\ncbabc\nacc\ncacab\nabc\naa\nacbca\ncb",
"output": "YE... | 1,688,960,678 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 358 | 18,944,000 | import sys
input=sys.stdin.readline
from hashlib import md5
def hash1(s):
h = md5()
h.update(s.encode())
hash = h.hexdigest()
return hash
n,m=map(int,input().split())
s=set()
for i in range(n):
x=input()
for i in range(len(x)-1):
s.add(hash1((x[:i]+x[i+1:])))
for i in ran... | Title: Watto and Mechanism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism sh... | ```python
import sys
input=sys.stdin.readline
from hashlib import md5
def hash1(s):
h = md5()
h.update(s.encode())
hash = h.hexdigest()
return hash
n,m=map(int,input().split())
s=set()
for i in range(n):
x=input()
for i in range(len(x)-1):
s.add(hash1((x[:i]+x[i+1:])))
fo... | 0 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,586,302,354 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | nineteen = str(input())
dict = {}
for i in nineteen:
if i in dict:
dict[i] += 1
else:
dict[i] = 1
#print(dict) #nineteen 2n, 1i, 1t, 3,e
x = min(min(min(dict['n']/2, dict['i']), dict['t']), dict['e']/3)
print(x) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
nineteen = str(input())
dict = {}
for i in nineteen:
if i in dict:
dict[i] += 1
else:
dict[i] = 1
#print(dict) #nineteen 2n, 1i, 1t, 3,e
x = min(min(min(dict['n']/2, dict['i']), dict['t']), dict['e']/3)
print(x)
``` | 0 | |
691 | C | Exponential notation | PROGRAMMING | 1,800 | [
"implementation",
"strings"
] | null | null | You are given a positive decimal number *x*.
Your task is to convert it to the "simple exponential notation".
Let *x*<==<=*a*·10*b*, where 1<=≤<=*a*<=<<=10, then in general case the "simple exponential notation" looks like "aEb". If *b* equals to zero, the part "Eb" should be skipped. If *a* is an integer, it shou... | The only line contains the positive decimal number *x*. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other. | Print the only line — the "simple exponential notation" of the given number *x*. | [
"16\n",
"01.23400\n",
".100\n",
"100.\n"
] | [
"1.6E1\n",
"1.234\n",
"1E-1\n",
"1E2\n"
] | none | 0 | [
{
"input": "16",
"output": "1.6E1"
},
{
"input": "01.23400",
"output": "1.234"
},
{
"input": ".100",
"output": "1E-1"
},
{
"input": "100.",
"output": "1E2"
},
{
"input": "9000",
"output": "9E3"
},
{
"input": "0.0012",
"output": "1.2E-3"
},
{
... | 1,587,121,379 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 124 | 6,451,200 | s = input()
if not '.' in s: s += '.'
a,b = s.strip('0').split('.')
if len(a) > 0:
b = (a[1:] + b).rstrip('0')
le = len(a)-1
a = a[0]
else:
le = len(b.strip('0')) - len(b) - 1
b = b.strip('0').rstrip('0')
a = b[0]
b = b[1:]
print(a,end='')
if len(b): print('.' + b,end='')
if le : print('E... | Title: Exponential notation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a positive decimal number *x*.
Your task is to convert it to the "simple exponential notation".
Let *x*<==<=*a*·10*b*, where 1<=≤<=*a*<=<<=10, then in general case the "simple exponential notatio... | ```python
s = input()
if not '.' in s: s += '.'
a,b = s.strip('0').split('.')
if len(a) > 0:
b = (a[1:] + b).rstrip('0')
le = len(a)-1
a = a[0]
else:
le = len(b.strip('0')) - len(b) - 1
b = b.strip('0').rstrip('0')
a = b[0]
b = b[1:]
print(a,end='')
if len(b): print('.' + b,end='')
if le ... | 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,574,619,237 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | n=input()
h=0
e=0
l=0
o=0
if len(n)<=5 or "h" not in n or "e" not in n or "l" not in n or "o" not in n:
print("NO")
elif "h" in n and "e" in n and "l" in n and "o" in n:
for i in range (len(n)):
if n[i]=="h":
h+=1
if n[i]=="e":
e+=1
if n[i]=="l":
... | 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
n=input()
h=0
e=0
l=0
o=0
if len(n)<=5 or "h" not in n or "e" not in n or "l" not in n or "o" not in n:
print("NO")
elif "h" in n and "e" in n and "l" in n and "o" in n:
for i in range (len(n)):
if n[i]=="h":
h+=1
if n[i]=="e":
e+=1
if n[i]=... | 0 |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,683,531,640 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=int(input())
x=n%4
y=pow(8,x)
print(str(y)[-1])
| Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n=int(input())
x=n%4
y=pow(8,x)
print(str(y)[-1])
``` | 0 | |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,622,133,566 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | n=int(input())
s1=0
s11=0
s2=0
s22=0
for i in range(n):
t,x,y=map(int,input().split())
if t==1:
s1+=x
s11+=y
else:
s2+=x
s22+=y
if s1>=(s11)/2:
print("LIVE")
else:
print("DEAD")
if s2>=s22/2:
print("LIVE")
else:
print("DEAD")... | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
n=int(input())
s1=0
s11=0
s2=0
s22=0
for i in range(n):
t,x,y=map(int,input().split())
if t==1:
s1+=x
s11+=y
else:
s2+=x
s22+=y
if s1>=(s11)/2:
print("LIVE")
else:
print("DEAD")
if s2>=s22/2:
print("LIVE")
else:
pri... | 0 | |
440 | A | Forgotten Episode | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watch... | Print the number of the episode that Polycarpus hasn't watched. | [
"10\n3 8 10 1 7 9 6 5 2\n"
] | [
"4\n"
] | none | 500 | [
{
"input": "10\n3 8 10 1 7 9 6 5 2",
"output": "4"
},
{
"input": "5\n4 3 2 1",
"output": "5"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "2\n2",
"output": "1"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "3\n1 3",
"output": "2"
},
... | 1,616,786,834 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 93 | 7,065,600 | n = int(input())
arr = list(map(int, input().split()))
ans = n *(n+1)//2 - sum(arr)
print(ans)
| Title: Forgotten Episode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episo... | ```python
n = int(input())
arr = list(map(int, input().split()))
ans = n *(n+1)//2 - sum(arr)
print(ans)
``` | 3 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,497,172,204 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 307,200 | import sys
import math
inf = 100000000
n = int(input())
a = [int(e) for e in input().split()]
f = [[0, 0, 0] for i in range(n)]
m = inf
f[0][0] = 1
if a[0] == 1 or a[0] == 3:
f[0][1] = 0
else:
f[0][1] = inf
if a[0] == 2 or a[0] == 3:
f[0][2] = 0
else:
f[0][2] = inf
if a[0] == 3:
f[0][1] = f[0][2] = inf
for i in ... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
import sys
import math
inf = 100000000
n = int(input())
a = [int(e) for e in input().split()]
f = [[0, 0, 0] for i in range(n)]
m = inf
f[0][0] = 1
if a[0] == 1 or a[0] == 3:
f[0][1] = 0
else:
f[0][1] = inf
if a[0] == 2 or a[0] == 3:
f[0][2] = 0
else:
f[0][2] = inf
if a[0] == 3:
f[0][1] = f[0][2] = inf... | 0 | |
851 | A | Arpa and a research in Mexican wave | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-t... | The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=<<=*n*<=+<=*k*). | Print single integer: how many spectators are standing at time *t*. | [
"10 5 3\n",
"10 5 7\n",
"10 5 12\n"
] | [
"3\n",
"5\n",
"3\n"
] | In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
- At *t* = 0 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spe... | 500 | [
{
"input": "10 5 3",
"output": "3"
},
{
"input": "10 5 7",
"output": "5"
},
{
"input": "10 5 12",
"output": "3"
},
{
"input": "840585600 770678331 788528791",
"output": "770678331"
},
{
"input": "25462281 23343504 8024619",
"output": "8024619"
},
{
"in... | 1,650,016,685 | 2,147,483,647 | Python 3 | OK | TESTS | 166 | 46 | 0 | n, k, t = map(int, input().split())
print(t if t <= k else k if k < t < n else n+k-t)
| Title: Arpa and a research in Mexican wave
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2,... | ```python
n, k, t = map(int, input().split())
print(t if t <= k else k if k < t < n else n+k-t)
``` | 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,552,334,858 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 11 14:00:39 2019
@author: wuser
"""
P = input()
low=0
May=0
for x in P:
if x == x.lower():
low+=1
else :
May+=1
if May > low:
print(P.upper())
else:
print(P.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 11 14:00:39 2019
@author: wuser
"""
P = input()
low=0
May=0
for x in P:
if x == x.lower():
low+=1
else :
May+=1
if May > low:
print(P.upper())
else:
print(P.lower())
``` | 3.9455 |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,567,178,855 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | (k,m,n,o,x)=map(int,input().split())
count1=k*m+2*o
count2=k*n+2*x
if count2>count1:
print("First")
if count1>count2:
print("Second")
if count1==count2:
print("Friendship")
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
(k,m,n,o,x)=map(int,input().split())
count1=k*m+2*o
count2=k*n+2*x
if count2>count1:
print("First")
if count1>count2:
print("Second")
if count1==count2:
print("Friendship")
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,606,199,335 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 216 | 307,200 | n = int(input())
f = list(map(int,input().split()))
fr = len(f)+1
ways = [1,2,3,4,5]
ss = sum(f)
r = list(range(1,ss+6))
for _ in range(0,len(r),fr):
r[_]=''
c = 0
for i in range(len(r)):
if r[i]!='' and r[i]>ss:
c+=1
print(c) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())
f = list(map(int,input().split()))
fr = len(f)+1
ways = [1,2,3,4,5]
ss = sum(f)
r = list(range(1,ss+6))
for _ in range(0,len(r),fr):
r[_]=''
c = 0
for i in range(len(r)):
if r[i]!='' and r[i]>ss:
c+=1
print(c)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a c... | The first line contains single integer *n* (3<=≤<=*n*<=≤<=2·105) — the number of squares in the park.
Each of the next (*n*<=-<=1) lines contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other u... | In the first line print single integer *k* — the minimum number of colors Andryusha has to use.
In the second line print *n* integers, the *i*-th of them should be equal to the balloon color on the *i*-th square. Each of these numbers should be within range from 1 to *k*. | [
"3\n2 3\n1 3\n",
"5\n2 3\n5 3\n4 3\n1 3\n",
"5\n2 1\n3 2\n4 3\n5 4\n"
] | [
"3\n1 3 2 ",
"5\n1 3 2 5 4 ",
"3\n1 2 3 1 2 "
] | In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.
In the second example there are following triples of consequently connected squares:
- 1 → 3 → 2 - 1 → 3 → 4 - 1 → 3 → 5 - 2 → 3 → 4 - 2 → 3 → 5 - 4 → 3 → 5
In the third example there are following... | 0 | [
{
"input": "3\n2 3\n1 3",
"output": "3\n1 3 2 "
},
{
"input": "5\n2 3\n5 3\n4 3\n1 3",
"output": "5\n1 3 2 5 4 "
},
{
"input": "5\n2 1\n3 2\n4 3\n5 4",
"output": "3\n1 2 3 1 2 "
},
{
"input": "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2",
"output": "5\n1 2 1 3 2 1 2 ... | 1,488,722,502 | 3,402 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 40 | 2,000 | 56,115,200 | import sys
def input():
return sys.stdin.readline()
n = int(input())
colors = [0 for _ in range(n+1)]
children = [list() for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
children[a].append(b)
children[b].append(a)
# находим какую-нибудь вершину с одним ребенко... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way th... | ```python
import sys
def input():
return sys.stdin.readline()
n = int(input())
colors = [0 for _ in range(n+1)]
children = [list() for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
children[a].append(b)
children[b].append(a)
# находим какую-нибудь вершину с одн... | 0 | |
316 | A2 | Special Task | PROGRAMMING | 1,400 | [
"math"
] | null | null | Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get th... | The first line contains string *s* — the hint to the safe code. String *s* consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string *s* doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
- 1<=≤<=|*s*|<=≤<=5.
The input limits for s... | Print the number of codes that match the given hint. | [
"AJ\n",
"1?AA\n"
] | [
"81\n",
"100\n"
] | none | 70 | [
{
"input": "AJ",
"output": "81"
},
{
"input": "1?AA",
"output": "100"
},
{
"input": "?",
"output": "9"
},
{
"input": "7",
"output": "1"
},
{
"input": "A",
"output": "9"
},
{
"input": "BBB?",
"output": "90"
},
{
"input": "BC??",
"output"... | 1,589,818,969 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS2 | 23 | 1,000 | 307,200 | a=input()
s={x for x in a if ord(x)>64}
r=10**a.count('?')
for i in range(len(s)):r*=10-i
if ord(a[0])>57:r=r//10*9
print(r) | Title: Special Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expen... | ```python
a=input()
s={x for x in a if ord(x)>64}
r=10**a.count('?')
for i in range(len(s)):r*=10-i
if ord(a[0])>57:r=r//10*9
print(r)
``` | 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,618,193,530 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | start = input()
end = input()
alist = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
startx = alist.index(start[0]) + 1
endx = alist.index(end[0]) + 1
starty = int(start[1])
endy = int(end[1])
xdirection = 0
ydirection = 0
xtimes = 0
ytimes = 0
outputlist = []
if startx > endx:
xdirection = 'L'
... | 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
start = input()
end = input()
alist = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
startx = alist.index(start[0]) + 1
endx = alist.index(end[0]) + 1
starty = int(start[1])
endy = int(end[1])
xdirection = 0
ydirection = 0
xtimes = 0
ytimes = 0
outputlist = []
if startx > endx:
xdirecti... | 0 |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,610,023,289 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 108 | 0 | l, r = map(int, input().split())
if r == l + 1 or r == l:
print(-1)
elif l%2 == 0:
print(l, l+1, l+2)
elif abs(r - l) > 3:
print(l+1, l+2, l+3)
else:
print(-1) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
l, r = map(int, input().split())
if r == l + 1 or r == l:
print(-1)
elif l%2 == 0:
print(l, l+1, l+2)
elif abs(r - l) > 3:
print(l+1, l+2, l+3)
else:
print(-1)
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,693,801,405 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | N,M = map(int,input().split())
res = M*N
print(int(res/2))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
N,M = map(int,input().split())
res = M*N
print(int(res/2))
``` | 3.977 |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,576,328,150 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 | s = input()
def f(s):
n = 0
i = 0
e = 0
t = 0
for j in s:
if j == 'n':
n += 1
elif j == 'i':
i += 1
elif j == 'e':
e += 1
elif j == 't':
t += 1
r = n - n // 2
n = n // 2
e == e // 3
... | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
s = input()
def f(s):
n = 0
i = 0
e = 0
t = 0
for j in s:
if j == 'n':
n += 1
elif j == 'i':
i += 1
elif j == 'e':
e += 1
elif j == 't':
t += 1
r = n - n // 2
n = n // 2
e == ... | 0 | |
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,653,550,797 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 92 | 0 | n = int(input())
a = list(map(int, input().split(' ')))
Sum = 0
Max = 0
for i in range(n):
Sum+=a[i]
k = 0
a = sorted(a)
if Sum%2 == 0:
for i in range(n):
if a[i]%2 == 0:
k+=1
else:
for i in range(n):
if a[i]%2 != 0:
k+=1
print(k)
| 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())
a = list(map(int, input().split(' ')))
Sum = 0
Max = 0
for i in range(n):
Sum+=a[i]
k = 0
a = sorted(a)
if Sum%2 == 0:
for i in range(n):
if a[i]%2 == 0:
k+=1
else:
for i in range(n):
if a[i]%2 != 0:
k+=1
print(k)... | 3 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,697,398,588 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | n = int(input())
total_sum = 0
for i in range(1, n + 1):
term = (-1) ** i * i
# Add the term to the total sum
total_sum += term
print(total_sum)
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n = int(input())
total_sum = 0
for i in range(1, n + 1):
term = (-1) ** i * i
# Add the term to the total sum
total_sum += term
print(total_sum)
``` | 0 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,614,367,726 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 62 | 0 | s=input()
sum=0
for i in range(len(s)):
if s[i]=='Q':
for j in range(i,len(s),1):
if s[j]=='A':
for k in range(j,len(s),1):
if s[k]=='Q':
sum=sum+1
print(sum)
| Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
s=input()
sum=0
for i in range(len(s)):
if s[i]=='Q':
for j in range(i,len(s),1):
if s[j]=='A':
for k in range(j,len(s),1):
if s[k]=='Q':
sum=sum+1
print(sum)
``` | 3 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,619,083,216 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 93 | 0 | # A. Counterexample
n,k=map(int,input().split())
if (n%2!=0):
n+=1
if k-n<2:
print(-1)
else:
print(n,n+1,n+2) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
# A. Counterexample
n,k=map(int,input().split())
if (n%2!=0):
n+=1
if k-n<2:
print(-1)
else:
print(n,n+1,n+2)
``` | 3 | |
91 | A | Newspaper Headline | PROGRAMMING | 1,500 | [
"greedy",
"strings"
] | A. Newspaper Headline | 2 | 256 | A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a n... | The input data contain two lines. The first line contain the heading *s*1, the second line contains the word *s*2. The lines only consist of lowercase Latin letters (1<=≤<=|*s*1|<=≤<=104,<=1<=≤<=|*s*2|<=≤<=106). | If it is impossible to get the word *s*2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings *s*1, which Fangy will need to receive the word *s*2. | [
"abc\nxyz\n",
"abcd\ndabc\n"
] | [
"-1\n",
"2\n"
] | none | 500 | [
{
"input": "abc\nxyz",
"output": "-1"
},
{
"input": "abcd\ndabc",
"output": "2"
},
{
"input": "ab\nbabaaab",
"output": "5"
},
{
"input": "ab\nbaaabba",
"output": "6"
},
{
"input": "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\nhbghjgijijcdafcbgiedichdeebaddfddb",
"ou... | 1,584,004,425 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 92,467,200 | s1, s2= input(), input()
if any([i not in s1 for i in s2]): print(-1)
else:
S1, S2 = map(enumerate,(s1, s2))
inv_map = {}
for k, v in S1:
inv_map[v] = inv_map.get(v, [])
inv_map[v].append(k)
pointer = inv_map[s2[0]][0]
count = 1
for i,j in list(S2)[1:]:
if pointer>=inv_map[j][-1]:
count+=... | Title: Newspaper Headline
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order... | ```python
s1, s2= input(), input()
if any([i not in s1 for i in s2]): print(-1)
else:
S1, S2 = map(enumerate,(s1, s2))
inv_map = {}
for k, v in S1:
inv_map[v] = inv_map.get(v, [])
inv_map[v].append(k)
pointer = inv_map[s2[0]][0]
count = 1
for i,j in list(S2)[1:]:
if pointer>=inv_map[j][-1]:
... | 0 |
583 | B | Robot's Task | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to colle... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. | Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information. | [
"3\n0 2 0\n",
"5\n4 2 3 0 1\n",
"7\n0 3 1 0 5 2 6\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to... | 1,000 | [
{
"input": "3\n0 2 0",
"output": "1"
},
{
"input": "5\n4 2 3 0 1",
"output": "3"
},
{
"input": "7\n0 3 1 0 5 2 6",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "0"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"out... | 1,446,330,977 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 187 | 409,600 | n = int(input())
a = list(map(int, input().split()))
cnt = 0
res = 0
while len(a):
b = []
for i in range(len(a)):
if a[i] <= cnt:
cnt += 1
else:
b.append(a[i])
a = b[::-1]
res += 1
print(res - 1) | Title: Robot's Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The compu... | ```python
n = int(input())
a = list(map(int, input().split()))
cnt = 0
res = 0
while len(a):
b = []
for i in range(len(a)):
if a[i] <= cnt:
cnt += 1
else:
b.append(a[i])
a = b[::-1]
res += 1
print(res - 1)
``` | 3 | |
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consumin... | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf9... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
... | 1,584,638,326 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | import math
n=int(input())
print(1)
print(2)
print(2) | Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 ar... | ```python
import math
n=int(input())
print(1)
print(2)
print(2)
``` | 0 | |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,585,683,897 | 2,147,483,647 | PyPy 3 | OK | TESTS | 159 | 171 | 0 | n=int(input());a=list(map(int,input().split()))
print(abs(a.index(n)-a.index(1))+(max(a.index(n),n-a.index(1)-1) if a.index(n)<a.index(1) else max(a.index(1),n-a.index(n)-1))) | Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
n=int(input());a=list(map(int,input().split()))
print(abs(a.index(n)-a.index(1))+(max(a.index(n),n-a.index(1)-1) if a.index(n)<a.index(1) else max(a.index(1),n-a.index(n)-1)))
``` | 3 | |
828 | A | Restaurant Tables | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the d... | Print the total number of people the restaurant denies service to. | [
"4 1 2\n1 2 1 1\n",
"4 1 1\n1 1 2 1\n"
] | [
"0\n",
"2\n"
] | In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin... | 500 | [
{
"input": "4 1 2\n1 2 1 1",
"output": "0"
},
{
"input": "4 1 1\n1 1 2 1",
"output": "2"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 1 2\n2 2",
"output": "0"
},
{
"input": "5 1 3\n1 2 2 2 1",
"output": "1"
},
{
"input": "7 6 1\n1 1 1 1 1 1... | 1,600,818,494 | 2,147,483,647 | Python 3 | OK | TESTS | 97 | 202 | 3,993,600 | n, a, b = map(int, input().split())
t = list(map(int,input().split()))
two_with_one = 0
d = 0
for i in t:
if i == 2:
if b > 0:
b -= 1
else:
d += 2
else:
if a > 0:
a -= 1
elif b > 0:
b -= 1
two_with_one += 1
elif two_with_one > 0:
two_with_one ... | Title: Restaurant Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, i... | ```python
n, a, b = map(int, input().split())
t = list(map(int,input().split()))
two_with_one = 0
d = 0
for i in t:
if i == 2:
if b > 0:
b -= 1
else:
d += 2
else:
if a > 0:
a -= 1
elif b > 0:
b -= 1
two_with_one += 1
elif two_with_one > 0:
two... | 3 | |
689 | C | Mike and Chocolate Thieves | PROGRAMMING | 1,700 | [
"binary search",
"combinatorics",
"math"
] | null | null | Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly *k* times more than the previous... | The single line of input contains the integer *m* (1<=≤<=*m*<=≤<=1015) — the number of ways the thieves might steal the chocolates, as rumours say. | Print the only integer *n* — the maximum amount of chocolates that thieves' bags can carry. If there are more than one *n* satisfying the rumors, print the smallest one.
If there is no such *n* for a false-rumoured *m*, print <=-<=1. | [
"1\n",
"8\n",
"10\n"
] | [
"8\n",
"54\n",
"-1\n"
] | In the first sample case the smallest *n* that leads to exactly one way of stealing chocolates is *n* = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest *n* that leads to exactly 8 ways is *n* = 54 with the po... | 1,500 | [
{
"input": "1",
"output": "8"
},
{
"input": "8",
"output": "54"
},
{
"input": "10",
"output": "-1"
},
{
"input": "27",
"output": "152"
},
{
"input": "28206",
"output": "139840"
},
{
"input": "32",
"output": "184"
},
{
"input": "115",
"o... | 1,608,582,093 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 7,372,800 | # todos los k posibles
t = [k ** 3 for k in range(2, 2*10**5)]
# leemos de la entrada
s = m = int(input())
# los limites de la busqueda binaria estan entre los valores posibles de m
a, b = 1, 10**15
# mientras no se crucen los punteros
while b - a > 1:
# vamos al medio de la lista
c = (a + ... | Title: Mike and Chocolate Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thi... | ```python
# todos los k posibles
t = [k ** 3 for k in range(2, 2*10**5)]
# leemos de la entrada
s = m = int(input())
# los limites de la busqueda binaria estan entre los valores posibles de m
a, b = 1, 10**15
# mientras no se crucen los punteros
while b - a > 1:
# vamos al medio de la lista
... | 0 | |
454 | A | Little Pony and Crystal Mine | PROGRAMMING | 800 | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot... | The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | 500 | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**... | 1,588,501,935 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | def solve():
n = int(input())
score = n // 2
lst = []
for i in range(score, -1, -1):
string = "*" * i + "D" * (n - 2*i) + "*" * i
lst.append(string)
for j in lst:
print(j)
for k in lst[1::-1]:
print(k)
solve() | Title: Little Pony and Crystal Mine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You ... | ```python
def solve():
n = int(input())
score = n // 2
lst = []
for i in range(score, -1, -1):
string = "*" * i + "D" * (n - 2*i) + "*" * i
lst.append(string)
for j in lst:
print(j)
for k in lst[1::-1]:
print(k)
solve()
``` | 0 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,415,027,639 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | import sys
import math
def nod(a, b):
if(b == 0):
return a
r = a % b
return nod(b, r)
l, r = [int(x) for x in (sys.stdin.readline()).split()]
res = []
if(r - l < 2):
print(-1)
else:
res.append(str(l))
res.append(str(l + 1))
for i in range(l + 2, r + 1):
i... | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
import sys
import math
def nod(a, b):
if(b == 0):
return a
r = a % b
return nod(b, r)
l, r = [int(x) for x in (sys.stdin.readline()).split()]
res = []
if(r - l < 2):
print(-1)
else:
res.append(str(l))
res.append(str(l + 1))
for i in range(l + 2, r + 1):
... | 0 | |
900 | A | Find Extra One | PROGRAMMING | 800 | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. | Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | 500 | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1... | 1,521,062,384 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 265 | 9,318,400 | x = [int(input().split()[0]) for _ in range(int(input()))]
x = [i//abs(i) for i in x]
print("Yes" if min(x.count(-1), x.count(1))<2 else "No") | Title: Find Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
Input Specification:
The first li... | ```python
x = [int(input().split()[0]) for _ in range(int(input()))]
x = [i//abs(i) for i in x]
print("Yes" if min(x.count(-1), x.count(1))<2 else "No")
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,654,254,171 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s = input()
t = input()
isSame = True
for i in range(len(s)):
if s[i] != t[len(t) - 1 - i]:
isSame = False
break
if isSame:
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s = input()
t = input()
isSame = True
for i in range(len(s)):
if s[i] != t[len(t) - 1 - i]:
isSame = False
break
if isSame:
print("YES")
else:
print("NO")
``` | 3.977 |
1,007 | A | Reorder the Array | PROGRAMMING | 1,300 | [
"combinatorics",
"data structures",
"math",
"sortings",
"two pointers"
] | null | null | You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can ... | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. | Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. | [
"7\n10 1 1 1 5 5 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"0\n"
] | In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0. | 500 | [
{
"input": "7\n10 1 1 1 5 5 3",
"output": "4"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000",
"output": "3"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "1\n1",
... | 1,591,719,800 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 109 | 409,600 | from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
c = Counter(arr)
Max = 0
print(c)
for key, val in c.items():
if val > Max:
Max = val
print(n-Max)
| Title: Reorder the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find t... | ```python
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
c = Counter(arr)
Max = 0
print(c)
for key, val in c.items():
if val > Max:
Max = val
print(n-Max)
``` | 0 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,693,582,837 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 124 | 1,331,200 | n = int(input())
b = sorted(list(map(int, input().split())))[::-1]
a = []
i = 0
while sum(b) >= sum(a):
a.append(b[i])
b[i] = 0
i += 1
print(len(a)) | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n = int(input())
b = sorted(list(map(int, input().split())))[::-1]
a = []
i = 0
while sum(b) >= sum(a):
a.append(b[i])
b[i] = 0
i += 1
print(len(a))
``` | 3 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,574,103,863 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 218 | 0 | import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
def solve():
n, m = read_tuple(int)
c = {}
for _ in range(m):
a, b = read_tuple(int)
c[b] = c.get(b, 0) + a
ans = 0
for b_i in sorted(c, reverse=True):
if n... | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
def solve():
n, m = read_tuple(int)
c = {}
for _ in range(m):
a, b = read_tuple(int)
c[b] = c.get(b, 0) + a
ans = 0
for b_i in sorted(c, reverse=True):
... | 3 |
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu... | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 ... | 1,515,023,030 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 5,529,600 | a, m = map(int, input().split())
x = a
while x != 0:
x += x % m
x %= m
if x == a:
print('No')
break
else:
print('Yes')
| Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the fac... | ```python
a, m = map(int, input().split())
x = a
while x != 0:
x += x % m
x %= m
if x == a:
print('No')
break
else:
print('Yes')
``` | 0 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,674,932,514 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | s = input()
n = s.count("WUB")
s = s.replace("WUB", " ", n)
s = s.strip()
l = len(s)
# print(s)
b = False
for i in range(len(s)):
if(s[i] == " "):
if(b == False):
print(s[i], end = "")
b = True
else:
print("", end = "")
else:
... | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
s = input()
n = s.count("WUB")
s = s.replace("WUB", " ", n)
s = s.strip()
l = len(s)
# print(s)
b = False
for i in range(len(s)):
if(s[i] == " "):
if(b == False):
print(s[i], end = "")
b = True
else:
print("", end = "")
el... | 3 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,684,365,090 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | #Keshika Patwari
#Indian Institute Of Technology, Jodhpur
# # 2022
# import sys
# input=sys.stdin.readline
def exe():
f=0
for i in range(n):
for j in range(m):
if(l[i][j]=='.'):
if((i+j)%2==0):
l[i][j]='W'
else:
... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
#Keshika Patwari
#Indian Institute Of Technology, Jodhpur
# # 2022
# import sys
# input=sys.stdin.readline
def exe():
f=0
for i in range(n):
for j in range(m):
if(l[i][j]=='.'):
if((i+j)%2==0):
l[i][j]='W'
else:
... | 3 | |
612 | B | HDD is Outdated Technology | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read s... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments.
The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector. | Print the only integer — the number of time units needed to read the file. | [
"3\n3 1 2\n",
"5\n1 3 5 4 2\n"
] | [
"3\n",
"10\n"
] | In the second example the head moves in the following way:
- 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time un... | 0 | [
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "5\n1 3 5 4 2",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "40"
... | 1,583,594,381 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 17 | 1,000 | 9,216,000 | n = int(input())
s = input()
a = s.split(sep=' ')
a = [int(x) for x in a]
# done reading
mins = []
while len(mins) <= n:
minim = min(a)
index = a.index(minim)
mins.append((minim, index))
a[index] = 32000
mins = mins[:-1]
s = 0
for item in range(1, len(mins)):
s += abs(mins[item][1] -... | Title: HDD is Outdated Technology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the ... | ```python
n = int(input())
s = input()
a = s.split(sep=' ')
a = [int(x) for x in a]
# done reading
mins = []
while len(mins) <= n:
minim = min(a)
index = a.index(minim)
mins.append((minim, index))
a[index] = 32000
mins = mins[:-1]
s = 0
for item in range(1, len(mins)):
s += abs(mins[... | 0 | |
868 | C | Qualification Rounds | PROGRAMMING | 1,500 | [
"bitmasks",
"brute force",
"constructive algorithms",
"dp"
] | null | null | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset.
*k* experienced teams are participating in the contest. Some of these teams already know some of the prob... | The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams.
Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n",
"3 2\n1 0\n1 1\n0 1\n"
] | [
"NO\n",
"YES\n"
] | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | 1,000 | [
{
"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0",
"output": "NO"
},
{
"input": "3 2\n1 0\n1 1\n0 1",
"output": "YES"
},
{
"input": "10 2\n1 0\n1 0\n0 0\n1 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1",
"output": "YES"
},
{
"input": "10 3\n1 0 0\n0 1 1\n1 0 0\n0 1 0\n0 0 1\n1 0 1\n0 1 1... | 1,517,034,605 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 61 | 530 | 6,963,200 | import math
def l(n,list):
for i in list:
if i>=n:
return True
return False
n,k=map(int,input().split())
a=[1]*k
c=[]
for i in range(n):
b=list(map(int,input().split()))
c.append(b.count(0))
for j in range(k):
a[j]=(a[j] and b[j])
if not(1 in a) and (l(math.... | Title: Qualification Rounds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset.
... | ```python
import math
def l(n,list):
for i in list:
if i>=n:
return True
return False
n,k=map(int,input().split())
a=[1]*k
c=[]
for i in range(n):
b=list(map(int,input().split()))
c.append(b.count(0))
for j in range(k):
a[j]=(a[j] and b[j])
if not(1 in a) an... | 0 | |
793 | D | Presents in Bankopolis | PROGRAMMING | 2,100 | [
"dp",
"graphs",
"shortest paths"
] | null | null | Bankopolis is an incredible city in which all the *n* crossroads are located on a straight line and numbered from 1 to *n* along it. On each crossroad there is a bank office.
The crossroads are connected with *m* oriented bicycle lanes (the *i*-th lane goes from crossroad *u**i* to crossroad *v**i*), the difficulty of... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=80) — the number of crossroads (and offices) and the number of offices Oleg wants to visit.
The second line contains single integer *m* (0<=≤<=*m*<=≤<=2000) — the number of bicycle lanes in Bankopolis.
The next *m* lines contain information about t... | In the only line print the minimum possible total difficulty of the lanes in a valid path, or -1 if there are no valid paths. | [
"7 4\n4\n1 6 2\n6 2 2\n2 4 2\n2 7 1\n",
"4 3\n4\n2 1 2\n1 3 2\n3 4 2\n4 1 1\n"
] | [
"6\n",
"3\n"
] | In the first example Oleg visiting banks by path 1 → 6 → 2 → 4.
Path 1 → 6 → 2 → 7 with smaller difficulity is incorrect because crossroad 2 → 7 passes near already visited office on the crossroad 6.
In the second example Oleg can visit banks by path 4 → 1 → 3. | 2,000 | [
{
"input": "7 4\n4\n1 6 2\n6 2 2\n2 4 2\n2 7 1",
"output": "6"
},
{
"input": "4 3\n4\n2 1 2\n1 3 2\n3 4 2\n4 1 1",
"output": "3"
},
{
"input": "3 2\n10\n2 3 290\n3 1 859\n3 1 852\n1 2 232\n1 2 358\n2 1 123\n1 3 909\n2 1 296\n1 3 119\n1 2 584",
"output": "119"
},
{
"input": "3... | 1,493,981,215 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 77 | 819,200 | import sys
from copy import deepcopy
sys.setrecursionlimit(100000000)
string_lines = sys.stdin.read().split('\n')[:-1]
lines = [list(x) for x in map(lambda line: map(int, line.split(' ')), string_lines)]
n, k = lines.pop(0)
[m] = lines.pop(0)
n += 1 # artificial
edges = [[] for _ in range(n)]
for u_i, v_i,... | Title: Presents in Bankopolis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bankopolis is an incredible city in which all the *n* crossroads are located on a straight line and numbered from 1 to *n* along it. On each crossroad there is a bank office.
The crossroads are connected with *m... | ```python
import sys
from copy import deepcopy
sys.setrecursionlimit(100000000)
string_lines = sys.stdin.read().split('\n')[:-1]
lines = [list(x) for x in map(lambda line: map(int, line.split(' ')), string_lines)]
n, k = lines.pop(0)
[m] = lines.pop(0)
n += 1 # artificial
edges = [[] for _ in range(n)]
for... | 0 | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100... | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,588,951,259 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 6,963,200 | import sys
def data():
return sys.stdin.readline().strip()
def sp(): return map(int, data().split())
def l(): return list(sp())
temp=l()
n=temp[0]
c=temp[1]
prices=l()
m=min(prices)
for i in range(n):
if prices[i]==m:
index=i-1
if c!=0:
print(prices[... | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
import sys
def data():
return sys.stdin.readline().strip()
def sp(): return map(int, data().split())
def l(): return list(sp())
temp=l()
n=temp[0]
c=temp[1]
prices=l()
m=min(prices)
for i in range(n):
if prices[i]==m:
index=i-1
if c!=0:
pri... | 0 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,629,680,845 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 154 | 6,758,400 | x,*y=input().split(' ')
x=int(x)
y=int(*y)
if x==2 and y==5:
print('NO')
else:
counter = sum(y%i==0 for i in range(2, y))
if counter ==0:
print('YES')
else:
print('NO') | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
x,*y=input().split(' ')
x=int(x)
y=int(*y)
if x==2 and y==5:
print('NO')
else:
counter = sum(y%i==0 for i in range(2, y))
if counter ==0:
print('YES')
else:
print('NO')
``` | 0 |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,457,699,912 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 0 | n = int(input())
M = [str(input()) for _ in range(n)]
r = 1
for i in range(n):
for j in range(n):
if M[i][j] == 'x':
a = 0
if i:
a += M[i-1][j] == 'o'
if j:
a += M[i][j-1] == 'o'
if i < n-1:
a += M[i+1][j] == 'o'... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
n = int(input())
M = [str(input()) for _ in range(n)]
r = 1
for i in range(n):
for j in range(n):
if M[i][j] == 'x':
a = 0
if i:
a += M[i-1][j] == 'o'
if j:
a += M[i][j-1] == 'o'
if i < n-1:
a += M[i+1]... | 0 | |
363 | A | Soroban | PROGRAMMING | 800 | [
"implementation"
] | null | null | You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about ... | The first line contains a single integer *n* (0<=≤<=*n*<=<<=109). | Print the description of the decimal digits of number *n* from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal represe... | [
"2\n",
"13\n",
"720\n"
] | [
"O-|OO-OO\n",
"O-|OOO-O\nO-|O-OOO\n",
"O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n"
] | none | 500 | [
{
"input": "2",
"output": "O-|OO-OO"
},
{
"input": "13",
"output": "O-|OOO-O\nO-|O-OOO"
},
{
"input": "720",
"output": "O-|-OOOO\nO-|OO-OO\n-O|OO-OO"
},
{
"input": "0",
"output": "O-|-OOOO"
},
{
"input": "1",
"output": "O-|O-OOO"
},
{
"input": "3",
... | 1,689,254,535 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689254534.940085")# 1689254534.940128 | Title: Soroban
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus develop... | ```python
print("_RANDOM_GUESS_1689254534.940085")# 1689254534.940128
``` | 0 | |
813 | B | The Golden Age | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as the... | The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018). | Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0. | [
"2 3 1 10\n",
"3 5 10 22\n",
"2 3 3 5\n"
] | [
"1\n",
"8\n",
"0\n"
] | In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | 0 | [
{
"input": "2 3 1 10",
"output": "1"
},
{
"input": "3 5 10 22",
"output": "8"
},
{
"input": "2 3 3 5",
"output": "0"
},
{
"input": "2 2 1 10",
"output": "1"
},
{
"input": "2 2 1 1000000",
"output": "213568"
},
{
"input": "2 2 1 1000000000000000000",
... | 1,614,250,468 | 868 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 124 | 1,945,600 | import sys
#import re
#sys.stdin=open('.in','r')
#sys.stdout=open('.out','w')
#import math
#import random
#import time
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
retur... | Title: The Golden Age
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 a... | ```python
import sys
#import re
#sys.stdin=open('.in','r')
#sys.stdout=open('.out','w')
#import math
#import random
#import time
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,587,656,689 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 156 | 0 | n=int(input())
m=list(map(int,input().split()))
e=[]
o=[]
for i in range(n):
if m[i]%2==0:
e.append(n[i])
else:
o.append(n[i])
print(m.index(e[0])+1 if len(e)==1 else m.index(o[0])+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
m=list(map(int,input().split()))
e=[]
o=[]
for i in range(n):
if m[i]%2==0:
e.append(n[i])
else:
o.append(n[i])
print(m.index(e[0])+1 if len(e)==1 else m.index(o[0])+1)
``` | -1 |
848 | E | Days of Floral Colours | PROGRAMMING | 3,400 | [
"combinatorics",
"divide and conquer",
"dp",
"fft",
"math"
] | null | null | The Floral Clock has been standing by the side of Mirror Lake for years. Though unable to keep time, it reminds people of the passage of time and the good old days.
On the rim of the Floral Clock are 2*n* flowers, numbered from 1 to 2*n* clockwise, each of which has a colour among all *n* possible ones. For each colou... | The first and only line of input contains a lonely positive integer *n* (3<=≤<=*n*<=≤<=50<=000) — the number of colours present on the Floral Clock. | Output one integer — the sum of beauty over all possible arrangements of flowers, modulo 998<=244<=353. | [
"3\n",
"4\n",
"7\n",
"15\n"
] | [
"24\n",
"4\n",
"1316\n",
"3436404\n"
] | With *n* = 3, the following six arrangements each have a beauty of 2 × 2 = 4.
While many others, such as the left one in the figure below, have a beauty of 0. The right one is invalid, since it's asymmetric. | 2,500 | [
{
"input": "3",
"output": "24"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "1316"
},
{
"input": "15",
"output": "3436404"
},
{
"input": "10",
"output": "26200"
},
{
"input": "99",
"output": "620067986"
},
{
"input": "1317"... | 1,611,301,061 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 155 | 1,740,800 | f = [0, 4, 8, -1, 16, -10, 4, -12, -48, 26, -44, 15, -16, -4, -4, -1]
jly = 998244353
t = 0
x = [0, 0, 0, 24, 4, 240, 204, 1316, 2988, 6720, 26200, 50248, 174280, 436904, 1140888, 3436404]
n = int(input())
for i in range(16, n + 1):
t = 0
for j in range(0, 16):
t = (t + f[(i - j - 1) & 15] * x[j... | Title: Days of Floral Colours
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Floral Clock has been standing by the side of Mirror Lake for years. Though unable to keep time, it reminds people of the passage of time and the good old days.
On the rim of the Floral Clock are 2*n* flower... | ```python
f = [0, 4, 8, -1, 16, -10, 4, -12, -48, 26, -44, 15, -16, -4, -4, -1]
jly = 998244353
t = 0
x = [0, 0, 0, 24, 4, 240, 204, 1316, 2988, 6720, 26200, 50248, 174280, 436904, 1140888, 3436404]
n = int(input())
for i in range(16, n + 1):
t = 0
for j in range(0, 16):
t = (t + f[(i - j - 1) &... | 3 | |
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,676,714,992 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 716,800 | n, k = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(n)]
mx = -1e9
for i in a:
mx = max(i[0] - i[1] + k if i[1] > k else i[0], mx)
print(mx) | 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
n, k = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(n)]
mx = -1e9
for i in a:
mx = max(i[0] - i[1] + k if i[1] > k else i[0], mx)
print(mx)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,692,574,219 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | t = int(input())
while t > 0:
word = input()
word = word[0] + str(len(word)-2) + word[-1] if len(word) > 10 else word
print(word)
t -= 1 | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
t = int(input())
while t > 0:
word = input()
word = word[0] + str(len(word)-2) + word[-1] if len(word) > 10 else word
print(word)
t -= 1
``` | 3.969 |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,493,315,136 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 62 | 5,529,600 | #!/usr/bin/env python
import sys
def countAndReplace(s,needle,repl):
assert(len(needle) == len(repl))
cnt = 0
offset = 0
while True:
p = s.find(needle,offset)
if -1 == p:
break
cnt += 1
offset = p + len(needle)
s = s[0:p] + repl + s[offset:]
re... | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
#!/usr/bin/env python
import sys
def countAndReplace(s,needle,repl):
assert(len(needle) == len(repl))
cnt = 0
offset = 0
while True:
p = s.find(needle,offset)
if -1 == p:
break
cnt += 1
offset = p + len(needle)
s = s[0:p] + repl + s[offset... | 3 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,680,265,021 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 184 | 13,516,800 | n = int(input())
a = list(map(int,input().split()))
min_el = min(a)
ans = a.count(min_el)
if(ans>1):
print("Still Rozdil")
else:
print(a.index(min_el)+1)
| Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
n = int(input())
a = list(map(int,input().split()))
min_el = min(a)
ans = a.count(min_el)
if(ans>1):
print("Still Rozdil")
else:
print(a.index(min_el)+1)
``` | 3 | |
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,490,740,022 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 62 | 5,529,600 | # Description of the problem can be found at http://codeforces.com/problemset/problem/591/A
l = int(input())
p = int(input())
q = int(input())
print((l / (p + q)) * p) | 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
# Description of the problem can be found at http://codeforces.com/problemset/problem/591/A
l = int(input())
p = int(input())
q = int(input())
print((l / (p + q)) * p)
``` | 3 | |
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T... | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2,... | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr... | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
... | 1,696,436,279 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 608 | 36,352,000 | from bisect import bisect_right
n,q = map(int, input().split())
a = list(map(int, input().split()))
zzz = 1
k = list(map(int, input().split()))
for i in range(1,n):
a[i] = a[i] + a[i-1]
cc=0
for i in k:
cc += i
t = bisect_right(a, cc)
if n!=t:
print(n-t)
else:
print(n)
... | Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line ... | ```python
from bisect import bisect_right
n,q = map(int, input().split())
a = list(map(int, input().split()))
zzz = 1
k = list(map(int, input().split()))
for i in range(1,n):
a[i] = a[i] + a[i-1]
cc=0
for i in k:
cc += i
t = bisect_right(a, cc)
if n!=t:
print(n-t)
else:
... | 3 | |
814 | A | An abandoned sentiment from past | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly ... | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulti... | 500 | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 4... | 1,539,892,950 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 155 | 0 | n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b=sorted(b)
b.reverse()
for i in range(len(b)):
for j in range(len(a)):
if(a[j]==0):
a[j]=b[i]
break
l=0
for i in range(len(a)-1):
if(a[i]<a[i+1]):
l+=1
if(l!=n-1)... | Title: An abandoned sentiment from past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of t... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b=sorted(b)
b.reverse()
for i in range(len(b)):
for j in range(len(a)):
if(a[j]==0):
a[j]=b[i]
break
l=0
for i in range(len(a)-1):
if(a[i]<a[i+1]):
l+=1
... | 3 | |
717 | I | Cowboy Beblop at his computer | PROGRAMMING | 2,800 | [
"geometry"
] | null | null | Cowboy Beblop is a funny little boy who likes sitting at his computer. He somehow obtained two elastic hoops in the shape of 2D polygons, which are not necessarily convex. Since there's no gravity on his spaceship, the hoops are standing still in the air. Since the hoops are very elastic, Cowboy Beblop can stretch, rot... | The first line of input contains an integer *n* (3<=≤<=*n*<=≤<=100<=000), which denotes the number of edges of the first polygon. The next N lines each contain the integers *x*, *y* and *z* (<=-<=1<=000<=000<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — coordinates of the vertices, in the manner mentioned above. The next line... | Your output should contain only one line, with the words "YES" or "NO", depending on whether the two given polygons are well-connected. | [
"4\n0 0 0\n2 0 0\n2 2 0\n0 2 0\n4\n1 1 -1\n1 1 1\n1 3 1\n1 3 -1\n"
] | [
"YES\n"
] | On the picture below, the two polygons are well-connected, as the edges of the vertical polygon cross the area of the horizontal one exactly once in one direction (for example, from above to below), and zero times in the other (in this case, from below to above). Note that the polygons do not have to be parallel to any... | 0 | [
{
"input": "4\n0 0 0\n2 0 0\n2 2 0\n0 2 0\n4\n1 1 -1\n1 1 1\n1 3 1\n1 3 -1",
"output": "YES"
},
{
"input": "4\n4 -2 0\n4 3 0\n-3 3 0\n-3 -2 0\n4\n6 -2 0\n3 2 2\n-3 7 0\n3 4 6",
"output": "NO"
},
{
"input": "4\n-6 6 0\n13 9 0\n15 -7 0\n-5 -5 0\n4\n2 0 4\n2 6 8\n2 12 1\n2 4 -4",
"outpu... | 1,572,886,258 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 124 | 512,000 | import random
a=random.randint(1,25)
if (a<=11):
print("YES")
else:
print("NO")
exit()
#vlvflv | Title: Cowboy Beblop at his computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cowboy Beblop is a funny little boy who likes sitting at his computer. He somehow obtained two elastic hoops in the shape of 2D polygons, which are not necessarily convex. Since there's no gravity on his s... | ```python
import random
a=random.randint(1,25)
if (a<=11):
print("YES")
else:
print("NO")
exit()
#vlvflv
``` | 0 | |
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk... | 1,674,905,874 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import sys
input = sys.stdin.readline
class Solution:
def supSeqPalind(self, s):
first = list(s)
second = list(reversed(first))
return ''.join( first+ second)
sol = Solution()
s = input()
print(sol.supSeqPalind(s))
| Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co... | ```python
import sys
input = sys.stdin.readline
class Solution:
def supSeqPalind(self, s):
first = list(s)
second = list(reversed(first))
return ''.join( first+ second)
sol = Solution()
s = input()
print(sol.supSeqPalind(s))
``` | 0 | |
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,636,858,609 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,505,600 | n, b, d = [int(t) for t in input().split()]
clean = 0
t = 0
a = [int(t) for t in input().split()]
for i in a:
if n > 1:
if i <= b:
t = t + i
if t > d:
clean = clean + 1
print(clean)
| 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 = [int(t) for t in input().split()]
clean = 0
t = 0
a = [int(t) for t in input().split()]
for i in a:
if n > 1:
if i <= b:
t = t + i
if t > d:
clean = clean + 1
print(clean)
``` | 0 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,699,037,183 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 93 | 0 | import math
W=int(input())
if W<=5:
print(1)
else:
print(math.ceil(W/5)) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
import math
W=int(input())
if W<=5:
print(1)
else:
print(math.ceil(W/5))
``` | 3 | |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,485,109,940 | 1,040 | Python 3 | OK | TESTS | 104 | 92 | 4,710,400 | days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
month, day = input().split()
month = int(month)
day = int(day)
columns = days[month-1] - (7 - day + 1)
result = 0
if (columns % 7 != 0):
result += 1
result += columns // 7 + 1
print(result) | Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
month, day = input().split()
month = int(month)
day = int(day)
columns = days[month-1] - (7 - day + 1)
result = 0
if (columns % 7 != 0):
result += 1
result += columns // 7 + 1
print(result)
``` | 3 | |
229 | B | Planets | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"graphs",
"shortest paths"
] | null | null | Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.
Overall the galaxy has *... | The first line contains two space-separated integers: *n* (2<=≤<=*n*<=≤<=105), the number of planets in the galaxy, and *m* (0<=≤<=*m*<=≤<=105) — the number of pairs of planets between which Jack can travel using stargates. Then *m* lines follow, containing three integers each: the *i*-th line contains numbers of plane... | Print a single number — the least amount of time Jack needs to get from planet 1 to planet *n*. If Jack can't get to planet *n* in any amount of time, print number -1. | [
"4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0\n",
"3 1\n1 2 3\n0\n1 3\n0\n"
] | [
"7\n",
"-1\n"
] | In the first sample Jack has three ways to go from planet 1. If he moves to planet 4 at once, he spends 8 seconds. If he transfers to planet 3, he spends 3 seconds, but as other travellers arrive to planet 3 at time 3 and 4, he can travel to planet 4 only at time 5, thus spending 8 seconds in total. But if Jack moves t... | 500 | [
{
"input": "4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0",
"output": "7"
},
{
"input": "3 1\n1 2 3\n0\n1 3\n0",
"output": "-1"
},
{
"input": "2 1\n1 2 3\n0\n1 3",
"output": "3"
},
{
"input": "2 1\n1 2 3\n1 0\n0",
"output": "4"
},
{
"input": "3 3... | 1,684,913,122 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 102,400 | def find(fa,x):
# 不会被卡爆栈的并查集find函数 省空间
fa.setdefault(x,x)
t = x
while fa[x] != x:
x = fa[x]
while t != x:
fa[t], t = x, fa[t]
return x
def union(fa,son, father):
# 数值往坐标高处合并 应该这么写才对
x = find(fa,son)
y = find(fa,father)
fa[x] = y
import sys
input =... | Title: Planets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friend... | ```python
def find(fa,x):
# 不会被卡爆栈的并查集find函数 省空间
fa.setdefault(x,x)
t = x
while fa[x] != x:
x = fa[x]
while t != x:
fa[t], t = x, fa[t]
return x
def union(fa,son, father):
# 数值往坐标高处合并 应该这么写才对
x = find(fa,son)
y = find(fa,father)
fa[x] = y
import sy... | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,680,131,791 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | first = (input())
second = (input())
sol = ""
for i in range(len(first)):
if first[i] == second[i]:
sol+='0'
else:
sol+='1'
print (sol)
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
first = (input())
second = (input())
sol = ""
for i in range(len(first)):
if first[i] == second[i]:
sol+='0'
else:
sol+='1'
print (sol)
``` | 3.9885 |
441 | C | Valera and Tubes | PROGRAMMING | 1,500 | [
"constructive algorithms",
"dfs and similar",
"implementation"
] | null | null | Valera has got a rectangle table consisting of *n* rows and *m* columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row *x* and column *y* by a pair of integers (*x*,<=*y*).
Valera w... | The first line contains three space-separated integers *n*,<=*m*,<=*k* (2<=≤<=*n*,<=*m*<=≤<=300; 2<=≤<=2*k*<=≤<=*n*·*m*) — the number of rows, the number of columns and the number of tubes, correspondingly. | Print *k* lines. In the *i*-th line print the description of the *i*-th tube: first print integer *r**i* (the number of tube cells), then print 2*r**i* integers *x**i*1,<=*y**i*1,<=*x**i*2,<=*y**i*2,<=...,<=*x**ir**i*,<=*y**ir**i* (the sequence of table cells).
If there are multiple solutions, you can print any of the... | [
"3 3 3\n",
"2 3 1\n"
] | [
"3 1 1 1 2 1 3\n3 2 1 2 2 2 3\n3 3 1 3 2 3 3\n",
"6 1 1 1 2 1 3 2 3 2 2 2 1\n"
] | Picture for the first sample:
Picture for the second sample: | 1,500 | [
{
"input": "3 3 3",
"output": "3 1 1 1 2 1 3\n3 2 1 2 2 2 3\n3 3 1 3 2 3 3"
},
{
"input": "2 3 1",
"output": "6 1 1 1 2 1 3 2 3 2 2 2 1"
},
{
"input": "2 3 1",
"output": "6 1 1 1 2 1 3 2 3 2 2 2 1"
},
{
"input": "300 300 2",
"output": "2 1 1 1 2\n89998 1 3 1 4 1 5 1 6 1 7... | 1,465,303,350 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 10 | 436 | 13,926,400 | from collections import defaultdict,deque,Counter,OrderedDict
def main():
n,m,k = map(int,input().split())
l = []
for i in range(1,n+1):
if i%2 == 0:
for j in range(m,0,-1):
l.append((i,j))
else:
for j in range(1,m+1):
l.app... | Title: Valera and Tubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got a rectangle table consisting of *n* rows and *m* columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent ... | ```python
from collections import defaultdict,deque,Counter,OrderedDict
def main():
n,m,k = map(int,input().split())
l = []
for i in range(1,n+1):
if i%2 == 0:
for j in range(m,0,-1):
l.append((i,j))
else:
for j in range(1,m+1):
... | -1 | |
722 | A | Broken Clock | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken ... | The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes. | The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them. | [
"24\n17:30\n",
"12\n17:30\n",
"24\n99:99\n"
] | [
"17:30\n",
"07:30\n",
"09:09\n"
] | none | 500 | [
{
"input": "24\n17:30",
"output": "17:30"
},
{
"input": "12\n17:30",
"output": "07:30"
},
{
"input": "24\n99:99",
"output": "09:09"
},
{
"input": "12\n05:54",
"output": "05:54"
},
{
"input": "12\n00:05",
"output": "01:05"
},
{
"input": "24\n23:80",
... | 1,607,542,706 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 155 | 0 | def f(x):
if(x==0): return("00")
elif(len(str(x))==1): return("0"+str(x))
else: return (str(x))
def ch(a,b):
q=0
for i in range(len(a)): q+=int(a[i]!=b[i])
return q
tf=int(input())
time=[x for x in input().split(':')]
hr12=[]
hr24=[]
mins=[]
for i in range(1,13): hr12.append(f(i... | Title: Broken Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes cha... | ```python
def f(x):
if(x==0): return("00")
elif(len(str(x))==1): return("0"+str(x))
else: return (str(x))
def ch(a,b):
q=0
for i in range(len(a)): q+=int(a[i]!=b[i])
return q
tf=int(input())
time=[x for x in input().split(':')]
hr12=[]
hr24=[]
mins=[]
for i in range(1,13): hr12.... | 3 | |
3 | D | Least Cost Bracket Sequence | PROGRAMMING | 2,600 | [
"greedy"
] | D. Least Cost Bracket Sequence | 1 | 64 | This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequenc... | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow *m* lines, where *m* is the number of characters "?" in the pattern. Each line contains two integer numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=<=*b**i*<=≤<=106), where... | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second.
Print -1, if there is no answer. If the answer is not unique, print any of them. | [
"(??)\n1 2\n2 8\n"
] | [
"4\n()()\n"
] | none | 0 | [
{
"input": "(??)\n1 2\n2 8",
"output": "4\n()()"
},
{
"input": "??\n1 1\n1 1",
"output": "2\n()"
},
{
"input": "(???\n1 1\n1 1\n1 1",
"output": "3\n(())"
},
{
"input": "(??)\n2 1\n1 1",
"output": "2\n()()"
},
{
"input": "(???)?\n3 3\n3 1\n3 3\n2 3",
"output": ... | 1,690,905,996 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 |
if __name__ == "__main__":
l = input().split()
print(4)
print(l[0]) | Title: Least Cost Bracket Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()"... | ```python
if __name__ == "__main__":
l = input().split()
print(4)
print(l[0])
``` | 0 |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
... | 1,622,804,685 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 218 | 0 | n=int(input())
a1=[]
b1=[]
for i in range(n):
a,b=map(int,input().split())
a1.append(a)
b1.append(b)
count=0
for i in range(len(a1)):
if a1[i] in b1:
if i!=b1.index(a1[i]):
count+=1
print(n-count) | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th... | ```python
n=int(input())
a1=[]
b1=[]
for i in range(n):
a,b=map(int,input().split())
a1.append(a)
b1.append(b)
count=0
for i in range(len(a1)):
if a1[i] in b1:
if i!=b1.index(a1[i]):
count+=1
print(n-count)
``` | 0 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,601,042,145 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 248 | 0 | def sleuth(s):
vowels = set()
s = s.replace(" ", "")
lst = ["a","e","i","o","u", "y"]
for vowel in lst:
vowels.add(vowel)
if s[-2].lower() in vowels:
print("YES")
else:
print("NO")
string = input()
sleuth(string)
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
def sleuth(s):
vowels = set()
s = s.replace(" ", "")
lst = ["a","e","i","o","u", "y"]
for vowel in lst:
vowels.add(vowel)
if s[-2].lower() in vowels:
print("YES")
else:
print("NO")
string = input()
sleuth(string)
``` | 3.938 |
822 | C | Hacker, pack your bags! | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"implementation",
"sortings"
] | null | null | It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly *x* days. Y... | The first line contains two integers *n* and *x* (2<=≤<=*n*,<=*x*<=≤<=2·105) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next *n* lines contains three integers *l**i*, *r**i* and *cost**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=2·105,<=1<=≤<=*cost**i*<=≤<=109) —... | Print a single integer — a minimal amount of money that Leha will spend, or print <=-<=1 if it's impossible to choose two disjoint vouchers with the total duration exactly *x*. | [
"4 5\n1 3 4\n1 2 5\n5 6 1\n1 2 4\n",
"3 2\n4 6 3\n2 4 1\n3 5 4\n"
] | [
"5\n",
"-1\n"
] | In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2. | 1,250 | [
{
"input": "4 5\n1 3 4\n1 2 5\n5 6 1\n1 2 4",
"output": "5"
},
{
"input": "3 2\n4 6 3\n2 4 1\n3 5 4",
"output": "-1"
},
{
"input": "2 1855\n159106 161198 437057705\n149039 158409 889963913",
"output": "-1"
},
{
"input": "15 17\n1 10 8\n5 19 1\n12 14 6\n9 19 8\n6 7 3\n5 11 9\n... | 1,695,123,367 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n,x=map(int,input().split())
v=[[]]*(x+1)
for _ in range(n):
s,e,c=list(map(int,input().split()))
if (e-s)+1<=x:
v[(e-s)+1].append([s,e,c])
p=-1
for i in range(n//2):
for s1,e1,c1 in v[i]:
for s2,e2,c2 in v[x-i]:
if e1<s2 or e2<s1:
if p<0 or p >c1+c2:... | Title: Hacker, pack your bags!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha beg... | ```python
n,x=map(int,input().split())
v=[[]]*(x+1)
for _ in range(n):
s,e,c=list(map(int,input().split()))
if (e-s)+1<=x:
v[(e-s)+1].append([s,e,c])
p=-1
for i in range(n//2):
for s1,e1,c1 in v[i]:
for s2,e2,c2 in v[x-i]:
if e1<s2 or e2<s1:
if p<0 or... | 0 | |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,543,960,300 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 124 | 0 | #coding: utf-8
lista = list(map(str,range(1,1001)))
string = ''.join(lista)
n = int(input())
print(string[n-1])
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
#coding: utf-8
lista = list(map(str,range(1,1001)))
string = ''.join(lista)
n = int(input())
print(string[n-1])
``` | 3 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,685,683,446 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,764,800 | location = int(input().split())
distance = 0
location.sort()
distance = location[1]-location[0] + location[2]-location[1]
print(distance)
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
location = int(input().split())
distance = 0
location.sort()
distance = location[1]-location[0] + location[2]-location[1]
print(distance)
``` | -1 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,663,167,975 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | M=int(input())
N=int(input())
if M*N%2==0:
print(int(M*N/2))
else:
print(int((M*N-1)/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M=int(input())
N=int(input())
if M*N%2==0:
print(int(M*N/2))
else:
print(int((M*N-1)/2))
``` | -1 |
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,636,756,551 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 62 | 28,364,800 | a, b = input() + input()[::-1], input() + input()[::-1]
print('YES' if b.replace('X', '') in a.replace('X', '') * 2 else 'NO')
| 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
a, b = input() + input()[::-1], input() + input()[::-1]
print('YES' if b.replace('X', '') in a.replace('X', '') * 2 else 'NO')
``` | 3 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,684,776,311 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 108 | 0 | s = list(map(lambda x: ord(x) - 97, list(input())))
ans = 0
prev = 0
for val in s:
ans += min(abs(prev - val), 26 - abs(prev - val))
prev = val
print(ans) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
s = list(map(lambda x: ord(x) - 97, list(input())))
ans = 0
prev = 0
for val in s:
ans += min(abs(prev - val), 26 - abs(prev - val))
prev = val
print(ans)
``` | 3 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,656,074,408 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | s, v1, v2, t1, t2 = map(int,input().split())
c1 = v1 * s + t1 * 2
c2 = v2 * s + t2 * 2
if c1 < c2:
print('First')
if c1 > c2:
print('Second')
if c1 == c2:
print('Friendship') | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s, v1, v2, t1, t2 = map(int,input().split())
c1 = v1 * s + t1 * 2
c2 = v2 * s + t2 * 2
if c1 < c2:
print('First')
if c1 > c2:
print('Second')
if c1 == c2:
print('Friendship')
``` | 3 | |
383 | A | Milking cows | PROGRAMMING | 1,600 | [
"data structures",
"greedy"
] | null | null | Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity o... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right. | Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4\n0 0 1 0\n",
"5\n1 0 1 0 1\n"
] | [
"1",
"3"
] | In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost. | 500 | [
{
"input": "4\n0 0 1 0",
"output": "1"
},
{
"input": "5\n1 0 1 0 1",
"output": "3"
},
{
"input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0",
"output": "416"
},
{
"input": "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 ... | 1,672,004,270 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 186 | 18,124,800 | from math import inf
from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
sm = [0]
for x in a: sm.append(sm[-1]+x)
ans1 = ans2 = 0
for i in range(1, n+1):
if a[i-1] == 0:
ans1 += sm[i-1]
for i in range(1, n+1):
if a[i-1] == 1:
a... | Title: Milking cows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub... | ```python
from math import inf
from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
sm = [0]
for x in a: sm.append(sm[-1]+x)
ans1 = ans2 = 0
for i in range(1, n+1):
if a[i-1] == 0:
ans1 += sm[i-1]
for i in range(1, n+1):
if a[i-1] == 1:
... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,610,612,975 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 614,400 | #!/usr/bin/env python3
import fileinput
with fileinput.input() as fp:
b1 = fp.readline().strip()
b2 = fp.readline().strip()
b = int(b1,2) ^ int(b2,2)
print(format(b, f'0{len(b1)}b'))
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
#!/usr/bin/env python3
import fileinput
with fileinput.input() as fp:
b1 = fp.readline().strip()
b2 = fp.readline().strip()
b = int(b1,2) ^ int(b2,2)
print(format(b, f'0{len(b1)}b'))
``` | 3.979606 |
929 | A | Прокат велосипедов | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат и... | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=.... | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы доб... | 500 | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},... | 1,520,059,819 | 54,919 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 62 | 5,632,000 | import math
n, k = [int(x) for x in input().split()] #Количество точек, максимальное расстояние, которое мальчик может проехать
x = [int(x) for x in input().split()] #Точки
deltas = [] # Здесь будут расстояния
i = 0
while i<len(x)-1: #Вычисляем расстояния между двумя ближайшими точками
deltas.append(x[i+1]-... | Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся... | ```python
import math
n, k = [int(x) for x in input().split()] #Количество точек, максимальное расстояние, которое мальчик может проехать
x = [int(x) for x in input().split()] #Точки
deltas = [] # Здесь будут расстояния
i = 0
while i<len(x)-1: #Вычисляем расстояния между двумя ближайшими точками
deltas.appe... | 0 | |
593 | A | 2Char | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sendi... | The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct,... | Print a single integer — the maximum possible total length of words in Andrew's article. | [
"4\nabb\ncacc\naaa\nbbb\n",
"5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n"
] | [
"9",
"6"
] | In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}. | 250 | [
{
"input": "4\nabb\ncacc\naaa\nbbb",
"output": "9"
},
{
"input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa",
"output": "6"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\nz\nz",
"output": "2"
},
{
"input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy",
"output"... | 1,446,655,936 | 436 | Python 3 | OK | TESTS | 49 | 77 | 0 | # import sys
# sys.stdin = open("cf593a.in")
alphabet = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
words = [input().strip() for _ in range(n)]
words = [(word, set(word)) for word in words]
words = [(word, s) for word, s in words if len(s) <= 2]
best = 0
for c1 in alphabet:
for c2 in alphabet:
sher... | Title: 2Char
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written an... | ```python
# import sys
# sys.stdin = open("cf593a.in")
alphabet = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
words = [input().strip() for _ in range(n)]
words = [(word, set(word)) for word in words]
words = [(word, s) for word, s in words if len(s) <= 2]
best = 0
for c1 in alphabet:
for c2 in alphabe... | 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,690,836,251 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 216 | 102,400 | import bisect
import math
from collections import Counter
M = (10**9)+7
#t = int(input())
t = 1
for _ in range(t):
n = input()
#n, k = map(int, input().split())
#l = list(map(int, input().split()))
ans = 0
for i in range(len(n)):
if n[i]==n... | 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
import bisect
import math
from collections import Counter
M = (10**9)+7
#t = int(input())
t = 1
for _ in range(t):
n = input()
#n, k = map(int, input().split())
#l = list(map(int, input().split()))
ans = 0
for i in range(len(n)):
... | 3.945809 |
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,594,045,832 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 6,656,000 | a=input()
u,l=0,0
for i in a:
if i.isupper():
u=u+1
if i.islower():
l=l+1
if u>1:
print(a.upper())
elif l>u:
print(a.lower())
elif l==u:
print(a.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
a=input()
u,l=0,0
for i in a:
if i.isupper():
u=u+1
if i.islower():
l=l+1
if u>1:
print(a.upper())
elif l>u:
print(a.lower())
elif l==u:
print(a.lower())
``` | 0 |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,601,785,349 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 155 | 2,764,800 | #https://codeforces.com/problemset/problem/551/A
n=int(input())
l=list(map(int,input().split()))
s=sorted(l,reverse=True)
for i in range(n):
l[i]=s.index(l[i])+1
print(*l)
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
#https://codeforces.com/problemset/problem/551/A
n=int(input())
l=list(map(int,input().split()))
s=sorted(l,reverse=True)
for i in range(n):
l[i]=s.index(l[i])+1
print(*l)
``` | 3 | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,689,994,004 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 204,800 | c=int(input())
b=list(map(int,input().split()))
e=int(input())
a=list(map(int,input().split()))
for i in range(1,len(b)):
b[i]+=b[i-1]
for i in range(len(a)):
l=0
h=len(b)-1
while l<=h:
mid =(l+h)//2
if b[mid]>a[i]:
h = mid - 1
elif b[mid]<a[i]:
... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
c=int(input())
b=list(map(int,input().split()))
e=int(input())
a=list(map(int,input().split()))
for i in range(1,len(b)):
b[i]+=b[i-1]
for i in range(len(a)):
l=0
h=len(b)-1
while l<=h:
mid =(l+h)//2
if b[mid]>a[i]:
h = mid - 1
elif b[mid]<a[i]:... | 0 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,697,283,764 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 108 | 12,697,600 | n = int(input())
array = [int(x) for x in input().split()]
dp = [1]*(n+1)
dp[0] = 0
for i in range(0,n-1):
if array[i+1] > array[i]:
dp[i+2] = dp[i+1] +1
print(max(dp))
| Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n = int(input())
array = [int(x) for x in input().split()]
dp = [1]*(n+1)
dp[0] = 0
for i in range(0,n-1):
if array[i+1] > array[i]:
dp[i+2] = dp[i+1] +1
print(max(dp))
``` | 3 | |
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,630,260,033 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 6,963,200 | n,m=map(int,input().split())
sumi=0
if(m>(n*(n+1)/2)):
rem=m-(n*(n+1)//2)
for i in range(1,rem+1):
if(sumi+i<=rem):
sumi+=i
else:
break
print(rem-sumi)
else:
for i in range(1,m+1):
if(sumi+i<=m):
sumi+=i
... | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
n,m=map(int,input().split())
sumi=0
if(m>(n*(n+1)/2)):
rem=m-(n*(n+1)//2)
for i in range(1,rem+1):
if(sumi+i<=rem):
sumi+=i
else:
break
print(rem-sumi)
else:
for i in range(1,m+1):
if(sumi+i<=m):
sumi+... | 0 |
45 | C | Dancing Lessons | PROGRAMMING | 1,900 | [
"data structures"
] | C. Dancing Lessons | 2 | 256 | There are *n* people taking dancing lessons. Every person is characterized by his/her dancing skill *a**i*. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of people. The next line contains *n* symbols B or G without spaces. B stands for a boy, G stands for a girl. The third line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=107) — the dancing skill. People are specified from left t... | Print the resulting number of couples *k*. Then print *k* lines containing two numerals each — the numbers of people forming the couple. The people are numbered with integers from 1 to *n* from left to right. When a couple leaves to dance you shouldn't renumber the people. The numbers in one couple should be sorted in ... | [
"4\nBGBG\n4 2 4 3\n",
"4\nBBGG\n4 6 1 5\n",
"4\nBGBB\n1 1 2 3\n"
] | [
"2\n3 4\n1 2\n",
"2\n2 3\n1 4\n",
"1\n1 2\n"
] | none | 0 | [
{
"input": "4\nBGBG\n4 2 4 3",
"output": "2\n3 4\n1 2"
},
{
"input": "4\nBBGG\n4 6 1 5",
"output": "2\n2 3\n1 4"
},
{
"input": "4\nBGBB\n1 1 2 3",
"output": "1\n1 2"
},
{
"input": "1\nB\n490297",
"output": "0"
},
{
"input": "2\nBB\n2518190 6313112",
"output": ... | 1,462,286,131 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 2,000 | 34,713,600 | import queue
q = queue.PriorityQueue()
cnt = 0
n = int(input())
sex = input()
a = list(map(int, input().split()))
l = [i-1 for i in range(n)]
r = [i+1 for i in range(n)]
for i in range(n-1):
if sex[i] != sex[i+1]:
q.put((abs(a[i] - a[i+1]), i, i+1))
cnt += 1
ans = []
while True:
if cnt == 0: break
t, i, j = q.ge... | Title: Dancing Lessons
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* people taking dancing lessons. Every person is characterized by his/her dancing skill *a**i*. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a g... | ```python
import queue
q = queue.PriorityQueue()
cnt = 0
n = int(input())
sex = input()
a = list(map(int, input().split()))
l = [i-1 for i in range(n)]
r = [i+1 for i in range(n)]
for i in range(n-1):
if sex[i] != sex[i+1]:
q.put((abs(a[i] - a[i+1]), i, i+1))
cnt += 1
ans = []
while True:
if cnt == 0: break
t, i... | 0 |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,696,428,276 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | m=str(input())
staring=""
for i in range(len(m)):
if i==0:
staring+=m[i].upper()
else:
staring+=m[i]
print(staring) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
m=str(input())
staring=""
for i in range(len(m)):
if i==0:
staring+=m[i].upper()
else:
staring+=m[i]
print(staring)
``` | 3 | |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* — the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,517,136,594 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 61 | 5,632,000 | s = input()
c = s[0]
r = s[1]
total = 8
if c in 'ah' and r in '18':
total -= 5
elif c in 'ah':
total -=3
elif r in '18':
total -=3
print (total) | Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
s = input()
c = s[0]
r = s[1]
total = 8
if c in 'ah' and r in '18':
total -= 5
elif c in 'ah':
total -=3
elif r in '18':
total -=3
print (total)
``` | 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.