contestId
int64
0
1.01k
index
stringclasses
40 values
name
stringlengths
2
54
type
stringclasses
2 values
rating
int64
0
3.4k
tags
listlengths
0
7
title
stringclasses
393 values
time-limit
stringclasses
7 values
memory-limit
stringclasses
6 values
problem-description
stringlengths
0
2.97k
input-specification
stringlengths
4
1.87k
output-specification
stringlengths
4
1.12k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
3.5k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
1 value
testset
stringclasses
9 values
passedTestCount
int64
1
402
timeConsumedMillis
int64
15
8.06k
memoryConsumedBytes
int64
0
514M
code
stringlengths
11
61.4k
prompt
stringlengths
297
7.35k
response
stringlengths
25
61.4k
score
float64
2.82
3.99
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,553,330,643
2,147,483,647
PyPy 3
OK
TESTS
36
140
1,536,000
n = int(input().strip()) arr = list(map(int, input().strip().split())) sArr = sorted(arr, reverse=True) ranks = {sArr[0]: 1} for i in range(1, len(sArr)): if sArr[i] not in ranks: ranks[sArr[i]] = i+1 ans = [ranks[i] for i in arr] print(*ans)
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 n = int(input().strip()) arr = list(map(int, input().strip().split())) sArr = sorted(arr, reverse=True) ranks = {sArr[0]: 1} for i in range(1, len(sArr)): if sArr[i] not in ranks: ranks[sArr[i]] = i+1 ans = [ranks[i] for i in arr] print(*ans) ```
3
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves β€” the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do...
The first line contains integer *n* (1<=≀<=*n*<=≀<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half...
Print a single number β€” the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the...
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n...
1,639,288,657
2,147,483,647
Python 3
OK
TESTS
59
122
0
def solve(n, arr): up = [] lo = [] for x, y in arr: up.append(x) lo.append(y) ans = -1 if sum(up) % 2 != 0 and sum(lo) % 2 != 0: for i in range(n): a, b = 0, 0 a = sum(up) - up[i] + lo[i] b = sum(lo) - up[i] + lo[i] ...
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves β€” the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n...
```python def solve(n, arr): up = [] lo = [] for x, y in arr: up.append(x) lo.append(y) ans = -1 if sum(up) % 2 != 0 and sum(lo) % 2 != 0: for i in range(n): a, b = 0, 0 a = sum(up) - up[i] + lo[i] b = sum(lo) - up[i] + lo[i] ...
3
842
A
Kirill And The Game
PROGRAMMING
1,200
[ "brute force", "two pointers" ]
null
null
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integersΒ β€” amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers ...
First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≀<=*l*<=≀<=*r*<=≀<=107, 1<=≀<=*x*<=≀<=*y*<=≀<=107, 1<=≀<=*k*<=≀<=107).
Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register.
[ "1 10 1 10 1\n", "1 5 6 10 1\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "1 10 1 10 1", "output": "YES" }, { "input": "1 5 6 10 1", "output": "NO" }, { "input": "1 1 1 1 1", "output": "YES" }, { "input": "1 1 1 1 2", "output": "NO" }, { "input": "1 100000 1 100000 100000", "output": "YES" }, { "input": "1 100000 ...
1,695,396,186
2,147,483,647
Python 3
OK
TESTS
101
904
0
l,r,x,y,k=[int(i) for i in input().split()] a=[];b=[];c=[];m=0 for i in range(x,y+1): if (k*i) <=r and (k*i)>=l : print('YES') ; break else : print('NO')
Title: Kirill And The Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integersΒ β€” amount of experience and cost. The efficiency of a potion is the ratio of the...
```python l,r,x,y,k=[int(i) for i in input().split()] a=[];b=[];c=[];m=0 for i in range(x,y+1): if (k*i) <=r and (k*i)>=l : print('YES') ; break else : print('NO') ```
3
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School β„–0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at prog...
The first line contains integer *n* (1<=≀<=*n*<=≀<=5000) β€” the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* β€” the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to...
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output...
1,673,722,477
2,147,483,647
Python 3
OK
TESTS
41
546
0
n = int(input("")) l = list(map(int,input("").split())) a = [l.count(1),l.count(2),l.count(3)] print(min(a)) for i in range(min(a)): print(str(l.index(1) + 1), str(l.index(2) + 1),str(l.index(3) + 1)) x = l.index(1) y = l.index(2) z = l.index(3) l.remove(1);l.insert(x,10) l.remove(2);l.insert(y,10) l....
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School β„–0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)...
```python n = int(input("")) l = list(map(int,input("").split())) a = [l.count(1),l.count(2),l.count(3)] print(min(a)) for i in range(min(a)): print(str(l.index(1) + 1), str(l.index(2) + 1),str(l.index(3) + 1)) x = l.index(1) y = l.index(2) z = l.index(3) l.remove(1);l.insert(x,10) l.remove(2);l.insert(...
3
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,544,192,998
2,147,483,647
Python 3
OK
TESTS
48
124
0
A = input() rev = A[::-1] print( A + rev)
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 A = input() rev = A[::-1] print( A + rev) ```
3
357
B
Flag Day
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
In Berland, there is the national holiday coming β€” the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: - overall, there must be *m* dances;- exactly three people must take part in each dance;- each d...
The first line contains two space-separated integers *n* (3<=≀<=*n*<=≀<=105) and *m* (1<=≀<=*m*<=≀<=105) β€” the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers β€” the numbers of the dan...
Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
[ "7 3\n1 2 3\n1 4 5\n4 6 7\n", "9 3\n3 6 9\n2 5 8\n1 4 7\n", "5 2\n4 1 5\n3 1 2\n" ]
[ "1 2 3 3 2 2 1 \n", "1 1 1 2 2 2 3 3 3 \n", "2 3 1 1 3 \n" ]
none
1,000
[ { "input": "7 3\n1 2 3\n1 4 5\n4 6 7", "output": "1 2 3 3 2 2 1 " }, { "input": "9 3\n3 6 9\n2 5 8\n1 4 7", "output": "1 1 1 2 2 2 3 3 3 " }, { "input": "5 2\n4 1 5\n3 1 2", "output": "2 3 1 1 3 " }, { "input": "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12", "output": "1 ...
1,695,984,121
2,147,483,647
Python 3
OK
TESTS
63
280
2,662,400
n,m=map(int,input().split()) lst=[0 for i in range(n+1)] for j in range(m): dancers=list(map(int,input().split())) color=[lst[dancers[0]],lst[dancers[1]],lst[dancers[2]]] for i in range(3): if(lst[dancers[i]]!=0): continue else: if(1 not in color): ...
Title: Flag Day Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland, there is the national holiday coming β€” the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: - ov...
```python n,m=map(int,input().split()) lst=[0 for i in range(n+1)] for j in range(m): dancers=list(map(int,input().split())) color=[lst[dancers[0]],lst[dancers[1]],lst[dancers[2]]] for i in range(3): if(lst[dancers[i]]!=0): continue else: if(1 not in color): ...
3
278
A
Circle Line
PROGRAMMING
800
[ "implementation" ]
null
null
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ...
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≀<=*d**i*<=≀<=100) β€” the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≀<=*s*,<=*t*<=≀<=*n*) β€”...
Print a single number β€” the length of the shortest path between stations number *s* and *t*.
[ "4\n2 3 4 9\n1 3\n", "4\n5 8 2 100\n4 1\n", "3\n1 1 1\n3 1\n", "3\n31 41 59\n1 1\n" ]
[ "5\n", "15\n", "1\n", "0\n" ]
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of st...
500
[ { "input": "4\n2 3 4 9\n1 3", "output": "5" }, { "input": "4\n5 8 2 100\n4 1", "output": "15" }, { "input": "3\n1 1 1\n3 1", "output": "1" }, { "input": "3\n31 41 59\n1 1", "output": "0" }, { "input": "5\n16 13 10 30 15\n4 2", "output": "23" }, { "inpu...
1,659,170,515
2,147,483,647
PyPy 3-64
OK
TESTS
23
154
0
n=int(input()) l1=[int(i) for i in input().split()] l2=[int(j) for j in input().split()] s=min(l2) t=max(l2) if s==t: print(0) else : l3=[] d=t-s count=0 for k in range(d): count=count+l1[s-1+k] l3.append(count) l3.append(sum(l1)-count) print(min(l3))
Title: Circle Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd...
```python n=int(input()) l1=[int(i) for i in input().split()] l2=[int(j) for j in input().split()] s=min(l2) t=max(l2) if s==t: print(0) else : l3=[] d=t-s count=0 for k in range(d): count=count+l1[s-1+k] l3.append(count) l3.append(sum(l1)-count) prin...
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,693,231,157
2,147,483,647
Python 3
OK
TESTS
49
92
0
def maximum_matches(n, m, containers): containers.sort(key=lambda x: x[1], reverse=True) total_matches = 0 remaining_boxes = n for i in range(m): matchboxes, matches_per_box = containers[i] if remaining_boxes >= matchboxes: total_matches += matchb...
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 def maximum_matches(n, m, containers): containers.sort(key=lambda x: x[1], reverse=True) total_matches = 0 remaining_boxes = n for i in range(m): matchboxes, matches_per_box = containers[i] if remaining_boxes >= matchboxes: total_matches...
3
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
The only string contains space-separated integers *a*, *b* and *n* (1<=≀<=*a*,<=*b*,<=*n*<=≀<=100) β€” the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b...
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "inpu...
1,599,897,806
2,147,483,647
PyPy 3
OK
TESTS
45
280
0
from math import gcd j=0 a,b,c=map(int,input().split()) while c!=0: c-=gcd(a,c) j+=1 if c!=0: c-=gcd(b,c) j+=1 if j%2==0: print(1) else: print(0)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto...
```python from math import gcd j=0 a,b,c=map(int,input().split()) while c!=0: c-=gcd(a,c) j+=1 if c!=0: c-=gcd(b,c) j+=1 if j%2==0: print(1) else: print(0) ```
3
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,651,953,193
2,147,483,647
Python 3
OK
TESTS
19
122
0
s, t = input(), input() moves = 0 for i in range(len(t)): c = t[i] if c == s[moves]: moves = moves + 1 print(moves + 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, t = input(), input() moves = 0 for i in range(len(t)): c = t[i] if c == s[moves]: moves = moves + 1 print(moves + 1) ```
3
609
A
USB Flash Drives
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of USB flash drives. The second line contains positive integer *m* (1<=≀<=*m*<=≀<=105) β€” the size of Sean's file. Each of the next *n* lines contains positive integer *a**i* (1<=≀<=*a**i*<=≀<=1000) β€” the sizes of USB flash drives in megabyt...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
[ "3\n5\n2\n1\n3\n", "3\n6\n2\n3\n2\n", "2\n5\n5\n10\n" ]
[ "2\n", "3\n", "1\n" ]
In the first example Sean needs only two USB flash drives β€” the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive β€” the first or the second.
0
[ { "input": "3\n5\n2\n1\n3", "output": "2" }, { "input": "3\n6\n2\n3\n2", "output": "3" }, { "input": "2\n5\n5\n10", "output": "1" }, { "input": "5\n16\n8\n1\n3\n4\n9", "output": "2" }, { "input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100", "output": "2" ...
1,677,322,590
2,147,483,647
Python 3
OK
TESTS
34
46
0
import bisect as bi from sys import stdin input = stdin.readline def main(): n = int(input()) m = int(input()) l = [] for _ in range(n): q = int(input()) l.append(q) l.sort(reverse = True) w = 0 for i in range(n): m -= l[i] w += 1 if m <= 0: print(w) break ...
Title: USB Flash Drives Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of...
```python import bisect as bi from sys import stdin input = stdin.readline def main(): n = int(input()) m = int(input()) l = [] for _ in range(n): q = int(input()) l.append(q) l.sort(reverse = True) w = 0 for i in range(n): m -= l[i] w += 1 if m <= 0: print(w) bre...
3
789
B
Masha and geometric depression
PROGRAMMING
1,700
[ "brute force", "implementation", "math" ]
null
null
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=&gt;<=1 the respective term satisfi...
The first line of input contains four integers *b*1, *q*, *l*, *m* (-109<=≀<=*b*1,<=*q*<=≀<=109, 1<=≀<=*l*<=≀<=109, 1<=≀<=*m*<=≀<=105)Β β€” the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second lin...
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
[ "3 2 30 4\n6 14 25 48\n", "123 1 2143435 4\n123 11 -5453 141245\n", "123 1 2143435 4\n54343 -13 6 124\n" ]
[ "3", "0", "inf" ]
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed *l* by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer....
1,000
[ { "input": "3 2 30 4\n6 14 25 48", "output": "3" }, { "input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0" }, { "input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf" }, { "input": "3 2 25 2\n379195692 -69874783", "output": "4" }, { "input": "3 2 3...
1,490,818,285
2,147,483,647
Python 3
OK
TESTS
116
93
12,902,400
b, q, l, m = list(map(int, input().split())) a = set(list(map(int, input().split()))) ans = 0 boo = False i = 0 while (i < 34) and (abs(b) <= l): if (b not in a): ans += 1 if i > 31: boo = True b *= q i += 1 if boo: print('inf') else: print(ans)
Title: Masha and geometric depression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric pro...
```python b, q, l, m = list(map(int, input().split())) a = set(list(map(int, input().split()))) ans = 0 boo = False i = 0 while (i < 34) and (abs(b) <= l): if (b not in a): ans += 1 if i > 31: boo = True b *= q i += 1 if boo: print('inf') else: print(ans) `...
3
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean...
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ...
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "outp...
1,697,117,843
2,147,483,647
PyPy 3-64
OK
TESTS
31
62
0
string = "qwertyuiopasdfghjkl;zxcvbnm,./" char = input() inputstring = input() answerstring = "" addition = 1 if char == 'L' else -1 for x in inputstring : num = string.index(x)+addition answerstring += string[num] print(answerstring)
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately....
```python string = "qwertyuiopasdfghjkl;zxcvbnm,./" char = input() inputstring = input() answerstring = "" addition = 1 if char == 'L' else -1 for x in inputstring : num = string.index(x)+addition answerstring += string[num] print(answerstring) ```
3
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*<=&lt;<=*m*<=≀<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≀<=*n*<=&lt;<=*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,526,322,736
2,147,483,647
Python 3
OK
TESTS
45
156
7,065,600
x=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47] a,b=map(int,input().split()) if b in x and x.index(b)-x.index(a)==1: 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=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47] a,b=map(int,input().split()) if b in x and x.index(b)-x.index(a)==1: print('YES') else: print('NO') ```
3.947839
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
The first line contains a non-empty string *s* β€” the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": ...
1,697,132,204
2,147,483,647
Python 3
OK
TESTS
21
62
0
s=input() l=[] for i in s: if i.isdigit(): l.append(i) l.sort() print('+'.join(l))
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak...
```python s=input() l=[] for i in s: if i.isdigit(): l.append(i) l.sort() print('+'.join(l)) ```
3
812
C
Sagheer and Nubian Market
PROGRAMMING
1,500
[ "binary search", "sortings" ]
null
null
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<...
The first line contains two integers *n* and *S* (1<=≀<=*n*<=≀<=105 and 1<=≀<=*S*<=≀<=109)Β β€” the number of souvenirs in the market and Sagheer's budget. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=105)Β β€” the base costs of the souvenirs.
On a single line, print two integers *k*, *T*Β β€” the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs.
[ "3 11\n2 3 5\n", "4 100\n1 2 5 6\n", "1 7\n7\n" ]
[ "2 11\n", "4 54\n", "0 0\n" ]
In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items. In the second example, he can buy all items as they will cost him [5, 10, 17, 22]. In the...
1,500
[ { "input": "3 11\n2 3 5", "output": "2 11" }, { "input": "4 100\n1 2 5 6", "output": "4 54" }, { "input": "1 7\n7", "output": "0 0" }, { "input": "1 7\n5", "output": "1 6" }, { "input": "1 1\n1", "output": "0 0" }, { "input": "4 33\n4 3 2 1", "outp...
1,678,799,520
2,147,483,647
PyPy 3
OK
TESTS
57
358
15,872,000
n,s = map(int,input().split()) a = list(map(int,input().split())) def find(k): # ans = 0 b = [(i+1)*k+a[i] for i in range(n)] b = sorted(b) return sum(b[:k]) l,r = 0,n ans = 0 while l<r: md = (l+r+1)//2 ans = find(md) # print(ans) if ans<=s: l = md else: ...
Title: Sagheer and Nubian Market Time Limit: None seconds Memory Limit: None megabytes Problem Description: On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. T...
```python n,s = map(int,input().split()) a = list(map(int,input().split())) def find(k): # ans = 0 b = [(i+1)*k+a[i] for i in range(n)] b = sorted(b) return sum(b[:k]) l,r = 0,n ans = 0 while l<r: md = (l+r+1)//2 ans = find(md) # print(ans) if ans<=s: l = md ...
3
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. Th...
The first line contains two integers, *n* and *k* (1<=≀<=*n*<=≀<=2000;Β 1<=≀<=*k*<=≀<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≀<=*y**i*<=≀<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number β€” the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0...
1,668,888,357
2,147,483,647
Python 3
OK
TESTS
35
46
0
n, m = [int(i) for i in input().split()] k = [int(i) for i in input().split()] a = [] for i in k: if i +m <= 5: a.append(i) if len(a) < 3: print(0) else: print(len(a)//3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi...
```python n, m = [int(i) for i in input().split()] k = [int(i) for i in input().split()] a = [] for i in k: if i +m <= 5: a.append(i) if len(a) < 3: print(0) else: print(len(a)//3) ```
3
239
A
Two Bags of Potatoes
PROGRAMMING
1,200
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=β‰₯<=1) potatoes, and the second β€” *y* (*y*<=β‰₯<=1) potatoes. Valera β€” very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first...
The first line of input contains three integers *y*, *k*, *n* (1<=≀<=*y*,<=*k*,<=*n*<=≀<=109; <=≀<=105).
Print the list of whitespace-separated integers β€” all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
500
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999...
1,461,759,462
2,147,483,647
Python 3
OK
TESTS
48
592
8,499,200
''' Created on Apr 27, 2016 Gmail : [emailΒ protected] @author: Md. Rezwanul Haque ''' ''' Created on Apr 27, 2016 Gmail : [emailΒ protected] @author: Md. Rezwanul Haque ''' import sys f = sys.stdin # f = open("input.txt", "r") y, k, n = map(int, f.readline().strip().split()) if y >= n: first = -1 e...
Title: Two Bags of Potatoes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=β‰₯<=1) potatoes, and the second β€” *y* (*y*<=β‰₯<=1) potatoes. Valera β€” very scattered boy, so the first bag of potatoes (it contains *x* pota...
```python ''' Created on Apr 27, 2016 Gmail : [emailΒ protected] @author: Md. Rezwanul Haque ''' ''' Created on Apr 27, 2016 Gmail : [emailΒ protected] @author: Md. Rezwanul Haque ''' import sys f = sys.stdin # f = open("input.txt", "r") y, k, n = map(int, f.readline().strip().split()) if y >= n: fir...
3
965
D
Single-use Stones
PROGRAMMING
1,900
[ "binary search", "flows", "greedy", "two pointers" ]
null
null
A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l &lt; w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them. The stones are located at integer distances from the banks. The...
The first line contains two integers $w$ and $l$ ($1 \le l &lt; w \le 10^5$)Β β€” the width of the river and the maximum length of a frog's jump. The second line contains $w - 1$ integers $a_1, a_2, \ldots, a_{w-1}$ ($0 \le a_i \le 10^4$), where $a_i$ is the number of stones at the distance $i$ from the bank the frogs ar...
Print a single integerΒ β€” the maximum number of frogs that can cross the river.
[ "10 5\n0 0 1 0 2 0 0 1 0\n", "10 3\n1 1 1 1 2 1 1 1 1\n" ]
[ "3\n", "3\n" ]
In the first sample two frogs can use the different stones at the distance $5$, and one frog can use the stones at the distances $3$ and then $8$. In the second sample although there are two stones at the distance $5$, that does not help. The three paths are: $0 \to 3 \to 6 \to 9 \to 10$, $0 \to 2 \to 5 \to 8 \to 10$,...
2,000
[ { "input": "10 5\n0 0 1 0 2 0 0 1 0", "output": "3" }, { "input": "10 3\n1 1 1 1 2 1 1 1 1", "output": "3" }, { "input": "2 1\n0", "output": "0" }, { "input": "2 1\n5", "output": "5" }, { "input": "10 4\n0 0 6 2 7 1 6 4 0", "output": "8" }, { "input": ...
1,524,865,683
2,147,483,647
Python 3
OK
TESTS
16
217
16,793,600
input_string = input().split() n = int(input_string[0]) l = int(input_string[1]) input_string = input().split() v = [] for i in range(0, len(input_string)): v.append(int(input_string[i])) dp = [0] for i in range(1, len(v) + 1): dp.append(dp[i-1] + v[i-1]) ans = 1000000000000000000000000000 for i in range(l, len(dp)):...
Title: Single-use Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l &lt; w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are ...
```python input_string = input().split() n = int(input_string[0]) l = int(input_string[1]) input_string = input().split() v = [] for i in range(0, len(input_string)): v.append(int(input_string[i])) dp = [0] for i in range(1, len(v) + 1): dp.append(dp[i-1] + v[i-1]) ans = 1000000000000000000000000000 for i in range(l,...
3
55
A
Flea travel
PROGRAMMING
1,200
[ "implementation", "math" ]
A. Flea travel
1
256
A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that ...
The only line contains single integer: 1<=≀<=*n*<=≀<=1000 β€” number of hassocks.
Output "YES" if all the hassocks will be visited and "NO" otherwise.
[ "1\n", "3\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "NO" }, { "input": "7", "output": "NO...
1,450,134,758
2,147,483,647
Python 3
OK
TESTS
83
93
4,403,200
n, c, k = int(input()), 0, 0 v = [[False] * n for i in range(n)] while not v[c][k]: v[c][k] = True k = (k + 1) % n c = (c + k) % n print('YES' if all(any(x) for x in v) else 'NO')
Title: Flea travel Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighbo...
```python n, c, k = int(input()), 0, 0 v = [[False] * n for i in range(n)] while not v[c][k]: v[c][k] = True k = (k + 1) % n c = (c + k) % n print('YES' if all(any(x) for x in v) else 'NO') ```
3.945298
903
G
Yet Another Maxflow Problem
PROGRAMMING
2,700
[ "data structures", "flows", "graphs" ]
null
null
In this problem you will have to deal with a very special network. The network consists of two parts: part *A* and part *B*. Each part consists of *n* vertices; *i*-th vertex of part *A* is denoted as *A**i*, and *i*-th vertex of part *B* is denoted as *B**i*. For each index *i* (1<=≀<=*i*<=&lt;<=*n*) there is a dire...
The first line contains three integer numbers *n*, *m* and *q* (2<=≀<=*n*,<=*m*<=≀<=2Β·105, 0<=≀<=*q*<=≀<=2Β·105) β€” the number of vertices in each part, the number of edges going from *A* to *B* and the number of changes, respectively. Then *n*<=-<=1 lines follow, *i*-th line contains two integers *x**i* and *y**i* deno...
Firstly, print the maximum flow value in the original network. Then print *q* integers, *i*-th of them must be equal to the maximum flow value after *i*-th change.
[ "4 3 2\n1 2\n3 4\n5 6\n2 2 7\n1 4 8\n4 3 9\n1 100\n2 100\n" ]
[ "9\n14\n14\n" ]
This is the original network in the example:
0
[ { "input": "4 3 2\n1 2\n3 4\n5 6\n2 2 7\n1 4 8\n4 3 9\n1 100\n2 100", "output": "9\n14\n14" }, { "input": "10 10 10\n291546518 199012865\n327731857 137263959\n145140225 631959974\n559674936 815057131\n677050070 949982094\n839693202 160045764\n967872826 489258292\n706535160 594950620\n230389718 27478...
1,683,662,340
2,147,483,647
PyPy 3-64
OK
TESTS
62
841
88,473,600
import heapq import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def make_graph(n, m): x, y, s = [0] * (2 * m), [0] * m, [0] * (n + 3) for i in range(0, 2 * m, 2): u, v, w = map(int, input().split()) s[u + 2] += 1 x[i], x[i + 1] = u, v y[i >...
Title: Yet Another Maxflow Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you will have to deal with a very special network. The network consists of two parts: part *A* and part *B*. Each part consists of *n* vertices; *i*-th vertex of part *A* is denoted as *A**i...
```python import heapq import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def make_graph(n, m): x, y, s = [0] * (2 * m), [0] * m, [0] * (n + 3) for i in range(0, 2 * m, 2): u, v, w = map(int, input().split()) s[u + 2] += 1 x[i], x[i + 1] = u, v ...
3
1,011
A
Stages
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the stringΒ β€” concatenation of letters, which correspond to the stages. There are $n$ stages available. The ro...
The first line of input contains two integersΒ β€” $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket. The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th...
Print a single integerΒ β€” the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
[ "5 3\nxyabd\n", "7 4\nproblem\n", "2 2\nab\n", "12 1\nabaabbaaabbb\n" ]
[ "29", "34", "-1", "1" ]
In the first example, the following rockets satisfy the condition: - "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$). Rocket "adx" has the minimal weight, so the answer is $29$. In the second example, target rocket is "belo". Its weight ...
500
[ { "input": "5 3\nxyabd", "output": "29" }, { "input": "7 4\nproblem", "output": "34" }, { "input": "2 2\nab", "output": "-1" }, { "input": "12 1\nabaabbaaabbb", "output": "1" }, { "input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa", "output": ...
1,533,707,179
2,147,483,647
PyPy 3
OK
TESTS
29
140
0
n,k = map(int,input().split()) s = input().rstrip() l = list(s) sum1 = 0 d = {} for i in range(26): d[chr(97 + i)] = i + 1 l.sort() sum1 += d[l[0]] count = 1 i,j = 1,0 while (i < len(l)) and (j < i) and count < k: if d[l[i]] < d[l[j]] + 2: i += 1 continue else: sum1 += d[l[i]] count +=...
Title: Stages Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the stringΒ β€” conca...
```python n,k = map(int,input().split()) s = input().rstrip() l = list(s) sum1 = 0 d = {} for i in range(26): d[chr(97 + i)] = i + 1 l.sort() sum1 += d[l[0]] count = 1 i,j = 1,0 while (i < len(l)) and (j < i) and count < k: if d[l[i]] < d[l[j]] + 2: i += 1 continue else: sum1 += d[l[i]] ...
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,563,478,354
2,147,483,647
Python 3
OK
TESTS
30
248
0
string = input() up = 0 low = 0 i = 0 while(i<len(string)): if ord(string[i])>=65 and ord(string[i])<=90: up+=1 else: low+=1 i+=1 if up>low: ok = string.upper() else: ok = string.lower() print(ok)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python string = input() up = 0 low = 0 i = 0 while(i<len(string)): if ord(string[i])>=65 and ord(string[i])<=90: up+=1 else: low+=1 i+=1 if up>low: ok = string.upper() else: ok = string.lower() print(ok) ```
3.938
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<...
The single line of input contains two integers *k* and *r* (1<=≀<=*k*<=≀<=1000, 1<=≀<=*r*<=≀<=9)Β β€” the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e...
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9Β·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels ...
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", ...
1,688,905,992
2,147,483,647
Python 3
OK
TESTS
54
46
0
k, r = map(int, input().split()) shovels = 1 price = k while price % 10 != 0 and price % 10 != r: shovels += 1 price = k * shovels print(shovels)
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his ...
```python k, r = map(int, input().split()) shovels = 1 price = k while price % 10 != 0 and price % 10 != r: shovels += 1 price = k * shovels print(shovels) ```
3
199
A
Hexadecimal's theorem
PROGRAMMING
900
[ "brute force", "constructive algorithms", "implementation", "number theory" ]
null
null
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F...
The input contains of a single integer *n* (0<=≀<=*n*<=&lt;<=109) β€” the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them.
[ "3\n", "13\n" ]
[ "1 1 1\n", "2 3 8\n" ]
none
500
[ { "input": "3", "output": "1 1 1" }, { "input": "13", "output": "2 3 8" }, { "input": "0", "output": "0 0 0" }, { "input": "1", "output": "1 0 0" }, { "input": "2", "output": "1 1 0" }, { "input": "1597", "output": "233 377 987" }, { "input...
1,637,301,308
2,147,483,647
Python 3
OK
TESTS
54
92
0
n = int(input()) if n == 0: print("0 0 0") elif n == 1: print("1 0 0") elif n == 2: print("1 1 0") elif n == 3: print("1 1 1") else: s = [0, 1];c = 1;i = 2 while (c != n): s.append(c) c = s[i - 1] + s[i] i += 1 print(s[i - 1], s[i - 3], s[i - 4])
Title: Hexadecimal's theorem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let'...
```python n = int(input()) if n == 0: print("0 0 0") elif n == 1: print("1 0 0") elif n == 2: print("1 1 0") elif n == 3: print("1 1 1") else: s = [0, 1];c = 1;i = 2 while (c != n): s.append(c) c = s[i - 1] + s[i] i += 1 print(s[i - 1], s[i - 3], s[i - ...
3
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. Th...
The first line contains two integers, *n* and *k* (1<=≀<=*n*<=≀<=2000;Β 1<=≀<=*k*<=≀<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≀<=*y**i*<=≀<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number β€” the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0...
1,648,227,616
2,147,483,647
Python 3
OK
TESTS
35
46
0
from math import floor n,k=[int(i1) for i1 in input().split()] students=[int(i2) for i2 in input().split()] eligible_students=0 max_rounds=5-k for i3 in students: if i3<=max_rounds: eligible_students+=1 print(floor(eligible_students/3))
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi...
```python from math import floor n,k=[int(i1) for i1 in input().split()] students=[int(i2) for i2 in input().split()] eligible_students=0 max_rounds=5-k for i3 in students: if i3<=max_rounds: eligible_students+=1 print(floor(eligible_students/3)) ```
3
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=3000) β€” the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=3000) β€” indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, ...
1,494,584,443
2,147,483,647
Python 3
OK
TESTS
30
218
307,200
'''input 3 1 7 2 ''' n = int(input()) a = sorted(map(int, input().split())) x = 1 while x in a: x += 1 print(x)
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the...
```python '''input 3 1 7 2 ''' n = int(input()) a = sorted(map(int, input().split())) x = 1 while x in a: x += 1 print(x) ```
3.944928
981
B
Businessmen Problems
PROGRAMMING
1,000
[ "sortings" ]
null
null
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies. In order to avoid this representatives of both companies decided to make an agreement on the ...
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) Β β€” the number of elements discovered by ChemForces. The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) Β β€” the index of the $i$-th element and the income of its usage on the exhibitio...
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
[ "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n", "1\n1000000000 239\n3\n14 15\n92 65\n35 89\n" ]
[ "24\n", "408\n" ]
In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$. In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + ...
750
[ { "input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4", "output": "24" }, { "input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89", "output": "408" }, { "input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\...
1,527,435,178
2,578
Python 3
OK
TESTS
33
842
20,582,400
n=int(input()) CF={} for i in range(n): x=list(map(int,input().split())) CF[x[0]]=x[1] m=int(input()) TC={} for i in range(m): x=list(map(int,input().split())) TC[x[0]]=x[1] keys_Tc=set(TC.keys()) keys_Cf=set(CF.keys()) common=keys_Cf&keys_Tc s=0 for x in TC: if x not in common: s+=TC[x] for x in CF: if x not i...
Title: Businessmen Problems Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both...
```python n=int(input()) CF={} for i in range(n): x=list(map(int,input().split())) CF[x[0]]=x[1] m=int(input()) TC={} for i in range(m): x=list(map(int,input().split())) TC[x[0]]=x[1] keys_Tc=set(TC.keys()) keys_Cf=set(CF.keys()) common=keys_Cf&keys_Tc s=0 for x in TC: if x not in common: s+=TC[x] for x in CF: ...
3
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
The first line contains the single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ...
Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,694,932,052
2,147,483,647
Python 3
OK
TESTS
37
92
0
num, *data = map(int, open(0).read().split()) subset = data[:1] for element in data: num -= min(subset) <= element <= max(subset) subset += element, print(num)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the re...
```python num, *data = map(int, open(0).read().split()) subset = data[:1] for element in data: num -= min(subset) <= element <= max(subset) subset += element, print(num) ```
3
519
B
A and B and Compilation Errors
PROGRAMMING
1,100
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix...
The first line of the input contains integer *n* (3<=≀<=*n*<=≀<=105) β€” the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109) β€” the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-sepa...
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
1,000
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6...
1,659,005,772
2,147,483,647
PyPy 3-64
OK
TESTS
33
156
25,292,800
a = int(input()) b = list(map(int,input().split(" "))) b.sort() c = list(map(int,input().split(" "))) c.sort() d = list(map(int,input().split(" "))) d.sort() first,second=0,0 for i in range(len(c)): if b[i] != c[i]: first = b[i] break if first == 0: first = b[-1] print(first) ...
Title: A and B and Compilation Errors Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler disp...
```python a = int(input()) b = list(map(int,input().split(" "))) b.sort() c = list(map(int,input().split(" "))) c.sort() d = list(map(int,input().split(" "))) d.sort() first,second=0,0 for i in range(len(c)): if b[i] != c[i]: first = b[i] break if first == 0: first = b[-1] prin...
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,548,784,151
2,147,483,647
Python 3
OK
TESTS
40
108
0
b=input() a='hello' k=0 for j in range(len(b)): try: if a[j] not in b: print('NO') k=1 break c=b.find(a[j]) b=b[c+1:] if a[j+1] in b: continue else: ...
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 b=input() a='hello' k=0 for j in range(len(b)): try: if a[j] not in b: print('NO') k=1 break c=b.find(a[j]) b=b[c+1:] if a[j+1] in b: continue else: ...
3.946
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*...
The first line contains an integer *n*Β (1<=≀<=*n*<=≀<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n*Β (1<=≀<=*v**i*<=≀<=109) β€” costs of the stones. The third line contains an integer *m*Β (1<=≀<=*m*<=≀<=105) β€” the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t...
Print *m* lines. Each line must contain an integer β€” the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1...
1,645,941,522
2,147,483,647
Python 3
OK
TESTS
46
1,044
9,216,000
n = int(input()) alist = list(map(int, input().split())) asort = sorted(alist) for i in range(1, n): alist[i] += alist[i - 1] asort[i] += asort[i - 1] m = int(input()) for _ in range(m): t, l, r = map(int, input().split()) if t == 2: print(asort[r-1] - asort[l - 2] if l - 1 !...
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s...
```python n = int(input()) alist = list(map(int, input().split())) asort = sorted(alist) for i in range(1, n): alist[i] += alist[i - 1] asort[i] += asort[i - 1] m = int(input()) for _ in range(m): t, l, r = map(int, input().split()) if t == 2: print(asort[r-1] - asort[l - 2] ...
3
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
The first line contains the single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ...
Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,677,237,718
2,147,483,647
PyPy 3-64
OK
TESTS
37
122
0
n = int(input()) scores = list(map(int, input().split())) min_score = max_score = scores[0] amazing_count = 0 for score in scores[1:]: if score > max_score: max_score = score amazing_count += 1 elif score < min_score: min_score = score amazing_count += 1 print(am...
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the re...
```python n = int(input()) scores = list(map(int, input().split())) min_score = max_score = scores[0] amazing_count = 0 for score in scores[1:]: if score > max_score: max_score = score amazing_count += 1 elif score < min_score: min_score = score amazing_count += 1 ...
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,578,856,006
2,147,483,647
PyPy 3
OK
TESTS
30
280
0
import sys import io import os total = 0 failed = 0 def run(test,res): x = io.StringIO() with io.StringIO(test) as sys.stdin: with x as sys.stdout: work() z = x.getvalue().strip() sys.stdout = sys.__stdout__ print("Passed?", z == res) print("Expected: "...
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 sys import io import os total = 0 failed = 0 def run(test,res): x = io.StringIO() with io.StringIO(test) as sys.stdin: with x as sys.stdout: work() z = x.getvalue().strip() sys.stdout = sys.__stdout__ print("Passed?", z == res) print("E...
3.93
298
B
Sail
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will ...
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≀<=*t*<=≀<=105,<=<=-<=109<=≀<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≀<=109). The starting location and the ending location will be different. The second line contains *t* characters, the *i*-th character is the wind blowing direction at the...
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
[ "5 0 0 1 1\nSESNW\n", "10 5 3 3 6\nNENSWESNEE\n" ]
[ "4\n", "-1\n" ]
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4. In the second sample, they cannot sail to the destination.
500
[ { "input": "5 0 0 1 1\nSESNW", "output": "4" }, { "input": "10 5 3 3 6\nNENSWESNEE", "output": "-1" }, { "input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS", "output": "13" }, { "input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS...
1,571,518,503
2,147,483,647
Python 3
OK
TESTS
43
372
1,331,200
p=input() t,sx,sy,ex,ey=map(int,p.split()) q=input() q=q.replace('',' ') q=q.split() i=0 while (sx!=ex or sy!=ey) and i<t: if q[i]=='E': if sx<ex: sx+=1 elif q[i]=='W': if sx>ex: sx-=1 elif q[i]=='N': if sy<ey: sy+=1 else: ...
Title: Sail Time Limit: None seconds Memory Limit: None megabytes Problem Description: The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu...
```python p=input() t,sx,sy,ex,ey=map(int,p.split()) q=input() q=q.replace('',' ') q=q.split() i=0 while (sx!=ex or sy!=ey) and i<t: if q[i]=='E': if sx<ex: sx+=1 elif q[i]=='W': if sx>ex: sx-=1 elif q[i]=='N': if sy<ey: sy+=1 e...
3
630
G
Challenge Pennants
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Because of budget cuts one IT company established new non-financial reward system instead of bonuses. Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting...
The only line of the input contains one integer *n* (1<=≀<=*n*<=≀<=500) β€” the number of tables in the IT company.
Output one integer β€” the amount of ways to place the pennants on *n* tables.
[ "2\n" ]
[ "24" ]
none
0
[ { "input": "2", "output": "24" }, { "input": "1", "output": "1" }, { "input": "3", "output": "210" }, { "input": "4", "output": "1120" }, { "input": "5", "output": "4410" }, { "input": "6", "output": "14112" }, { "input": "7", "output":...
1,687,723,013
2,147,483,647
PyPy 3-64
OK
TESTS
15
62
0
import sys input = lambda: sys.stdin.readline().rstrip() import math N = int(input()) a = math.comb(N+5-1,5) b = math.comb(N+3-1,3) print(a*b)
Title: Challenge Pennants Time Limit: None seconds Memory Limit: None megabytes Problem Description: Because of budget cuts one IT company established new non-financial reward system instead of bonuses. Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed ...
```python import sys input = lambda: sys.stdin.readline().rstrip() import math N = int(input()) a = math.comb(N+5-1,5) b = math.comb(N+3-1,3) print(a*b) ```
3
877
A
Alex and broken contest
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ...
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n" ]
[ "NO", "YES", "NO" ]
none
500
[ { "input": "Alex_and_broken_contest", "output": "NO" }, { "input": "NikitaAndString", "output": "YES" }, { "input": "Danil_and_Olya", "output": "NO" }, { "input": "Slava____and_the_game", "output": "YES" }, { "input": "Olya_and_energy_drinks", "output": "YES" ...
1,521,712,898
2,147,483,647
Python 3
OK
TESTS
55
93
7,065,600
s=input() D="Danil" O="Olya" S="Slava" A="Ann" N="Nikita" if s.count(D)==1 and s.count(O)==0 and s.count(S)==0 and s.count(A)==0 and s.count(N)==0: print("YES") elif s.count(D)==0 and s.count(O)==1 and s.count(S)==0 and s.count(A)==0 and s.count(N)==0: print("YES") elif s.count(D)==0 and s.count(O)==0...
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems,...
```python s=input() D="Danil" O="Olya" S="Slava" A="Ann" N="Nikita" if s.count(D)==1 and s.count(O)==0 and s.count(S)==0 and s.count(A)==0 and s.count(N)==0: print("YES") elif s.count(D)==0 and s.count(O)==1 and s.count(S)==0 and s.count(A)==0 and s.count(N)==0: print("YES") elif s.count(D)==0 and s.c...
3
27
E
Number With The Given Amount Of Divisors
PROGRAMMING
2,000
[ "brute force", "dp", "number theory" ]
E. Number With The Given Amount Of Divisors
2
256
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
The first line of the input contains integer *n* (1<=≀<=*n*<=≀<=1000).
Output the smallest positive integer with exactly *n* divisors.
[ "4\n", "6\n" ]
[ "6\n", "12\n" ]
none
2,500
[ { "input": "1", "output": "1" }, { "input": "7", "output": "64" }, { "input": "8", "output": "24" }, { "input": "9", "output": "36" }, { "input": "10", "output": "48" }, { "input": "15", "output": "144" }, { "input": "20", "output": "24...
1,617,574,239
2,147,483,647
PyPy 3
OK
TESTS
22
248
3,891,200
INF = 20**18 primes = [] a = [1]*100 def crivo(): for i in range(2, 100): if a[i]: primes.append(i) for j in range(i+i, 100, i): a[j] = 0 def dp(div, idx): div = int(div) idx = int(idx) if div == 1: return 1 resp = INF for i in ra...
Title: Number With The Given Amount Of Divisors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. Input Specification: The first line...
```python INF = 20**18 primes = [] a = [1]*100 def crivo(): for i in range(2, 100): if a[i]: primes.append(i) for j in range(i+i, 100, i): a[j] = 0 def dp(div, idx): div = int(div) idx = int(idx) if div == 1: return 1 resp = INF f...
3.930752
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,641,817,941
2,147,483,647
Python 3
OK
TESTS
49
92
0
n,m = map(int,input().split()) matchboxes = {} for _ in range(m): a,b = map(int,input().split()) #a refers to number of matchboxes holding b matches matchboxes[b] = a if b not in matchboxes else matchboxes[b] + a highest = 0 for key,value in sorted(matchboxes.items(),key = lambda x: x[0],reverse = True): ...
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat...
```python n,m = map(int,input().split()) matchboxes = {} for _ in range(m): a,b = map(int,input().split()) #a refers to number of matchboxes holding b matches matchboxes[b] = a if b not in matchboxes else matchboxes[b] + a highest = 0 for key,value in sorted(matchboxes.items(),key = lambda x: x[0],reverse...
3
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer β€” the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,697,835,375
2,147,483,647
Python 3
OK
TESTS
21
92
0
n = int(input()) counter = 0 for i in range(0, n): k = input() if k.count("1") >= 2: counter += 1 print(counter)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python n = int(input()) counter = 0 for i in range(0, n): k = input() if k.count("1") >= 2: counter += 1 print(counter) ```
3
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,560,212,128
2,147,483,647
Python 3
OK
TESTS
58
108
0
n = input() vet = [0,0,0,0]; for i in range(0,len(n)): if(n[i] == 'n'): vet[0]+=1 elif(n[i] == 'i'): vet[1]+=1 elif(n[i] == 'e'): vet[2]+=1 elif(n[i] == 't'): vet[3]+=1 vet[0] = (vet[0] - 1) / 2 vet[2] /= 3 vet.sort() print(int(vet[0]))
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 n = input() vet = [0,0,0,0]; for i in range(0,len(n)): if(n[i] == 'n'): vet[0]+=1 elif(n[i] == 'i'): vet[1]+=1 elif(n[i] == 'e'): vet[2]+=1 elif(n[i] == 't'): vet[3]+=1 vet[0] = (vet[0] - 1) / 2 vet[2] /= 3 vet.sort() print(int(vet[0])) ```
3
251
A
Points on Line
PROGRAMMING
1,300
[ "binary search", "combinatorics", "two pointers" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen...
The first line contains two integers: *n* and *d* (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*d*<=≀<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 β€” the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input stri...
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. Please do not use 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 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
500
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "...
1,675,540,751
2,147,483,647
PyPy 3
OK
TESTS
39
404
28,467,200
num, choose = map(int, input().split()) lista = list(map(int, input().split())) ans = 0 j = 0 for i in range(0,num): while(lista[i] - lista[j] > choose): j+=1 ans += ((i - j) * (i - j - 1))/2 print(int(ans))
Title: Points on Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart...
```python num, choose = map(int, input().split()) lista = list(map(int, input().split())) ans = 0 j = 0 for i in range(0,num): while(lista[i] - lista[j] > choose): j+=1 ans += ((i - j) * (i - j - 1))/2 print(int(ans)) ```
3
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco...
The first line contains a single integer *a* (1<=≀<=*a*<=≀<=1000) β€” the initial position of the first friend. The second line contains a single integer *b* (1<=≀<=*b*<=≀<=1000) β€” the initial position of the second friend. It is guaranteed that *a*<=β‰ <=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, an...
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,570,327,331
2,147,483,647
Python 3
OK
TESTS
40
124
0
a=int(input()) b=int(input()) if abs(a-b)==1: print("1") else: n=abs(a-b) h=n//2 s=(h*(h+1))//2 if n%2==0: print(2*s) else: r=(2*s)+(h+1) print(r)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in...
```python a=int(input()) b=int(input()) if abs(a-b)==1: print("1") else: n=abs(a-b) h=n//2 s=(h*(h+1))//2 if n%2==0: print(2*s) else: r=(2*s)+(h+1) print(r) ```
3
893
C
Rumor
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "greedy" ]
null
null
Vova promised himself that he would never play computer games... But recently Firestorm β€” a well-known game developing company β€” published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
The first line contains two integer numbers *n* and *m* (1<=≀<=*n*<=≀<=105,<=0<=≀<=*m*<=≀<=105) β€” the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≀<=*c**i*<=≀<=109) β€” the amount of gold *i*-th character asks to start spreading the rumor. ...
Print one number β€” the minimum amount of gold Vova has to spend in order to finish the quest.
[ "5 2\n2 5 3 4 8\n1 4\n4 5\n", "10 0\n1 2 3 4 5 6 7 8 9 10\n", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n" ]
[ "10\n", "55\n", "15\n" ]
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example ...
0
[ { "input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10" }, { "input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55" }, { "input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15" }, { "input": "1 0\n0", "output": "0" }, { "input": "1 0\n10000000...
1,679,779,817
2,147,483,647
PyPy 3
OK
TESTS
46
1,107
17,408,000
from collections import deque n, m=map(int, input().split()) gold=[0]+list(map(int, input().split())) adjacency_list={i: [] for i in range(1, n+1)} for i in range(m): l, r=map(int, input().split()) adjacency_list[l].append(r) adjacency_list[r].append(l) marks=[0 for i in range(n+1)] connected_c...
Title: Rumor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova promised himself that he would never play computer games... But recently Firestorm β€” a well-known game developing company β€” published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte...
```python from collections import deque n, m=map(int, input().split()) gold=[0]+list(map(int, input().split())) adjacency_list={i: [] for i in range(1, n+1)} for i in range(m): l, r=map(int, input().split()) adjacency_list[l].append(r) adjacency_list[r].append(l) marks=[0 for i in range(n+1)] c...
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,591,177,603
2,147,483,647
Python 3
OK
TESTS
40
218
0
a = input() b = input() s1 = a[:len(a)//2] s2 = a[len(a)//2:] if(s2[::-1]+s1[::-1] == b): 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 a = input() b = input() s1 = a[:len(a)//2] s2 = a[len(a)//2:] if(s2[::-1]+s1[::-1] == b): print("YES") else: print("NO") ```
3.9455
18
C
Stripe
PROGRAMMING
1,200
[ "data structures", "implementation" ]
C. Stripe
2
64
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ...
The first input line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” amount of squares in the stripe. The second line contains *n* space-separated numbers β€” they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
[ "9\n1 5 -6 7 9 -16 0 -2 2\n", "3\n1 1 1\n", "2\n0 0\n" ]
[ "3\n", "0\n", "1\n" ]
none
0
[ { "input": "9\n1 5 -6 7 9 -16 0 -2 2", "output": "3" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "2\n0 0", "output": "1" }, { "input": "4\n100 1 10 111", "output": "1" }, { "input": "10\n0 4 -3 0 -2 2 -3 -3 2 5", "output": "3" }, { "input": "...
1,485,789,948
2,147,483,647
Python 3
OK
TESTS
45
218
11,980,800
# 18C # ΞΈ(n) time # ΞΈ(n) space __author__ = 'artyom' # SOLUTION def main(): n = read() a = read(3) s = 0 t = sum(a) count = 0 for i in range(n - 1): s += a[i] t -= a[i] if s == t: count += 1 return count # HELPERS def read(m...
Title: Stripe Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ...
```python # 18C # ΞΈ(n) time # ΞΈ(n) space __author__ = 'artyom' # SOLUTION def main(): n = read() a = read(3) s = 0 t = sum(a) count = 0 for i in range(n - 1): s += a[i] t -= a[i] if s == t: count += 1 return count # HELPERS ...
3.856236
545
C
Woodcutters
PROGRAMMING
1,500
[ "dp", "greedy" ]
null
null
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=...
The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≀<=*x**i*,<=*h**i*<=≀<=109) β€” the coordinate and the height of the *Ρ–*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t...
Print a single number β€” the maximum number of trees that you can cut down by the given rules.
[ "5\n1 2\n2 1\n5 10\n10 9\n19 1\n", "5\n1 2\n2 1\n5 10\n10 9\n20 1\n" ]
[ "3\n", "4\n" ]
In the first sample you can fell the trees like that: - fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] - fell the 2-nd tree to the right β€” now it occupies segment [2;3] - leave the 3-rd tree β€” it occupies point 5 - leave the 4-th tree β€” it occupies point 10 - fell the 5-th tree to the right β€” ...
1,750
[ { "input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3" }, { "input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4" }, { "input": "4\n10 4\n15 1\n19 3\n20 1", "output": "4" }, { "input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10...
1,666,771,479
2,147,483,647
Python 3
OK
TESTS
67
343
10,035,200
n = int(input()) trees = [] for i in range(n): trees.append(list(map(int,input().split()))) # trees[i][0]: position # trees[i][1]: height r_edge = -trees[0][1] max_num = 1 for i in range(n-1): # try to cut i-th tree # if can be cut leftward, then rightward, then cannot be cut if trees[i][0]...
Title: Woodcutters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b...
```python n = int(input()) trees = [] for i in range(n): trees.append(list(map(int,input().split()))) # trees[i][0]: position # trees[i][1]: height r_edge = -trees[0][1] max_num = 1 for i in range(n-1): # try to cut i-th tree # if can be cut leftward, then rightward, then cannot be cut if t...
3
989
A
A Blend of Springtime
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o...
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$)Β β€” denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower).
[ ".BAC.\n", "AA..CB\n" ]
[ "Yes\n", "No\n" ]
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it. In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
500
[ { "input": ".BAC.", "output": "Yes" }, { "input": "AA..CB", "output": "No" }, { "input": ".", "output": "No" }, { "input": "ACB.AAAAAA", "output": "Yes" }, { "input": "B.BC.BBBCA", "output": "Yes" }, { "input": "BA..CAB..B", "output": "Yes" }, ...
1,528,738,547
2,147,483,647
Python 3
OK
TESTS
37
92
0
l = input() if "ABC" in l or "ACB" in l or "BCA" in l or "BAC" in l: print("Yes") elif "CAB" in l or "CBA" in l: print("Yes") else: print("No")
Title: A Blend of Springtime Time Limit: None seconds Memory Limit: None megabytes Problem Description: "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti...
```python l = input() if "ABC" in l or "ACB" in l or "BCA" in l or "BAC" in l: print("Yes") elif "CAB" in l or "CBA" in l: print("Yes") else: print("No") ```
3
579
A
Raising Bacteria
PROGRAMMING
1,000
[ "bitmasks" ]
null
null
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the mini...
The only line containing one integer *x* (1<=≀<=*x*<=≀<=109).
The only line containing one integer: the answer.
[ "5\n", "8\n" ]
[ "2\n", "1\n" ]
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th ...
250
[ { "input": "5", "output": "2" }, { "input": "8", "output": "1" }, { "input": "536870911", "output": "29" }, { "input": "1", "output": "1" }, { "input": "343000816", "output": "14" }, { "input": "559980448", "output": "12" }, { "input": "697...
1,692,380,314
2,147,483,647
PyPy 3-64
OK
TESTS
36
61
0
def main(): x = int(input()) restos = 0 dividendo = x while (dividendo != 1): restos += dividendo % 2 dividendo = dividendo // 2 bacterias = restos + 1 # bacteria inicial print(bacterias) main()
Title: Raising Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split...
```python def main(): x = int(input()) restos = 0 dividendo = x while (dividendo != 1): restos += dividendo % 2 dividendo = dividendo // 2 bacterias = restos + 1 # bacteria inicial print(bacterias) main() ```
3
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's we...
The only line of the input contains two integers *a* and *b* (1<=≀<=*a*<=≀<=*b*<=≀<=10)Β β€” the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4Β·3 = 12 and 7Β·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li...
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output...
1,693,669,884
2,147,483,647
Python 3
OK
TESTS
62
46
0
import math m=input() g=m.split() alist=[] alist.append((int(g[0]), int(g[1]))) count=0 for c in alist: a,b=c if a==b: print(1) else: x = min(a, b) y = max(a, b) while x < y+0.0001: x=x*3 y=y*2 count += 1 print(coun...
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e...
```python import math m=input() g=m.split() alist=[] alist.append((int(g[0]), int(g[1]))) count=0 for c in alist: a,b=c if a==b: print(1) else: x = min(a, b) y = max(a, b) while x < y+0.0001: x=x*3 y=y*2 count += 1 ...
3
962
A
Equator
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on...
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (...
0
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }...
1,524,313,310
530
Python 3
OK
TESTS
106
187
20,787,200
n = int(input()) a = list(map(int, input().split())) sum1 = sum(a) sum2 = 0 i = 0 while sum2 < (sum1 + 1) // 2: sum2 += a[i] i += 1 print(i)
Title: Equator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve...
```python n = int(input()) a = list(map(int, input().split())) sum1 = sum(a) sum2 = 0 i = 0 while sum2 < (sum1 + 1) // 2: sum2 += a[i] i += 1 print(i) ```
3
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105) β€” the sizes of arrays *a* and *b*. The second line contains *n* integers β€” the elements of array *a* (<=-<=109<=≀<=*a**i*<=≀<=109). The third line contains *m* integers β€” the elements of array *b* (<=-<=109<=≀<=*b**j*<=≀<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -77918754...
1,655,034,456
2,147,483,647
Python 3
OK
TESTS
60
1,076
27,545,600
if __name__ == '__main__': n, m = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split())) c = [] for i in range(m): c.append([b[i], i]) a.sort() c = sorted(c, key=lambda k: k[0]) left = 0 res ...
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. In...
```python if __name__ == '__main__': n, m = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split())) c = [] for i in range(m): c.append([b[i], i]) a.sort() c = sorted(c, key=lambda k: k[0]) left = 0...
3
556
A
Case of the Zeros and Ones
PROGRAMMING
900
[ "greedy" ]
null
null
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an...
First line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=2Β·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
[ "4\n1100\n", "5\n01010\n", "8\n11101111\n" ]
[ "0\n", "1\n", "6\n" ]
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like...
250
[ { "input": "4\n1100", "output": "0" }, { "input": "5\n01010", "output": "1" }, { "input": "8\n11101111", "output": "6" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "2" }, { "input"...
1,640,629,192
2,147,483,647
Python 3
OK
TESTS
49
61
204,800
n=int(input()) s=input() c0=s.count("0") c1=s.count("1") print(c0+c1-2*min(c0,c1))
Title: Case of the Zeros and Ones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Cons...
```python n=int(input()) s=input() c0=s.count("0") c1=s.count("1") print(c0+c1-2*min(c0,c1)) ```
3
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane ...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=1000) β€” the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≀<=*a**i*<=≀<=1000) β€” *a**i* stands for the number of empty seats in the *i*-th...
Print two integers β€” the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person β€” to the 2-nd pl...
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7...
1,687,623,165
2,147,483,647
Python 3
OK
TESTS
33
124
0
def result(n,m,lis): k=lis p=tuple(k) maxx=0 for i in range(n): a=max(k) b=k.index(a) maxx+=a k[b]=a-1 p=list(p) minn=0 i=0 c=0 while i<n: if len(p)==0 or c==n: break a=min(p) b=p.index(a) if a==0: p.pop(b) i+=1 continue minn+=a c+=1 p[b]=a-1 i+=1 print(maxx,minn) ...
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen pl...
```python def result(n,m,lis): k=lis p=tuple(k) maxx=0 for i in range(n): a=max(k) b=k.index(a) maxx+=a k[b]=a-1 p=list(p) minn=0 i=0 c=0 while i<n: if len(p)==0 or c==n: break a=min(p) b=p.index(a) if a==0: p.pop(b) i+=1 continue minn+=a c+=1 p[b]=a-1 i+=1 print(maxx,mi...
3
513
A
Game
PROGRAMMING
800
[ "constructive algorithms", "math" ]
null
null
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2...
The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output "First" if the first player wins and "Second" otherwise.
[ "2 2 1 2\n", "2 1 1 1\n" ]
[ "Second\n", "First\n" ]
Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.
3
[ { "input": "2 2 1 2", "output": "Second" }, { "input": "2 1 1 1", "output": "First" }, { "input": "5 7 4 1", "output": "Second" }, { "input": "5 7 1 4", "output": "Second" }, { "input": "5 7 10 10", "output": "Second" }, { "input": "5 7 1 10", "out...
1,641,559,711
2,147,483,647
PyPy 3-64
OK
TESTS
20
93
0
x = input().split() temp = [] for i in x: temp.append(int(i)) x = temp.copy() n1 = x[0] n2 = x[1] k1 = x[2] k2 = x[-1] c1 = False while c1==False: if n1==0: print("Second") break n1 -= 1 if n2 == 0: print("First") break n2 -= 1
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba...
```python x = input().split() temp = [] for i in x: temp.append(int(i)) x = temp.copy() n1 = x[0] n2 = x[1] k1 = x[2] k2 = x[-1] c1 = False while c1==False: if n1==0: print("Second") break n1 -= 1 if n2 == 0: print("First") break n2 -= 1 ...
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,590,009,860
2,147,483,647
Python 3
OK
TESTS
30
310
819,200
import string s = input() def x(s): u =0 l = 0 for c in s: if c in string.ascii_uppercase: u+=1 else: l+=1 if u>l: return s.upper() else: return s.lower() print(x(s))
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python import string s = input() def x(s): u =0 l = 0 for c in s: if c in string.ascii_uppercase: u+=1 else: l+=1 if u>l: return s.upper() else: return s.lower() print(x(s)) ```
3.920974
574
B
Bear and Three Musketeers
PROGRAMMING
1,500
[ "brute force", "dfs and similar", "graphs", "hashing" ]
null
null
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose thre...
The first line contains two space-separated integers, *n* and *m* (3<=≀<=*n*<=≀<=4000, 0<=≀<=*m*<=≀<=4000) β€” respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*, *a**...
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
[ "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n", "7 4\n2 1\n3 6\n5 1\n1 7\n" ]
[ "2\n", "-1\n" ]
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti...
1,000
[ { "input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "output": "2" }, { "input": "7 4\n2 1\n3 6\n5 1\n1 7", "output": "-1" }, { "input": "5 0", "output": "-1" }, { "input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4", "output": "5" }, { ...
1,445,358,601
2,147,483,647
Python 3
OK
TESTS
40
670
716,800
def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] [n,m]=get() mus={} for z in range(n): mus[z+1]=[] for z in range(m): [x,y]=get() mus[x].append(y) mus...
Title: Bear and Three Musketeers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br...
```python def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] [n,m]=get() mus={} for z in range(n): mus[z+1]=[] for z in range(m): [x,y]=get() mus[x].append(y) ...
3
967
B
Watering System
PROGRAMMING
1,000
[ "math", "sortings" ]
null
null
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole. Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After...
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$)Β β€” the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)...
Print a single integerΒ β€” the number of holes Arkady should block.
[ "4 10 3\n2 2 2 2\n", "4 80 20\n3 2 1 4\n", "5 10 10\n1000 1 1 1 1\n" ]
[ "1\n", "0\n", "4\n" ]
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady. In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les...
1,000
[ { "input": "4 10 3\n2 2 2 2", "output": "1" }, { "input": "4 80 20\n3 2 1 4", "output": "0" }, { "input": "5 10 10\n1000 1 1 1 1", "output": "4" }, { "input": "10 300 100\n20 1 3 10 8 5 3 6 4 3", "output": "1" }, { "input": "10 300 100\n20 25 68 40 60 37 44 85 23 ...
1,618,138,844
2,147,483,647
PyPy 3
OK
TESTS
26
156
9,523,200
n,a,b=map(int,input().split()) x=list(map(int,input().split())) x1=x[1:] x1.sort() y=sum(x) while(a*x[0]<b*y): y-=x1.pop() print(n-len(x1)-1)
Title: Watering System Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi...
```python n,a,b=map(int,input().split()) x=list(map(int,input().split())) x1=x[1:] x1.sort() y=sum(x) while(a*x[0]<b*y): y-=x1.pop() print(n-len(x1)-1) ```
3
355
A
Vasya and Digital Root
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<...
The first line contains two integers *k* and *d* (1<=≀<=*k*<=≀<=1000; 0<=≀<=*d*<=≀<=9).
In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes.
[ "4 4\n", "5 1\n", "1 0\n" ]
[ "5881\n", "36172\n", "0\n" ]
For the first test sample *dr*(5881)  =  *dr*(22)  =  4. For the second test sample *dr*(36172)  =  *dr*(19)  =  *dr*(10)  =  1.
500
[ { "input": "4 4", "output": "5881" }, { "input": "5 1", "output": "36172" }, { "input": "1 0", "output": "0" }, { "input": "8 7", "output": "49722154" }, { "input": "487 0", "output": "No solution" }, { "input": "1000 5", "output": "854193955406789...
1,381,811,842
2,147,483,647
Python 3
OK
TESTS
20
62
307,200
#import fileinput import sys #k,d = next(fileinput.input()).split(' ') #for line in fileinput.input(): #k,d = line.split(' ') #print(k + ' ' + d) for line in sys.stdin: k,d = [int(x) for x in line.split(' ')] if d == 0: if k == 1: print(0) else: print(...
Title: Vasya and Digital Root Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=...
```python #import fileinput import sys #k,d = next(fileinput.input()).split(' ') #for line in fileinput.input(): #k,d = line.split(' ') #print(k + ' ' + d) for line in sys.stdin: k,d = [int(x) for x in line.split(' ')] if d == 0: if k == 1: print(0) else: ...
3
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β€” an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=β‰₯<=*k*), and you already know their scores. Calculate...
The first line of the input contains two integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence...
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15...
1,697,381,439
2,147,483,647
Python 3
OK
TESTS
50
92
0
def main(): n,k=map(int , input().split()) a = [int(i) for i in input().split()] x,ans = a[k-1] , 0 for i in range(len(a)): ans += 1 if a[i] > 0 and a[i] >= x else 0 print(ans) main()
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β€” an excerpt from contest rules. A total of *n* p...
```python def main(): n,k=map(int , input().split()) a = [int(i) for i in input().split()] x,ans = a[k-1] , 0 for i in range(len(a)): ans += 1 if a[i] > 0 and a[i] >= x else 0 print(ans) main() ```
3
350
A
TL
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ...
The first line contains two integers *n*, *m* (1<=≀<=*n*,<=*m*<=≀<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=100) β€” the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1...
If there is a valid TL value, print it. Otherwise, print -1.
[ "3 6\n4 5 2\n8 9 6 10 7 11\n", "3 1\n3 4 5\n6\n" ]
[ "5", "-1\n" ]
none
500
[ { "input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5" }, { "input": "3 1\n3 4 5\n6", "output": "-1" }, { "input": "2 5\n45 99\n49 41 77 83 45", "output": "-1" }, { "input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43...
1,550,226,732
2,147,483,647
Python 3
OK
TESTS
45
248
0
n, m = map(int, input().split()) ct = (sorted([int(i) for i in input().split()])) wt = [int(i) for i in input().split()] k = max(ct[-1],2*ct[0]) print(k if 2 * ct[0] <= k < min(wt) else "-1")
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val...
```python n, m = map(int, input().split()) ct = (sorted([int(i) for i in input().split()])) wt = [int(i) for i in input().split()] k = max(ct[-1],2*ct[0]) print(k if 2 * ct[0] <= k < min(wt) else "-1") ```
3
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=150) β€” the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter Β«XΒ»). Thus, there are no empty statements. The operation and th...
Print a single integer β€” the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\...
1,696,865,408
2,147,483,647
Python 3
OK
TESTS
36
61
0
x = 0 n = int(input()) for i in range(n): operation = input() if "++" in operation: x += 1 elif "--" in operation: x -= 1 print(x)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ incre...
```python x = 0 n = int(input()) for i in range(n): operation = input() if "++" in operation: x += 1 elif "--" in operation: x -= 1 print(x) ```
3
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the...
The first line contains two space-separated integers *n* and *x* (1<=≀<=*n*<=≀<=1000, 0<=≀<=*x*<=≀<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≀<=*d**i*<=≀<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ...
Print two space-separated integersΒ β€” number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1....
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,690,719,199
2,147,483,647
PyPy 3-64
OK
TESTS
34
77
1,740,800
n, packs = map(int, input().split()) child = 0 for _ in range(n): a, b = input().split() b = int(b) if a == '+': packs += b else: if packs < b: child += 1 continue packs -= b print(packs, child)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, p...
```python n, packs = map(int, input().split()) child = 0 for _ in range(n): a, b = input().split() b = int(b) if a == '+': packs += b else: if packs < b: child += 1 continue packs -= b print(packs, child) ```
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-&gt;2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2-&gt;3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3-&gt;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,700,144,610
2,147,483,647
PyPy 3-64
OK
TESTS
24
140
20,582,400
n = (int)(input()) a = (list)(map(int , input().split())) pos = [0 for _ in range(n + 1)] for _ in range(n) : pos[a[_]] = _ ans = 0 for index in range(2 , n + 1) : ans += abs(pos[index] - pos[index - 1]) print(ans)
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()) a = (list)(map(int , input().split())) pos = [0 for _ in range(n + 1)] for _ in range(n) : pos[a[_]] = _ ans = 0 for index in range(2 , n + 1) : ans += abs(pos[index] - pos[index - 1]) print(ans) ```
3
347
B
Fixed Points
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not. A fixed point of a function is a point that is mapped to itself by the function. A p...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 β€” the given permutation.
Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation.
[ "5\n0 1 3 4 2\n" ]
[ "3\n" ]
none
1,000
[ { "input": "5\n0 1 3 4 2", "output": "3" }, { "input": "10\n6 9 4 7 8 2 3 5 0 1", "output": "2" }, { "input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15...
1,649,207,483
2,147,483,647
Python 3
OK
TESTS
19
218
9,420,800
# @Chukamin ZZU_TRAIN def main(): n = int(input()) data = list(map(int, input().split())) flat = {} flag = 0 wrong = 0 for i in range(n): if data[i] != i: flat[i] = data[i] if data[i] in flat and flat[data[i]] == i: flag = 1 wrong += 1...
Title: Fixed Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<...
```python # @Chukamin ZZU_TRAIN def main(): n = int(input()) data = list(map(int, input().split())) flat = {} flag = 0 wrong = 0 for i in range(n): if data[i] != i: flat[i] = data[i] if data[i] in flat and flat[data[i]] == i: flag = 1 ...
3
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,696,687,983
2,147,483,647
Python 3
OK
TESTS
37
46
0
n = int(input()) count = 0 num = 1 while True: num_str = str(num) num_length = len(num_str) if count + num_length >= n: nth_digit = num_str[n - count - 1] print(nth_digit) break count += num_length num += 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 n = int(input()) count = 0 num = 1 while True: num_str = str(num) num_length = len(num_str) if count + num_length >= n: nth_digit = num_str[n - count - 1] print(nth_digit) break count += num_length num += 1 ```
3
955
B
Not simply beatiful strings
PROGRAMMING
1,400
[ "implementation" ]
null
null
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others β€” a ...
The only line contains *s* (1<=≀<=|*s*|<=≀<=105) consisting of lowercase latin letters.
Print Β«YesΒ» if the string can be split according to the criteria above or Β«NoΒ» otherwise. Each letter can be printed in arbitrary case.
[ "ababa\n", "zzcxx\n", "yeee\n" ]
[ "Yes\n", "Yes\n", "No\n" ]
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
1,000
[ { "input": "ababa", "output": "Yes" }, { "input": "zzcxx", "output": "Yes" }, { "input": "yeee", "output": "No" }, { "input": "a", "output": "No" }, { "input": "bbab", "output": "No" }, { "input": "abcd", "output": "Yes" }, { "input": "abc"...
1,687,938,590
1,790
Python 3
OK
TESTS
56
62
102,400
N = 26; s = input (); cnt = dict () for ch in s : cnt[ch] = cnt.get (ch, 0) + 1 cnt1, cnt2 = 0, 0 for i in cnt.keys () : if cnt[i] > 1 : cnt2 += 1 else : cnt1 += 1 if len (s) < 4 or cnt1 + cnt2 > 4 or cnt1 + cnt2 == 1: print ("No") elif cnt1 + cnt2 == 2 : print ("Yes" if cnt2 == 2 else "No") else : print ("...
Title: Not simply beatiful strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, abab...
```python N = 26; s = input (); cnt = dict () for ch in s : cnt[ch] = cnt.get (ch, 0) + 1 cnt1, cnt2 = 0, 0 for i in cnt.keys () : if cnt[i] > 1 : cnt2 += 1 else : cnt1 += 1 if len (s) < 4 or cnt1 + cnt2 > 4 or cnt1 + cnt2 == 1: print ("No") elif cnt1 + cnt2 == 2 : print ("Yes" if cnt2 == 2 else "No") else ...
3
910
A
The Way to Home
PROGRAMMING
800
[ "dfs and similar", "dp", "greedy", "implementation" ]
null
null
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* ...
The first line contains two integers *n* and *d* (2<=≀<=*n*<=≀<=100, 1<=≀<=*d*<=≀<=*n*<=-<=1) β€” the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ...
If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
[ "8 4\n10010101\n", "4 2\n1001\n", "8 4\n11100101\n", "12 3\n101111100101\n" ]
[ "2\n", "-1\n", "3\n", "4\n" ]
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a ...
500
[ { "input": "8 4\n10010101", "output": "2" }, { "input": "4 2\n1001", "output": "-1" }, { "input": "8 4\n11100101", "output": "3" }, { "input": "12 3\n101111100101", "output": "4" }, { "input": "5 4\n11011", "output": "1" }, { "input": "5 4\n10001", ...
1,590,241,759
2,147,483,647
PyPy 3
OK
TESTS
63
171
0
def read_tokens(): return input().strip().split() def read_ints(): return [int(s) for s in read_tokens()] n, d = read_ints() arr = input() def solve(arr: str, d: int) -> int: # dp[i] = min(dp[i-1], dp[i-2], ..., dp[i-d]) + 1 # d # = 1 + min dp[i-j] # j=1 ...
Title: The Way to Home Time Limit: None seconds Memory Limit: None megabytes Problem Description: A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c...
```python def read_tokens(): return input().strip().split() def read_ints(): return [int(s) for s in read_tokens()] n, d = read_ints() arr = input() def solve(arr: str, d: int) -> int: # dp[i] = min(dp[i-1], dp[i-2], ..., dp[i-d]) + 1 # d # = 1 + min dp[i-j] # ...
3
931
B
World Cup
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the thirdΒ β€” with the ...
The only line contains three integers *n*, *a* and *b* (2<=≀<=*n*<=≀<=256, 1<=≀<=*a*,<=*b*<=≀<=*n*)Β β€” the total number of teams, and the ids of the teams that Arkady is interested in. It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal.
In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final. Otherwise, print a single integerΒ β€” the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1.
[ "4 1 2\n", "8 2 6\n", "8 7 5\n" ]
[ "1\n", "Final!\n", "2\n" ]
In the first example teams 1 and 2 meet in the first round. In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds. In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs...
1,000
[ { "input": "4 1 2", "output": "1" }, { "input": "8 2 6", "output": "Final!" }, { "input": "8 7 5", "output": "2" }, { "input": "128 30 98", "output": "Final!" }, { "input": "256 128 256", "output": "Final!" }, { "input": "256 2 127", "output": "7" ...
1,613,173,148
1,748
PyPy 3
OK
TESTS
64
124
102,400
class SegTree: def __init__(self, init_val, ide_ele, segfunc): self.n = len(init_val) self.num = 2**(self.n-1).bit_length() self.ide_ele = ide_ele self.segfunc = segfunc self.seg = [ide_ele]*2*self.num # set_val for i in range(self.n): self.seg[i+s...
Title: World Cup Time Limit: None seconds Memory Limit: None megabytes Problem Description: The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in th...
```python class SegTree: def __init__(self, init_val, ide_ele, segfunc): self.n = len(init_val) self.num = 2**(self.n-1).bit_length() self.ide_ele = ide_ele self.segfunc = segfunc self.seg = [ide_ele]*2*self.num # set_val for i in range(self.n): se...
3
501
B
Misha and Changing Handles
PROGRAMMING
1,100
[ "data structures", "dsu", "strings" ]
null
null
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the re...
The first line contains integer *q* (1<=≀<=*q*<=≀<=1000), the number of handle change requests. Next *q* lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and di...
In the first line output the integer *n* β€” the number of users that changed their handles at least once. In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*,...
[ "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n" ]
[ "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n" ]
none
500
[ { "input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov", "output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123" }, { "input": "1\nMisha Vasya", "output": "1\nMisha Vasya" }, { "input": "10\na b\nb c\nc d\nd...
1,586,608,007
2,147,483,647
PyPy 3
OK
TESTS
49
249
4,096,000
q = int(input()) d = {} for i in range(q): w = input().split() a, b = w[0], w[1] if a in d.values(): for j in d.keys(): if d[j]==a: d[j]=b break else: d[a]=b print(len(d)) for i in d: print(i, d[i])
Title: Misha and Changing Handles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is a...
```python q = int(input()) d = {} for i in range(q): w = input().split() a, b = w[0], w[1] if a in d.values(): for j in d.keys(): if d[j]==a: d[j]=b break else: d[a]=b print(len(d)) for i in d: print(i, d[i]) ```
3
818
A
Diplomas and Certificates
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ...
The first (and the only) line of input contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
0
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1",...
1,516,854,188
308
Python 3
OK
TESTS
44
62
5,632,000
n,k=map(int,input().split()) x=n//(2*(k+1)) print(x,k*x,n-x*(k+1))
Title: Diplomas and Certificates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with...
```python n,k=map(int,input().split()) x=n//(2*(k+1)) print(x,k*x,n-x*(k+1)) ```
3
415
A
Mashmokh and Lights
PROGRAMMING
900
[ "implementation" ]
null
null
Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turn...
The first line of the input contains two space-separated integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m*Β (1<=≀<=*b**i*<=≀<=*n*). It is guaranteed that all lights...
Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off.
[ "5 4\n4 3 1 2\n", "5 5\n5 4 3 2 1\n" ]
[ "1 1 3 4 4 \n", "1 2 3 4 5 \n" ]
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus bu...
500
[ { "input": "5 4\n4 3 1 2", "output": "1 1 3 4 4 " }, { "input": "5 5\n5 4 3 2 1", "output": "1 2 3 4 5 " }, { "input": "16 11\n8 5 12 10 14 2 6 3 15 9 1", "output": "1 2 2 2 5 5 5 8 8 8 8 8 8 8 8 8 " }, { "input": "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 6...
1,396,799,036
236
Python 3
OK
TESTS
31
77
0
n,m=map(int,input().split()) L=list(map(int,input().split())) Q=[1]*n Ans=[-1]*(n) for i in range(m): x=L[i]-1 for j in range(x,n): if(Q[j]==1): Q[j]=0 Ans[j]=x+1 for item in Ans: print(item,end=" ")
Title: Mashmokh and Lights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. ...
```python n,m=map(int,input().split()) L=list(map(int,input().split())) Q=[1]*n Ans=[-1]*(n) for i in range(m): x=L[i]-1 for j in range(x,n): if(Q[j]==1): Q[j]=0 Ans[j]=x+1 for item in Ans: print(item,end=" ") ```
3
572
B
Order Book
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* β€” buy or sell, and integer *q**i*. This means that the participant is ready ...
The input starts with two positive integers *n* and *s* (1<=≀<=*n*<=≀<=1000,<=1<=≀<=*s*<=≀<=50), the number of orders and the book depth. Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≀<=*p**i*<=≀<=105) and an integer *q**i* (1<=≀<=*q**i*<=≀<=104) β€” direction, price and volume resp...
Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input.
[ "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n" ]
[ "S 50 8\nS 40 1\nB 25 10\nB 20 4\n" ]
Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample. You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.
1,000
[ { "input": "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10", "output": "S 50 8\nS 40 1\nB 25 10\nB 20 4" }, { "input": "2 1\nB 7523 5589\nS 69799 1711", "output": "S 69799 1711\nB 7523 5589" }, { "input": "1 1\nB 48259 991", "output": "B 48259 991" }, { "input": "1 50\n...
1,440,280,348
2,147,483,647
PyPy 3
OK
TESTS
34
202
1,740,800
n, s = tuple(map(int, input().split())) agr = dict() for i in range(n): arr = input().split() arr[1] = int(arr[1]) arr[2] = int(arr[2]) agr[(arr[0], arr[1])] = agr.get((arr[0], arr[1]), 0) + arr[2] sell, buy = [], [] for elem in agr: if elem[0] == 'B': buy.append([elem[1], agr[...
Title: Order Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i...
```python n, s = tuple(map(int, input().split())) agr = dict() for i in range(n): arr = input().split() arr[1] = int(arr[1]) arr[2] = int(arr[2]) agr[(arr[0], arr[1])] = agr.get((arr[0], arr[1]), 0) + arr[2] sell, buy = [], [] for elem in agr: if elem[0] == 'B': buy.append([ele...
3
884
A
Book Reading
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she...
The first line contains two integers *n* and *t* (1<=≀<=*n*<=≀<=100, 1<=≀<=*t*<=≀<=106) β€” the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≀<=*a**i*<=≀<=86400) β€” the time Luba has to spend on her work during *i*-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*.
[ "2 2\n86400 86398\n", "2 86400\n0 86400\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "2 2\n86400 86398", "output": "2" }, { "input": "2 86400\n0 86400", "output": "1" }, { "input": "2 86400\n1 86399", "output": "2" }, { "input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
1,628,404,385
2,147,483,647
PyPy 3
OK
TESTS
16
93
20,172,800
n, t = map(int, input().split()) ans = 0 for x in [int(i) for i in input().split()]: t -= 86400-x ans += 1 if t <= 0: print(ans) break
Title: Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of ...
```python n, t = map(int, input().split()) ans = 0 for x in [int(i) for i in input().split()]: t -= 86400-x ans += 1 if t <= 0: print(ans) break ```
3
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits....
The first line contains a single integer *x* (1<=≀<=*x*<=≀<=1018) β€” the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", ...
1,681,477,692
2,147,483,647
Python 3
OK
TESTS
43
62
0
n = input() word = "" for i in range(len(n)): d = n[i] if i==0: if n[i]!="9": if int(n[i])>4: d = str(9-int(n[i])) else: if int(n[i])>4: d = str(9-int(n[i])) word+= d print(word)
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform...
```python n = input() word = "" for i in range(len(n)): d = n[i] if i==0: if n[i]!="9": if int(n[i])>4: d = str(9-int(n[i])) else: if int(n[i])>4: d = str(9-int(n[i])) word+= d print(word) ```
3
527
B
Error Correct System
PROGRAMMING
1,500
[ "greedy" ]
null
null
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings *S* and *T* of equal length to be "similar". After a brief search on th...
The first line contains integer *n* (1<=≀<=*n*<=≀<=200<=000) β€” the length of strings *S* and *T*. The second line contains string *S*. The third line contains string *T*. Each of the lines only contains lowercase Latin letters.
In the first line, print number *x* β€” the minimum possible Hamming distance between strings *S* and *T* if you swap at most one pair of letters in *S*. In the second line, either print the indexes *i* and *j* (1<=≀<=*i*,<=*j*<=≀<=*n*, *i*<=β‰ <=*j*), if reaching the minimum possible distance is possible by swapping lett...
[ "9\npergament\npermanent\n", "6\nwookie\ncookie\n", "4\npetr\negor\n", "6\ndouble\nbundle\n" ]
[ "1\n4 6\n", "1\n-1 -1\n", "2\n1 2\n", "2\n4 1\n" ]
In the second test it is acceptable to print *i* = 2, *j* = 3.
1,000
[ { "input": "9\npergament\npermanent", "output": "1\n4 6" }, { "input": "6\nwookie\ncookie", "output": "1\n-1 -1" }, { "input": "4\npetr\negor", "output": "2\n1 2" }, { "input": "6\ndouble\nbundle", "output": "2\n4 1" }, { "input": "1\na\na", "output": "0\n-1 -...
1,428,927,595
2,147,483,647
Python 3
OK
TESTS
57
233
1,843,200
n=int(input()) s,t=input(),input() alpha=list('abcdefghijklmnopqrstuvwxyz') spair,tpair=dict(),dict() x=[1]*n k=n d=0 u,v=-1,-1 dd=dict() for i in range(n): if s[i]==t[i]: k=k-1 else: dd[s[i]+t[i]]=str(i+1) for i in alpha: for j in alpha: if (i+j in dd) and...
Title: Error Correct System Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write ...
```python n=int(input()) s,t=input(),input() alpha=list('abcdefghijklmnopqrstuvwxyz') spair,tpair=dict(),dict() x=[1]*n k=n d=0 u,v=-1,-1 dd=dict() for i in range(n): if s[i]==t[i]: k=k-1 else: dd[s[i]+t[i]]=str(i+1) for i in alpha: for j in alpha: if (i+j ...
3
285
A
Slightly Decreasing Permutations
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. The ...
The single line contains two space-separated integers: *n*,<=*k* (1<=≀<=*n*<=≀<=105,<=0<=≀<=*k*<=&lt;<=*n*) β€” the permutation length and the decreasing coefficient.
In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* β€” the permutation of length *n* with decreasing coefficient *k*. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.
[ "5 2\n", "3 0\n", "3 2\n" ]
[ "1 5 2 4 3\n", "1 2 3\n", "3 2 1\n" ]
none
500
[ { "input": "5 2", "output": "1 5 2 4 3" }, { "input": "3 0", "output": "1 2 3" }, { "input": "3 2", "output": "3 2 1" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "1 2" }, { "input": "2 1", "output": "2 1" }, { "input":...
1,588,906,295
2,147,483,647
Python 3
OK
TESTS
28
498
10,137,600
a, b = input().split() a = int(a) b = int(b) temp = a - b ans = [] for i in range(b): ans.append(a) a -= 1 add = 1 for i in range(temp): ans.append(add) add += 1 for item in ans: print(item, end = " ")
Title: Slightly Decreasing Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutat...
```python a, b = input().split() a = int(a) b = int(b) temp = a - b ans = [] for i in range(b): ans.append(a) a -= 1 add = 1 for i in range(temp): ans.append(add) add += 1 for item in ans: print(item, end = " ") ```
3
626
A
Robot Sequence
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L'Β β€” instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s...
The first line of the input contains a single positive integer, *n* (1<=≀<=*n*<=≀<=200)Β β€” the number of commands. The next line contains *n* characters, each either 'U', 'R', 'D', or 'L'Β β€” Calvin's source code.
Print a single integerΒ β€” the number of contiguous substrings that Calvin can execute and return to his starting square.
[ "6\nURLLDR\n", "4\nDLUU\n", "7\nRLRLRLR\n" ]
[ "2\n", "0\n", "12\n" ]
In the first case, the entire source code works, as well as the "RL" substring in the second and third characters. Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.
500
[ { "input": "6\nURLLDR", "output": "2" }, { "input": "4\nDLUU", "output": "0" }, { "input": "7\nRLRLRLR", "output": "12" }, { "input": "1\nR", "output": "0" }, { "input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL...
1,487,962,072
2,147,483,647
Python 3
OK
TESTS
25
77
4,608,000
import sys sys.stdin.readline() line = sys.stdin.readline().strip() count = 0 for i, elem in enumerate(line): up, down, left, right = 0,0,0,0 for sub in line[i:]: if sub == "U": up += 1 if sub == "D": down -= 1 if sub == "R": right += 1 if s...
Title: Robot Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L'Β β€” instructions to move a single square up, right, down, or left, respectively...
```python import sys sys.stdin.readline() line = sys.stdin.readline().strip() count = 0 for i, elem in enumerate(line): up, down, left, right = 0,0,0,0 for sub in line[i:]: if sub == "U": up += 1 if sub == "D": down -= 1 if sub == "R": right += 1 ...
3
0
none
none
none
0
[ "none" ]
null
null
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't ...
The first line contains the integer *n* (1<=≀<=*n*<=≀<=200<=000) β€” the number of points. Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≀<=*x**i*<=≀<=109,<=1<=≀<=*w**i*<=≀<=109) β€” the coordinate and the weight of a point. All *x**i* are different.
Print a single number β€” the number of vertexes in the maximum clique of the given graph.
[ "4\n2 3\n3 1\n6 1\n0 2\n" ]
[ "3\n" ]
If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars! The picture for the sample test.
0
[ { "input": "4\n2 3\n3 1\n6 1\n0 2", "output": "3" }, { "input": "1\n42 23", "output": "1" }, { "input": "2\n1 5\n2 6", "output": "1" }, { "input": "2\n1 5\n12 6", "output": "2" }, { "input": "1\n0 1", "output": "1" }, { "input": "1\n1000000000 10000000...
1,609,855,807
2,147,483,647
Python 3
OK
TESTS
51
686
18,432,000
import sys readline = sys.stdin.readline def main(): N = int(input()) itvs = [] for _ in range(N): x, w = map(int, input().split()) itvs.append((x - w, x + w)) itvs.sort(key=lambda x: x[1]) ans = 0 end = -(10**9 + 1) for l, r in itvs: if end <= l: ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum siz...
```python import sys readline = sys.stdin.readline def main(): N = int(input()) itvs = [] for _ in range(N): x, w = map(int, input().split()) itvs.append((x - w, x + w)) itvs.sort(key=lambda x: x[1]) ans = 0 end = -(10**9 + 1) for l, r in itvs: if end ...
3
817
C
Really Big Numbers
PROGRAMMING
1,600
[ "binary search", "brute force", "dp", "math" ]
null
null
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different...
The first (and the only) line contains two integers *n* and *s* (1<=≀<=*n*,<=*s*<=≀<=1018).
Print one integer β€” the quantity of really big numbers that are not greater than *n*.
[ "12 1\n", "25 20\n", "10 9\n" ]
[ "3\n", "0\n", "1\n" ]
In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
0
[ { "input": "12 1", "output": "3" }, { "input": "25 20", "output": "0" }, { "input": "10 9", "output": "1" }, { "input": "300 1000", "output": "0" }, { "input": "500 1000", "output": "0" }, { "input": "1000 2000", "output": "0" }, { "input":...
1,497,541,456
2,356
PyPy 3
OK
TESTS
68
109
102,400
def check(x, s): k = 0 for i in str(x): k += int(i) return x - k >= s n, s = map(int, input().split()) l = 0 r = n while r - l > 1: m = (l + r) // 2 if check(m, s): r = m else: l = m if check(r, s): print(n - r + 1) else: print(0)
Title: Really Big Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its...
```python def check(x, s): k = 0 for i in str(x): k += int(i) return x - k >= s n, s = map(int, input().split()) l = 0 r = n while r - l > 1: m = (l + r) // 2 if check(m, s): r = m else: l = m if check(r, s): print(n - r + 1) else: print(0) ``...
3
794
B
Cutting Carrot
PROGRAMMING
1,200
[ "geometry", "math" ]
null
null
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles tri...
The first and only line of input contains two space-separated integers, *n* and *h* (2<=≀<=*n*<=≀<=1000, 1<=≀<=*h*<=≀<=105).
The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correc...
[ "3 2\n", "2 100000\n" ]
[ "1.154700538379 1.632993161855\n", "70710.678118654752\n" ]
Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle).
1,000
[ { "input": "3 2", "output": "1.154700538379 1.632993161855" }, { "input": "2 100000", "output": "70710.678118654752" }, { "input": "1000 100000", "output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8...
1,494,669,519
1,419
Python 3
OK
TESTS
31
62
307,200
import sys from math import sqrt def main(): n,h=list(map(int,sys.stdin.readline().split())) sn=sqrt(n) result=[] for i in range(n-1): result.append(sqrt(i+1)*h/sn) sys.stdout.write(' '.join(map(str,result))+'\n') main()
Title: Cutting Carrot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cu...
```python import sys from math import sqrt def main(): n,h=list(map(int,sys.stdin.readline().split())) sn=sqrt(n) result=[] for i in range(n-1): result.append(sqrt(i+1)*h/sn) sys.stdout.write(' '.join(map(str,result))+'\n') main() ```
3
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
The single line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=100;Β 2<=≀<=*m*<=≀<=100), separated by a space.
Print a single integer β€” the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on...
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,647,171,318
2,147,483,647
PyPy 3-64
OK
TESTS
26
62
0
n,m=[int(x) for x in input().split()] have=n use=0 day=1 while have>0: use+=1 if day%m!=0: have=have-1 day+=1 print(use)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th...
```python n,m=[int(x) for x in input().split()] have=n use=0 day=1 while have>0: use+=1 if day%m!=0: have=have-1 day+=1 print(use) ```
3
387
B
George and Round
PROGRAMMING
1,200
[ "brute force", "greedy", "two pointers" ]
null
null
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=3000) β€” the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≀<=106) β€” the requirem...
Print a single integer β€” the answer to the problem.
[ "3 5\n1 2 3\n1 2 2 3 3\n", "3 5\n1 2 3\n1 1 1 1 1\n", "3 1\n2 3 4\n1\n" ]
[ "0\n", "2\n", "3\n" ]
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems wi...
1,000
[ { "input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0" }, { "input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2" }, { "input": "3 1\n2 3 4\n1", "output": "3" }, { "input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97...
1,516,155,105
2,147,483,647
Python 3
OK
TESTS
41
62
5,939,200
#http://codeforces.com/problemset/problem/387/B def inp(): return map(int, input().split()) n,m=inp() a=list(inp()) b=list(inp()) i,j=0,0 while ((i < n) & (j < m)): if (b[j] >= a[i]): i+=1 j+=1 print(n-i)
Title: George and Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. T...
```python #http://codeforces.com/problemset/problem/387/B def inp(): return map(int, input().split()) n,m=inp() a=list(inp()) b=list(inp()) i,j=0,0 while ((i < n) & (j < m)): if (b[j] >= a[i]): i+=1 j+=1 print(n-i) ```
3
49
B
Sum
PROGRAMMING
1,500
[ "math" ]
B. Sum
2
256
Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base *p* and regard the...
The first letter contains two space-separated numbers *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=1000) which represent the given summands.
Print a single number β€” the length of the longest answer.
[ "78 87\n", "1 1\n" ]
[ "3\n", "2\n" ]
none
1,000
[ { "input": "78 87", "output": "3" }, { "input": "1 1", "output": "2" }, { "input": "9 7", "output": "2" }, { "input": "11 11", "output": "3" }, { "input": "43 21", "output": "3" }, { "input": "84 89", "output": "3" }, { "input": "12 34", ...
1,644,766,305
2,147,483,647
PyPy 3
OK
TESTS
67
154
0
import sys input = sys.stdin.readline a, b = map(int, input().split()) s = set() for i in list(str(a)): s.add(int(i)) for i in list(str(b)): s.add(int(i)) m = 0 for i in s: m = max(m, i) m += 1 ans = 0 for i in range(m, 20): a0, b0 = list(str(a)), list(str(b)) a1, b1 = 0, 0 j =...
Title: Sum Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positiona...
```python import sys input = sys.stdin.readline a, b = map(int, input().split()) s = set() for i in list(str(a)): s.add(int(i)) for i in list(str(b)): s.add(int(i)) m = 0 for i in s: m = max(m, i) m += 1 ans = 0 for i in range(m, 20): a0, b0 = list(str(a)), list(str(b)) a1, b1 = 0, ...
3.9615
746
B
Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=2000)Β β€” the length of the encoded word. The second line contains the string *s* of length *n* consisting of lowercase English lettersΒ β€” the encoding.
Print the word that Polycarp encoded.
[ "5\nlogva\n", "2\nno\n", "4\nabba\n" ]
[ "volga\n", "no\n", "baba\n" ]
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec...
1,000
[ { "input": "5\nlogva", "output": "volga" }, { "input": "2\nno", "output": "no" }, { "input": "4\nabba", "output": "baba" }, { "input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv", "output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv" }, { "...
1,612,973,370
2,147,483,647
PyPy 3
OK
TESTS
34
108
1,228,800
n = int(input()) s = input()[::-1] ans = ['' for i in range(n)] cnt = 0 for i in range(0,n-1,2): ans[cnt] = s[i] ans[n-cnt-1] = s[i+1] cnt+=1 if n%2!=0: ans[n//2] = s[n-1] print(''.join(ans[::-1]))
Title: Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the...
```python n = int(input()) s = input()[::-1] ans = ['' for i in range(n)] cnt = 0 for i in range(0,n-1,2): ans[cnt] = s[i] ans[n-cnt-1] = s[i+1] cnt+=1 if n%2!=0: ans[n//2] = s[n-1] print(''.join(ans[::-1])) ```
3
53
C
Little Frog
PROGRAMMING
1,200
[ "constructive algorithms" ]
C. Little Frog
2
256
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha...
The single line contains a number *n* (1<=≀<=*n*<=≀<=104) which is the number of mounds.
Print *n* integers *p**i* (1<=≀<=*p**i*<=≀<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≀<=*i*<=≀<=*n*<=-<=1). If there are several solutions, output any.
[ "2\n", "3\n" ]
[ "1 2 ", "1 3 2 " ]
none
1,500
[ { "input": "2", "output": "1 2 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "1 4 2 3 " }, { "input": "5", "output": "1 5 2 4 3 " }, { "input": "6", "output": "1 6 2 5 3 4 " }, { "input": "1", "output": "1 " }, { "inp...
1,515,683,419
2,147,483,647
Python 3
OK
TESTS
22
154
5,734,400
import sys n = int(input()) ans = [0 for _ in range(n)] iter = 0 for i in range( 0 , n - 1 ,2 ): ans[i], ans[i + 1] = iter + 1, n - iter iter = iter + 1 if n % 2: ans[n - 1] = n // 2 + 1 for i in range(n): sys.stdout.write(str(ans[i]) + ' ') print()
Title: Little Frog Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ...
```python import sys n = int(input()) ans = [0 for _ in range(n)] iter = 0 for i in range( 0 , n - 1 ,2 ): ans[i], ans[i + 1] = iter + 1, n - iter iter = iter + 1 if n % 2: ans[n - 1] = n // 2 + 1 for i in range(n): sys.stdout.write(str(ans[i]) + ' ') print() ```
3.950819
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,685,594,567
2,147,483,647
Python 3
OK
TESTS
34
46
0
n = int(input()) array = [int(x) for x in input().split(" ")] seriji = 0 dima = 0 left = 0 right = n-1 serijis_turn = True while(left<=right): choose=0 if array[left]>array[right]: choose = array[left] left+=1 else: choose = array[right] right-=1 if serijis...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python n = int(input()) array = [int(x) for x in input().split(" ")] seriji = 0 dima = 0 left = 0 right = n-1 serijis_turn = True while(left<=right): choose=0 if array[left]>array[right]: choose = array[left] left+=1 else: choose = array[right] right-=1 ...
3
629
A
Far Relative’s Birthday Cake
PROGRAMMING
800
[ "brute force", "combinatorics", "constructive algorithms", "implementation" ]
null
null
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=Γ—<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta...
In the first line of the input, you are given a single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
[ "3\n.CC\nC..\nC.C\n", "4\nCC..\nC..C\n.CC.\n.CC.\n" ]
[ "4\n", "9\n" ]
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
500
[ { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9" }, { "input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "output": "46" }, { "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "output": "84" },...
1,656,793,608
2,147,483,647
PyPy 3-64
OK
TESTS
48
109
512,000
n=int(input()) l=[] res=0 for i in range(n): l.append(list(input())) y=list(zip(*l)) #print(y) for i in range(n): x=l[i].count('C') b=y[i].count('C') res+=((x-1)*x)//2+((b-1)*b)//2 print(res) #EXERCISES WITH MATRIX #See this exercise when you have problems with matrices #How ...
Title: Far Relative’s Birthday Cake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=Γ—<=*n* square consisting of equal squares with s...
```python n=int(input()) l=[] res=0 for i in range(n): l.append(list(input())) y=list(zip(*l)) #print(y) for i in range(n): x=l[i].count('C') b=y[i].count('C') res+=((x-1)*x)//2+((b-1)*b)//2 print(res) #EXERCISES WITH MATRIX #See this exercise when you have problems with matri...
3
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some...
The first line of the input contains an integer *n* (1<=≀<=*n*<=≀<=100<=000)Β β€” the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "outp...
1,619,327,095
2,147,483,647
Python 3
OK
TESTS
47
77
409,600
from collections import Counter n=int(input()) s=input() if(len(s)>26): print(-1) else: c=Counter(s) p=c.values() print(sum(p)-len(p))
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di...
```python from collections import Counter n=int(input()) s=input() if(len(s)>26): print(-1) else: c=Counter(s) p=c.values() print(sum(p)-len(p)) ```
3
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≀<=*n*<=≀<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9",...
1,628,197,432
2,147,483,647
Python 3
OK
TESTS
47
186
6,758,400
k = input().strip() a = k.split('1') l = ['', '4', '44'] if k[0] == '4': print('NO') exit(0) for i in a: if i not in l: print('NO') exit(0) print('YES')
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're ...
```python k = input().strip() a = k.split('1') l = ['', '4', '44'] if k[0] == '4': print('NO') exit(0) for i in a: if i not in l: print('NO') exit(0) print('YES') ```
3
554
A
Kyoya and Photobooks
PROGRAMMING
900
[ "brute force", "math", "strings" ]
null
null
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
The first line of input will be a single string *s* (1<=≀<=|*s*|<=≀<=20). String *s* consists only of lowercase English letters.
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
[ "a\n", "hi\n" ]
[ "51\n", "76\n" ]
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
250
[ { "input": "a", "output": "51" }, { "input": "hi", "output": "76" }, { "input": "y", "output": "51" }, { "input": "kgan", "output": "126" }, { "input": "zoabkyuvus", "output": "276" }, { "input": "spyemhyznjieyhhbk", "output": "451" }, { "i...
1,549,390,124
2,147,483,647
Python 3
OK
TESTS
33
93
0
n=input() print(25*len(n)+26)
Title: Kyoya and Photobooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b...
```python n=input() print(25*len(n)+26) ```
3
808
D
Array Division
PROGRAMMING
1,900
[ "binary search", "data structures", "implementation" ]
null
null
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element ...
The first line contains single integer *n* (1<=≀<=*n*<=≀<=100000) β€” the size of the array. The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≀<=*a**i*<=≀<=109) β€” the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
[ "3\n1 3 2\n", "5\n1 2 3 4 5\n", "5\n2 2 3 4 5\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
0
[ { "input": "3\n1 3 2", "output": "YES" }, { "input": "5\n1 2 3 4 5", "output": "NO" }, { "input": "5\n2 2 3 4 5", "output": "YES" }, { "input": "5\n72 32 17 46 82", "output": "NO" }, { "input": "6\n26 10 70 11 69 57", "output": "NO" }, { "input": "7\n4...
1,659,599,463
2,147,483,647
PyPy 3-64
OK
TESTS
115
124
19,763,200
from itertools import accumulate if __name__=='__main__': n=int(input()) nums=list(map(int,input().split())) total=sum(nums) if total & 1: print('NO') quit() s=0 presum={v:i for i,v in enumerate(accumulate(nums))} for i,n in enumerate(nums): l=tot...
Title: Array Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to...
```python from itertools import accumulate if __name__=='__main__': n=int(input()) nums=list(map(int,input().split())) total=sum(nums) if total & 1: print('NO') quit() s=0 presum={v:i for i,v in enumerate(accumulate(nums))} for i,n in enumerate(nums): ...
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,665,580,306
2,147,483,647
Python 3
OK
TESTS
40
92
0
S=input()[::-1] A=input() if(S==A): 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()[::-1] A=input() if(S==A): print("YES") else: print("NO") ```
3.977
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million...
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≀<=*k*,<=*l*<=≀<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number β€” the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "N...
1,527,011,251
2,147,483,647
Python 3
OK
TESTS
64
184
0
# python 3 """ """ def cifera(k_int: int, l_int: int) -> None: curr = l_int la_count = -1 while True: if curr % k_int == 0: la_count += 1 curr = curr // k_int if curr == 1: print("YES") print(la_count) break ...
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa...
```python # python 3 """ """ def cifera(k_int: int, l_int: int) -> None: curr = l_int la_count = -1 while True: if curr % k_int == 0: la_count += 1 curr = curr // k_int if curr == 1: print("YES") print(la_count) br...
3
127
A
Wasted Time
PROGRAMMING
900
[ "geometry" ]
null
null
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers *n* and *k* (2<=≀<=*n*<=≀<=100, 1<=≀<=*k*<=≀<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* β€” integers *x**i* and *y**i*, separated by a space. All points *A**i* are different. Th...
Print one real number β€” the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6.
[ "2 1\n0 0\n10 0\n", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n" ]
[ "0.200000000", "6.032163204", "3.000000000" ]
none
500
[ { "input": "2 1\n0 0\n10 0", "output": "0.200000000" }, { "input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204" }, { "input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000" }, { "input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n1...
1,642,845,958
2,147,483,647
Python 3
OK
TESTS
42
92
0
n, k = map(int, input().split()) a, b = map(int, input().split()) p = 0 for i in range(n - 1): x, y = map(int, input().split()) t = (x-a)**2+(y-b)**2 p += t**0.5 a, b = x, y print(p*k/50)
Title: Wasted Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count ...
```python n, k = map(int, input().split()) a, b = map(int, input().split()) p = 0 for i in range(n - 1): x, y = map(int, input().split()) t = (x-a)**2+(y-b)**2 p += t**0.5 a, b = x, y print(p*k/50) ```
3
361
B
Levko and Permutation
PROGRAMMING
1,200
[ "constructive algorithms", "math", "number theory" ]
null
null
Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*. Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *g...
The single line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=105, 0<=≀<=*k*<=≀<=*n*).
In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist. If there are multiple suitable permutations, you are allowed to print any of them.
[ "4 2\n", "1 1\n" ]
[ "2 4 3 1", "-1\n" ]
In the first sample elements 4 and 3 are good because *gcd*(2, 4) = 2 &gt; 1 and *gcd*(3, 3) = 3 &gt; 1. Elements 2 and 1 are not good because *gcd*(1, 2) = 1 and *gcd*(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful. The second sample has no beautiful permutations.
1,000
[ { "input": "4 2", "output": "2 1 3 4 " }, { "input": "1 1", "output": "-1" }, { "input": "7 4", "output": "3 1 2 4 5 6 7 " }, { "input": "10 9", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "10000 5000", "output": "5000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1...
1,651,258,593
2,147,483,647
Python 3
OK
TESTS
47
93
6,758,400
n, k = [int(n) for n in input().split()] if k == n: print(-1) else: ordenada = list(range(1, n + 1)) desordenei = 1 ini = 1 if (n - k) % 2 == 0: ordenada[0], ordenada[1] = ordenada[1], ordenada[0] desordenei += 1 ini = 2 while desordenei < n - k: ordenada[ini], ...
Title: Levko and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*. Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numb...
```python n, k = [int(n) for n in input().split()] if k == n: print(-1) else: ordenada = list(range(1, n + 1)) desordenei = 1 ini = 1 if (n - k) % 2 == 0: ordenada[0], ordenada[1] = ordenada[1], ordenada[0] desordenei += 1 ini = 2 while desordenei < n - k: orden...
3
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≀<=*n*<=≀<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\...
1,660,916,871
2,147,483,647
Python 3
OK
TESTS
87
140
7,372,800
n = int(input()) a = input() l = a.split() mini_odd=1000000000000000000; sm=0 for i in range(len(l)): l[i] = int(l[i]) sm+=l[i] if l[i]%2!=0: mini_odd=min(mini_odd,l[i]) if sm%2!=0: print(sm-mini_odd) else: print(sm)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, th...
```python n = int(input()) a = input() l = a.split() mini_odd=1000000000000000000; sm=0 for i in range(len(l)): l[i] = int(l[i]) sm+=l[i] if l[i]%2!=0: mini_odd=min(mini_odd,l[i]) if sm%2!=0: print(sm-mini_odd) else: print(sm) ```
3
508
B
Anton and currency you all know
PROGRAMMING
1,300
[ "greedy", "math", "strings" ]
null
null
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of...
The first line contains an odd positive integer *n*Β β€” the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes.
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro...
[ "527\n", "4573\n", "1357997531\n" ]
[ "572\n", "3574\n", "-1\n" ]
none
1,000
[ { "input": "527", "output": "572" }, { "input": "4573", "output": "3574" }, { "input": "1357997531", "output": "-1" }, { "input": "444443", "output": "444434" }, { "input": "22227", "output": "72222" }, { "input": "24683", "output": "34682" }, ...
1,647,595,479
2,147,483,647
Python 3
OK
TESTS
58
93
614,400
def pro(arr): n=len(arr) prev=None for i in range(n): if( int(arr[i])%2==0): if(int(arr[i])<int(arr[-1])): prev=i break else: prev=i if(prev!=None): arr[prev],arr[-1]= arr[-1],arr[prev] print(...
Title: Anton and currency you all know Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed...
```python def pro(arr): n=len(arr) prev=None for i in range(n): if( int(arr[i])%2==0): if(int(arr[i])<int(arr[-1])): prev=i break else: prev=i if(prev!=None): arr[prev],arr[-1]= arr[-1],arr[prev] ...
3
171
A
Mysterious numbers - 1
PROGRAMMING
1,200
[ "*special", "constructive algorithms" ]
null
null
The input contains two integers *a*1,<=*a*2 (0<=≀<=*a**i*<=≀<=109), separated by a single space. Output a single integer.
The input contains two integers *a*1,<=*a*2 (0<=≀<=*a**i*<=≀<=109), separated by a single space.
Output a single integer.
[ "3 14\n", "27 12\n", "100 200\n" ]
[ "44\n", "48\n", "102\n" ]
none
0
[ { "input": "3 14", "output": "44" }, { "input": "27 12", "output": "48" }, { "input": "100 200", "output": "102" }, { "input": "0 0", "output": "0" }, { "input": "31415 92653", "output": "67044" }, { "input": "1000000000 0", "output": "1000000000" ...
1,585,714,238
2,147,483,647
Python 3
OK
TESTS
41
218
0
"""==================================================================================== ==================================================================================== ___ _______ ___ _______ ___ ___ | /\ | | \ | | / | | | | |\ /| | ...
Title: Mysterious numbers - 1 Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains two integers *a*1,<=*a*2 (0<=≀<=*a**i*<=≀<=109), separated by a single space. Output a single integer. Input Specification: The input contains two integers *a*1,<=*a*2 (0<=≀<=*a**i*<=≀<=109),...
```python """==================================================================================== ==================================================================================== ___ _______ ___ _______ ___ ___ | /\ | | \ | | / | | | | |\ ...
3
746
A
Compote
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruitsΒ β€” ...
The first line contains the positive integer *a* (1<=≀<=*a*<=≀<=1000)Β β€” the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≀<=*b*<=≀<=1000)Β β€” the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≀<=*c*<=≀<=1000)Β β€” the number of pears Nikolay has...
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
[ "2\n5\n7\n", "4\n7\n13\n", "2\n3\n2\n" ]
[ "7\n", "21\n", "0\n" ]
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
500
[ { "input": "2\n5\n7", "output": "7" }, { "input": "4\n7\n13", "output": "21" }, { "input": "2\n3\n2", "output": "0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n4", "output": "7" }, { "input": "1000\n1000\n1000", "output": "1750" }...
1,633,924,269
2,147,483,647
Python 3
OK
TESTS
84
77
6,758,400
lemon = int(input()) apple = int(input()) pears = int(input()) compote = list(['0']) compote.append(lemon) compote.append(int(apple/2)) compote.append(int(pears/4)) del compote[0] mini = min(compote) print(mini*7)
Title: Compote Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa...
```python lemon = int(input()) apple = int(input()) pears = int(input()) compote = list(['0']) compote.append(lemon) compote.append(int(apple/2)) compote.append(int(pears/4)) del compote[0] mini = min(compote) print(mini*7) ```
3