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
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input":...
1,696,056,069
2,147,483,647
Python 3
OK
TESTS
53
92
0
def compare_strings(str1,str2): str1=str1.lower() str2=str2.lower() if str1<str2: return-1 elif str1>str2: return 1 else: return 0 str1=input() str2=input() result=compare_strings(str1,str2) print(result)
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ...
```python def compare_strings(str1,str2): str1=str1.lower() str2=str2.lower() if str1<str2: return-1 elif str1>str2: return 1 else: return 0 str1=input() str2=input() result=compare_strings(str1,str2) print(result) ```
3.977
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,699,427,049
2,147,483,647
PyPy 3
OK
TESTS
21
216
1,638,400
questions = int(input()) total = 0 while questions: answers = input() answers = list(map(int, answers.split(' '))) answers = answers.count(1) if (answers > 1): total += 1 questions -= 1 print(total)
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 questions = int(input()) total = 0 while questions: answers = input() answers = list(map(int, answers.split(' '))) answers = answers.count(1) if (answers > 1): total += 1 questions -= 1 print(total) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,679,780,213
2,147,483,647
Python 3
OK
TESTS
20
46
0
n = int(input()) list = ['a'] for i in range(n): st = str(input()) if len(st) > 10: for i in st: list.append(i) one = list[1] two = str(len(st)-2) thre =list[len(st)] print(one+two+thre) else: print(st) list = ['a']
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python n = int(input()) list = ['a'] for i in range(n): st = str(input()) if len(st) > 10: for i in st: list.append(i) one = list[1] two = str(len(st)-2) thre =list[len(st)] print(one+two+thre) else: print(st) list = ['a'] ```
3.977
0
none
none
none
0
[ "none" ]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes...
In first line there is one integer *n* (1<=≀<=*n*<=≀<=2Β·105)Β β€” number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=2Β·105) are writtenΒ β€” indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ...
Print one integerΒ β€” index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in...
0
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000...
1,510,508,301
5,601
Python 3
OK
TESTS
33
140
19,046,400
n = [None for x in range(int(input()))] u = input().split() u.reverse() x = dict(zip(u,n)) for key in x: n = key print(n)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First o...
```python n = [None for x in range(int(input()))] u = input().split() u.reverse() x = dict(zip(u,n)) for key in x: n = key print(n) ```
3
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is ...
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m...
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", ...
1,694,691,000
2,147,483,647
PyPy 3
OK
TESTS
28
140
3,891,200
import sys fin = sys.stdin s = fin.readline().rstrip()[::-1] t = fin.readline().rstrip()[::-1] i = 0 m = min(len(s), len(t)) for i in range(m): if s[i] != t[i]: break else: i = m print(len(s)+len(t)-2*i)
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ...
```python import sys fin = sys.stdin s = fin.readline().rstrip()[::-1] t = fin.readline().rstrip()[::-1] i = 0 m = min(len(s), len(t)) for i in range(m): if s[i] != t[i]: break else: i = m print(len(s)+len(t)-2*i) ```
3
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers β€” the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number β€” the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second oneΒ β€” 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,631,283,464
2,147,483,647
PyPy 3
OK
TESTS
27
248
20,172,800
import math arr = list(map(lambda x: int(x), input().split())) a = math.sqrt((arr[0]*arr[1])/arr[2]) b = math.sqrt((arr[2]*arr[1])/arr[0]) c = math.sqrt((arr[2]*arr[0])/arr[1]) print(int(4*(a+b+c)))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python import math arr = list(map(lambda x: int(x), input().split())) a = math.sqrt((arr[0]*arr[1])/arr[2]) b = math.sqrt((arr[2]*arr[1])/arr[0]) c = math.sqrt((arr[2]*arr[0])/arr[1]) print(int(4*(a+b+c))) ```
3
820
A
Mister B and Book Reading
PROGRAMMING
900
[ "implementation" ]
null
null
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ...
First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≀<=*c*<=≀<=1000, 0<=≀<=*l*<=&lt;<=*v*0<=≀<=*v*1<=≀<=1000, 0<=≀<=*a*<=≀<=1000) β€” the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo...
Print one integer β€” the number of days Mister B needed to finish the book.
[ "5 5 10 5 4\n", "12 4 12 4 1\n", "15 1 100 0 0\n" ]
[ "1\n", "3\n", "15\n" ]
In the first sample test the book contains 5 pages, so Mister B read it right at the first day. In the second sample test at first day Mister B read pages number 1 - 4, at second dayΒ β€” 4 - 11, at third dayΒ β€” 11 - 12 and finished the book. In third sample test every day Mister B read 1 page of the book, so he finished...
500
[ { "input": "5 5 10 5 4", "output": "1" }, { "input": "12 4 12 4 1", "output": "3" }, { "input": "15 1 100 0 0", "output": "15" }, { "input": "1 1 1 0 0", "output": "1" }, { "input": "1000 999 1000 1000 998", "output": "2" }, { "input": "1000 2 2 5 1", ...
1,690,718,215
2,147,483,647
Python 3
OK
TESTS
110
46
0
def main(): p,s,max,ds,rr = map(int,input().split()) days = 1 speed = s total=s total=s while total<p: total-=rr speed+=ds if speed>max: speed = max total+=speed days+=1 print(days) main()
Title: Mister B and Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ...
```python def main(): p,s,max,ds,rr = map(int,input().split()) days = 1 speed = s total=s total=s while total<p: total-=rr speed+=ds if speed>max: speed = max total+=speed days+=1 print(days) main() ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
The only line of input contains the name of some exhibitΒ β€” the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integerΒ β€” the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "...
1,654,723,344
2,147,483,647
Python 3
OK
TESTS
44
46
0
w = input() init = 'a' rot = 0 for c in w: temp = abs(ord(c) - ord(init)) # no of clockwise rotations (n) rot += temp if temp <= 13 else (26-temp) # if clockwise > 13 do (26 - n) anticlockwise rotations init = c print(rot)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devis...
```python w = input() init = 'a' rot = 0 for c in w: temp = abs(ord(c) - ord(init)) # no of clockwise rotations (n) rot += temp if temp <= 13 else (26-temp) # if clockwise > 13 do (26 - n) anticlockwise rotations init = c print(rot) ```
3
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'...
The first input line contains the only integer *n* (1<=≀<=*n*<=≀<=200) β€” the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≀<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac...
Print the only number β€” the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point β€” point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n...
1,622,283,126
2,226
Python 3
OK
TESTS
26
156
0
number_of_testcases = 1 #int(input()) for _ in range(number_of_testcases): number_of_points = int(input()) coordinates = [list(map(int,input().split())) for i in range(number_of_points)] #print(coordinates) num_supercentral_points = 0 for i in coordinates: correct_set = 0 ...
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give...
```python number_of_testcases = 1 #int(input()) for _ in range(number_of_testcases): number_of_points = int(input()) coordinates = [list(map(int,input().split())) for i in range(number_of_points)] #print(coordinates) num_supercentral_points = 0 for i in coordinates: correct_set...
3
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *...
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≀<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≀<=1000)Β β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th...
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participantΒ β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participantΒ β€” in 5 milliseconds. So, ...
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, ...
1,587,825,162
2,147,483,647
Python 3
OK
TESTS
32
109
0
s,p1,p2,t1,t2=map(int,input().split()) a=(s*p1)+(2*t1) b=(s*p2)+(2*t2) if(a<b): print('First') elif(b<a): print('Second') else: print('Friendship')
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t...
```python s,p1,p2,t1,t2=map(int,input().split()) a=(s*p1)+(2*t1) b=(s*p2)+(2*t2) if(a<b): print('First') elif(b<a): print('Second') else: print('Friendship') ```
3
383
A
Milking cows
PROGRAMMING
1,600
[ "data structures", "greedy" ]
null
null
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity o...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right.
Print a single integer, the minimum amount of lost milk. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4\n0 0 1 0\n", "5\n1 0 1 0 1\n" ]
[ "1", "3" ]
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
500
[ { "input": "4\n0 0 1 0", "output": "1" }, { "input": "5\n1 0 1 0 1", "output": "3" }, { "input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0", "output": "416" }, { "input": "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 ...
1,672,870,015
2,147,483,647
Python 3
OK
TESTS
42
124
3,686,400
n = int(input()) lst = list(map(int,input().split())) res,s = 0,0 for i in lst: if i == 0: res+=s else: s+=1 print(res)
Title: Milking cows Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub...
```python n = int(input()) lst = list(map(int,input().split())) res,s = 0,0 for i in lst: if i == 0: res+=s else: s+=1 print(res) ```
3
876
B
Divisiblity of Differences
PROGRAMMING
1,300
[ "implementation", "math", "number theory" ]
null
null
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number...
First line contains three integers *n*, *k* and *m* (2<=≀<=*k*<=≀<=*n*<=≀<=100<=000, 1<=≀<=*m*<=≀<=100<=000)Β β€” number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=...
If it is not possible to select *k* numbers in the desired way, output Β«NoΒ» (without the quotes). Otherwise, in the first line of output print Β«YesΒ» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k*Β β€” the selected numbers. If there are multiple possible solutions, print any of them...
[ "3 2 3\n1 8 4\n", "3 3 3\n1 8 4\n", "4 3 5\n2 7 7 7\n" ]
[ "Yes\n1 4 ", "No", "Yes\n2 7 7 " ]
none
1,000
[ { "input": "3 2 3\n1 8 4", "output": "Yes\n1 4 " }, { "input": "3 3 3\n1 8 4", "output": "No" }, { "input": "4 3 5\n2 7 7 7", "output": "Yes\n2 7 7 " }, { "input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825", "output":...
1,508,369,627
2,147,483,647
Python 3
OK
TESTS
63
452
14,950,400
n, k, m = map(int, input().split()) a = list(map(int, input().split())) ost = [[] for i in range(m)] for i in range(n): ost[a[i]%m].append(a[i]); for i in range(m): if len(ost[i])>=k: print('Yes') for j in range(k): print(ost[i][j], end=' '); exit(0) print('No')
Title: Divisiblity of Differences Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be re...
```python n, k, m = map(int, input().split()) a = list(map(int, input().split())) ost = [[] for i in range(m)] for i in range(n): ost[a[i]%m].append(a[i]); for i in range(m): if len(ost[i])>=k: print('Yes') for j in range(k): print(ost[i][j], end=' '); exit(0) print('No') ```
3
964
A
Splits
PROGRAMMING
800
[ "math" ]
null
null
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$. Th...
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output one integerΒ β€” the answer to the problem.
[ "7\n", "8\n", "9\n" ]
[ "4\n", "5\n", "5\n" ]
In the first sample, there are following possible weights of splits of $7$: Weight 1: [$\textbf 7$] Weight 2: [$\textbf 3$, $\textbf 3$, 1] Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1] Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$]
500
[ { "input": "7", "output": "4" }, { "input": "8", "output": "5" }, { "input": "9", "output": "5" }, { "input": "1", "output": "1" }, { "input": "286", "output": "144" }, { "input": "48", "output": "25" }, { "input": "941", "output": "471...
1,523,976,315
2,414
Python 3
OK
TESTS
63
93
7,065,600
n = int(input()) sum = 0 sum = n//2 + 1 print(sum)
Title: Splits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The foll...
```python n = int(input()) sum = 0 sum = n//2 + 1 print(sum) ```
3
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=200<=000)Β β€” the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i*Β β€” the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one numberΒ β€” the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,673,716,016
2,147,483,647
PyPy 3-64
OK
TESTS
30
1,075
9,113,600
di={"Tetrahedron": 4 ,"Cube":6,"Octahedron":8 ,"Dodecahedron":12, "Icosahedron":20 } n=int(input()) c=0 for i in range(n) : s=input() c+=di[s] print(c)
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python di={"Tetrahedron": 4 ,"Cube":6,"Octahedron":8 ,"Dodecahedron":12, "Icosahedron":20 } n=int(input()) c=0 for i in range(n) : s=input() c+=di[s] print(c) ```
3
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,627,113,445
2,147,483,647
Python 3
OK
TESTS
34
77
6,963,200
n = int(input()) s=input() c=[] i=0 if n%2==1: c.append(s[i]) i+=1 n-=1 while i<n: c.insert(0, s[i]) c.append(s[i+1]) i+=2 x=''.join(c) print(x)
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() c=[] i=0 if n%2==1: c.append(s[i]) i+=1 n-=1 while i<n: c.insert(0, s[i]) c.append(s[i+1]) i+=2 x=''.join(c) print(x) ```
3
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son...
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE...
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "...
1,689,491,884
2,147,483,647
Python 3
OK
TESTS
71
92
0
w = input().replace("WUB", " ") w = [_ for _ in w.split() if _] print(" ".join(w))
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consist...
```python w = input().replace("WUB", " ") w = [_ for _ in w.split() if _] print(" ".join(w)) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,681,287,923
2,147,483,647
Python 3
OK
TESTS
20
46
0
def long(n): if len(n)<=10: return n else: return n[0] + str(len(n)-2) + n[len(n)-1] n=int(input()) L=[] for j in range(n): l=input() L.append(long(l)) for k in L: print(k)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python def long(n): if len(n)<=10: return n else: return n[0] + str(len(n)-2) + n[len(n)-1] n=int(input()) L=[] for j in range(n): l=input() L.append(long(l)) for k in L: print(k) ```
3.977
949
A
Zebras
PROGRAMMING
1,600
[ "greedy" ]
null
null
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o...
In the only line of input data there is a non-empty string *s* consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |*s*|) does not exceed 200<=000 characters.
If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer *k* (1<=≀<=*k*<=≀<=|*s*|), the resulting number of subsequences. In the *i*-th of following *k* lines first print the integer *l**i* (1<=≀<=*l**i*<=≀<=|*s*|), which is the length of the *i*-th subsequenc...
[ "0010100\n", "111\n" ]
[ "3\n3 1 3 4\n3 2 5 6\n1 7\n", "-1\n" ]
none
500
[ { "input": "0010100", "output": "3\n1 1\n5 2 3 4 5 6\n1 7" }, { "input": "111", "output": "-1" }, { "input": "0", "output": "1\n1 1" }, { "input": "1", "output": "-1" }, { "input": "0101010101", "output": "-1" }, { "input": "010100001", "output": "...
1,653,927,101
2,147,483,647
PyPy 3-64
OK
TESTS
71
545
39,424,000
from collections import deque def zebras(s): zbs=[] alzbs=[] for i in range(n): if s[i]=='0': if not alzbs: zbs.append([i+1]) else: tmp=alzbs.pop() tmp.append(i+1) zbs.append(tmp) ...
Title: Zebras Time Limit: None seconds Memory Limit: None megabytes Problem Description: Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alter...
```python from collections import deque def zebras(s): zbs=[] alzbs=[] for i in range(n): if s[i]=='0': if not alzbs: zbs.append([i+1]) else: tmp=alzbs.pop() tmp.append(i+1) zbs.append(tmp) ...
3
81
A
Plug-in
PROGRAMMING
1,400
[ "implementation" ]
A. Plug-in
1
256
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy...
The input data consists of a single line to be processed. The length of the line is from 1 to 2Β·105 characters inclusive. The string contains only lowercase Latin letters.
Print the given string after it is processed. It is guaranteed that the result will contain at least one character.
[ "hhoowaaaareyyoouu\n", "reallazy\n", "abacabaabacabaa\n" ]
[ "wre", "rezy", "a" ]
none
500
[ { "input": "hhoowaaaareyyoouu", "output": "wre" }, { "input": "reallazy", "output": "rezy" }, { "input": "abacabaabacabaa", "output": "a" }, { "input": "xraccabccbry", "output": "xy" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b"...
1,685,037,179
2,147,483,647
Python 3
OK
TESTS
32
124
5,324,800
def remove_duplicates(s): st = [] for char in s[::-1]: if st and st[-1] == char: st.pop() else: st.append(char) return ''.join(st[::-1]) s = input() ans = remove_duplicates(s) print(ans)
Title: Plug-in Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed...
```python def remove_duplicates(s): st = [] for char in s[::-1]: if st and st[-1] == char: st.pop() else: st.append(char) return ''.join(st[::-1]) s = input() ans = remove_duplicates(s) print(ans) ```
3.928082
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers β€” the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number β€” the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second oneΒ β€” 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,672,566,575
2,147,483,647
PyPy 3-64
OK
TESTS
27
122
0
import math a, b, c = map(int, input().split(' ')) print(int(4 * (a * b + b * c + a * c) * math.sqrt(a * b * c) / (a * b * c)))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python import math a, b, c = map(int, input().split(' ')) print(int(4 * (a * b + b * c + a * c) * math.sqrt(a * b * c) / (a * b * c))) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,679,554,183
2,147,483,647
Python 3
OK
TESTS
20
46
0
n = int(input()) m = [0]*n for i in range(n): m[i] = input() for i in range(len(m)): if len(m[i]) > 10: print(str(m[i][0]) + str(len(m[i])-2) + str(m[i][-1])) else: print(m[i])
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python n = int(input()) m = [0]*n for i in range(n): m[i] = input() for i in range(len(m)): if len(m[i]) > 10: print(str(m[i][0]) + str(len(m[i])-2) + str(m[i][-1])) else: print(m[i]) ```
3.977
828
B
Black Square
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has a checkered sheet of paper of size *n*<=Γ—<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum pos...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100) β€” the sizes of the sheet. The next *n* lines contain *m* letters 'B' or 'W' each β€” the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
[ "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n", "1 2\nBB\n", "3 3\nWWW\nWWW\nWWW\n" ]
[ "5\n", "-1\n", "1\n" ]
In the first example it is needed to paint 5 cells β€” (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third exampl...
750
[ { "input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5" }, { "input": "1 2\nBB", "output": "-1" }, { "input": "3 3\nWWW\nWWW\nWWW", "output": "1" }, { "input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n...
1,521,103,052
2,147,483,647
Python 3
OK
TESTS
128
545
5,836,800
##n = int(input()) ##a = list(map(int, input().split())) ##print(' '.join(map(str, res))) def list_input(): return list(map(int, input().split())) [n, m] = list_input() cell = list() for i in range(n): cell.append(input()) ps = [[0 for j in range(m+1)] for i in range(n+1)] for i in range(n): ...
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has a checkered sheet of paper of size *n*<=Γ—<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of w...
```python ##n = int(input()) ##a = list(map(int, input().split())) ##print(' '.join(map(str, res))) def list_input(): return list(map(int, input().split())) [n, m] = list_input() cell = list() for i in range(n): cell.append(input()) ps = [[0 for j in range(m+1)] for i in range(n+1)] for i in range...
3
285
B
Find Marble
PROGRAMMING
1,200
[ "implementation" ]
null
null
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position *s*. Then he performs som...
The first line contains three integers: *n*,<=*s*,<=*t* (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*s*,<=*t*<=≀<=*n*) β€” the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≀<=*p**i*<=≀<=*n*) β€” the shuffling operation parameters. It is guaran...
If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer β€” the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1.
[ "4 2 1\n2 3 4 1\n", "4 3 3\n4 1 3 2\n", "4 3 4\n1 2 3 4\n", "3 1 3\n2 1 3\n" ]
[ "3\n", "0\n", "-1\n", "-1\n" ]
none
1,000
[ { "input": "4 2 1\n2 3 4 1", "output": "3" }, { "input": "4 3 3\n4 1 3 2", "output": "0" }, { "input": "4 3 4\n1 2 3 4", "output": "-1" }, { "input": "3 1 3\n2 1 3", "output": "-1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 6 7\n10 7 8 1...
1,587,977,931
2,147,483,647
Python 3
OK
TESTS
33
310
7,372,800
n, s, t = map(int, input().split()) a = [0] + [int(x) for x in input().split()] if s==t: print("0") else: count = 0 found = False temp = s while(a[temp]!=s): count += 1 temp = a[temp] if temp == t: found = True break if found: ...
Title: Find Marble Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ...
```python n, s, t = map(int, input().split()) a = [0] + [int(x) for x in input().split()] if s==t: print("0") else: count = 0 found = False temp = s while(a[temp]!=s): count += 1 temp = a[temp] if temp == t: found = True break if foun...
3
567
C
Geometric Progression
PROGRAMMING
1,700
[ "binary search", "data structures", "dp" ]
null
null
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers. He wants to know how many subsequences of length three can be selected from *a*, so that they form a geo...
The first line of the input contains two integers, *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=2Β·105), showing how many numbers Polycarp's sequence has and his favorite number. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≀<=*a**i*<=≀<=109) β€” elements of the sequence.
Output a single number β€” the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*.
[ "5 2\n1 1 2 2 4\n", "3 1\n1 1 1\n", "10 3\n1 2 6 2 3 6 9 18 3 9\n" ]
[ "4", "1", "6" ]
In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.
1,500
[ { "input": "5 2\n1 1 2 2 4", "output": "4" }, { "input": "3 1\n1 1 1", "output": "1" }, { "input": "10 3\n1 2 6 2 3 6 9 18 3 9", "output": "6" }, { "input": "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "output": "5" }, { "input": "5 3\n5 15 15 15 45...
1,618,034,305
2,147,483,647
Python 3
OK
TESTS
81
405
22,630,400
n , k = map(int, input().split()) arr = list(map(int, input().split())) counter = 0 # To store no.of every element occurrence. element_occurrence = {} # To store no.of every element occurrence which has a valid value (Geometric Progression) . # this store How many time this element valid to be used in Geo...
Title: Geometric Progression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers...
```python n , k = map(int, input().split()) arr = list(map(int, input().split())) counter = 0 # To store no.of every element occurrence. element_occurrence = {} # To store no.of every element occurrence which has a valid value (Geometric Progression) . # this store How many time this element valid to be u...
3
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces ...
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": "...
1,694,162,679
2,147,483,647
Python 3
OK
TESTS
42
92
0
s=input() s1=s.lower() vowels=['a','e','i','o','u','y'] res="" for i in s1: if i not in vowels: res+='.' res+=i print(res)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters...
```python s=input() s1=s.lower() vowels=['a','e','i','o','u','y'] res="" for i in s1: if i not in vowels: res+='.' res+=i print(res) ```
3
44
A
Indian Summer
PROGRAMMING
900
[ "implementation" ]
A. Indian Summer
2
256
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β€” she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor...
Output the single number β€” the number of Alyona's leaves.
[ "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n", "3\noak yellow\noak yellow\noak yellow\n" ]
[ "4\n", "1\n" ]
none
0
[ { "input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4" }, { "input": "3\noak yellow\noak yellow\noak yellow", "output": "1" }, { "input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae", "output": "5" }, { "input"...
1,671,875,360
2,147,483,647
Python 3
OK
TESTS
29
92
0
n = int(input()) lst = [] for i in range(n): s = input() lst.append(s) lst = set(lst) print(len(lst))
Title: Indian Summer Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β€” she doesn't take a leaf if it matches the color and the specie...
```python n = int(input()) lst = [] for i in range(n): s = input() lst.append(s) lst = set(lst) print(len(lst)) ```
3.977
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ...
The only line contains two integers: *n* and *m* (3<=≀<=*n*,<=*m*<=≀<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#...
1,685,334,662
2,147,483,647
PyPy 3-64
OK
TESTS
28
77
0
n, m = map(int, input().split()) flag = True for i in range(1, n + 1): if i % 2 == 0 and flag: print('.' * (m - 1) + '#') flag = False elif i % 2 == 0 and not flag: print('#' + '.' * (m - 1)) flag = True else: print('#' * m)
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*...
```python n, m = map(int, input().split()) flag = True for i in range(1, n + 1): if i % 2 == 0 and flag: print('.' * (m - 1) + '#') flag = False elif i % 2 == 0 and not flag: print('#' + '.' * (m - 1)) flag = True else: print('#' * m) ```
3
420
A
Start Up
PROGRAMMING
1,000
[ "implementation" ]
null
null
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
[ "AHA\n", "Z\n", "XO\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "AHA", "output": "YES" }, { "input": "Z", "output": "NO" }, { "input": "XO", "output": "NO" }, { "input": "AAA", "output": "YES" }, { "input": "AHHA", "output": "YES" }, { "input": "BAB", "output": "NO" }, { "input": "OMMMAAMMMO"...
1,667,531,073
2,147,483,647
Python 3
OK
TESTS
80
46
0
n=input() if n==n[::-1] and "Z" not in n and "S" not in n and "R" not in n and "Q" not in n and "P" not in n and "N" not in n and "L" not in n and "K" not in n and "J" not in n and "G" not in n and "F" not in n and "E" not in n and "D" not in n and "C" not in n and "B" not in n: print("YES") else: print("NO")
Title: Start Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of ...
```python n=input() if n==n[::-1] and "Z" not in n and "S" not in n and "R" not in n and "Q" not in n and "P" not in n and "N" not in n and "L" not in n and "K" not in n and "J" not in n and "G" not in n and "F" not in n and "E" not in n and "D" not in n and "C" not in n and "B" not in n: print("YES") else: print("NO...
3
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen...
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $...
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "...
1,546,079,821
2,147,483,647
Python 3
OK
TESTS
31
109
0
input() a = list(map(int, input().split())) b = list(map(int, input().split())) c = [element for element in a if element in b] for i in c: print(i, end=' ')
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keyp...
```python input() a = list(map(int, input().split())) b = list(map(int, input().split())) c = [element for element in a if element in b] for i in c: print(i, end=' ') ```
3
242
B
Big Segment
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth...
The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=109) β€” the borders of the *i*-th segment. It is guaranteed that no two segments c...
Print a single integer β€” the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.
[ "3\n1 1\n2 2\n3 3\n", "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n" ]
[ "-1\n", "3\n" ]
none
1,000
[ { "input": "3\n1 1\n2 2\n3 3", "output": "-1" }, { "input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "output": "3" }, { "input": "4\n1 5\n2 2\n2 4\n2 5", "output": "1" }, { "input": "5\n3 3\n1 3\n2 2\n2 3\n1 2", "output": "2" }, { "input": "7\n7 7\n8 8\n3 7\n1 6\n1 ...
1,617,979,334
2,147,483,647
Python 3
OK
TESTS
45
622
7,577,600
def solution(): n=int(input()) k=[] mn=float('Inf') mx=float('-Inf') for i in range(n): l,r=map(int,input().split()) k.append((l,r)) mn=min(l,mn) mx=max(r, mx) for i in range(n): if k[i][0]==mn and k[i][1]==mx: print(i+1) return print(-1) return solution()
Title: Big Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments ...
```python def solution(): n=int(input()) k=[] mn=float('Inf') mx=float('-Inf') for i in range(n): l,r=map(int,input().split()) k.append((l,r)) mn=min(l,mn) mx=max(r, mx) for i in range(n): if k[i][0]==mn and k[i][1]==mx: print(i+1) return print(-1) return solution() ```
3
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
The first line contains string *s* of length *n* (2<=≀<=*n*<=≀<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≀<=*m*<=≀<=105) β€” the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t...
Print *m* integers β€” the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5...
1,699,426,025
2,147,483,647
Python 3
OK
TESTS
37
716
9,523,200
s = input() m = int(input()) ans = [] n = len(s) dp = [0 for _ in range(n)] t = 0 for i in range(1, n): if s[i] == s[i - 1]: t += 1 dp[i] = t for _ in range(m): l, r = map(int, input().split()) t = dp[r - 1] - dp[l - 1] ans.append(t) for j in range(m): print(ans[j])
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ...
```python s = input() m = int(input()) ans = [] n = len(s) dp = [0 for _ in range(n)] t = 0 for i in range(1, n): if s[i] == s[i - 1]: t += 1 dp[i] = t for _ in range(m): l, r = map(int, input().split()) t = dp[r - 1] - dp[l - 1] ans.append(t) for j in range(m): print(...
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of lines in the description. Then follow *n* lines β€” for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,570,713,373
2,147,483,647
PyPy 3
OK
TESTS
34
342
409,600
from sys import stdin from collections import defaultdict n=int(stdin.readline().rstrip()) df=defaultdict(int) for i in range(n): s=stdin.readline().rstrip() df[s]+=1 m=0 p="" for i in df.keys(): if m<df[i]: p=i m=df[i] print(p)
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python from sys import stdin from collections import defaultdict n=int(stdin.readline().rstrip()) df=defaultdict(int) for i in range(n): s=stdin.readline().rstrip() df[s]+=1 m=0 p="" for i in df.keys(): if m<df[i]: p=i m=df[i] print(p) ```
3.913737
888
A
Local Extrema
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=&gt;<=*...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of elements in array *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=1000) β€” the elements of array *a*.
Print the number of local extrema in the given array.
[ "3\n1 2 3\n", "4\n1 5 2 5\n" ]
[ "0\n", "2\n" ]
none
0
[ { "input": "3\n1 2 3", "output": "0" }, { "input": "4\n1 5 2 5", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "1\n548", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n3 2 3", "output": "1" }, { "inp...
1,690,349,327
2,147,483,647
Python 3
OK
TESTS
14
46
0
a=int(input()) l=list(map(int,input().split())) p=0 for k in range(1,a-1): if l[k-1]<l[k] and l[k]>l[k+1]: p+=1 elif l[k-1]>l[k] and l[k]<l[k+1]: p+=1 print(p)
Title: Local Extrema Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element c...
```python a=int(input()) l=list(map(int,input().split())) p=0 for k in range(1,a-1): if l[k-1]<l[k] and l[k]>l[k+1]: p+=1 elif l[k-1]>l[k] and l[k]<l[k+1]: p+=1 print(p) ```
3
682
B
Alyona and Mex
PROGRAMMING
1,200
[ "sortings" ]
null
null
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100<=000)Β β€” the number of elements in the Alyona's array. The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109)Β β€” the elements of the array.
Print one positive integerΒ β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
[ "5\n1 3 3 3 6\n", "2\n2 1\n" ]
[ "5\n", "3\n" ]
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
1,000
[ { "input": "5\n1 3 3 3 6", "output": "5" }, { "input": "2\n2 1", "output": "3" }, { "input": "1\n1", "output": "2" }, { "input": "1\n1000000000", "output": "2" }, { "input": "1\n2", "output": "2" }, { "input": "2\n1 1", "output": "2" }, { "...
1,520,952,026
2,147,483,647
Python 3
OK
TESTS
127
155
14,438,400
input();m=1 for i in (sorted(list(map(int,input().split())))): if i>=m:m+=1 print(m)
Title: Alyona and Mex Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is small...
```python input();m=1 for i in (sorted(list(map(int,input().split())))): if i>=m:m+=1 print(m) ```
3
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'...
The first input line contains the only integer *n* (1<=≀<=*n*<=≀<=200) β€” the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≀<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac...
Print the only number β€” the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point β€” point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n...
1,683,455,001
2,147,483,647
Python 3
OK
TESTS
26
92
0
n=int(input()) x=[list(map(int,input().split()))for i in range(n)] count = 0 for i in range(n): u, d, l, r = 0, 0, 0, 0 for j in range(n): if i==j: continue else: if x[i][0]>x[j][0] and x[i][1]==x[j][1]: r = 1 # else: # r = 0 ...
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give...
```python n=int(input()) x=[list(map(int,input().split()))for i in range(n)] count = 0 for i in range(n): u, d, l, r = 0, 0, 0, 0 for j in range(n): if i==j: continue else: if x[i][0]>x[j][0] and x[i][1]==x[j][1]: r = 1 # else: # ...
3
802
J
Send the Fool Further! (easy)
PROGRAMMING
1,400
[ "dfs and similar", "graphs", "trees" ]
null
null
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d...
The first line of the input contains the number of friends *n* (3<=≀<=*n*<=≀<=100). The next *n*<=-<=1 lines each contain three space-separated integers *u*, *v* and *c* (0<=≀<=*u*,<=*v*<=≀<=*n*<=-<=1, 1<=≀<=*c*<=≀<=104), meaning that *u* and *v* are friends (know each other directly) and the cost for travelling betwee...
Output a single integer – the maximum sum of costs.
[ "4\n0 1 4\n0 2 2\n2 3 3\n", "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10\n", "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378\n" ]
[ "5\n", "105\n", "5551\n" ]
In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2).
0
[ { "input": "4\n0 1 4\n0 2 2\n2 3 3", "output": "5" }, { "input": "3\n1 0 5987\n2 0 8891", "output": "8891" }, { "input": "10\n1 0 518\n2 0 4071\n3 1 121\n4 2 3967\n5 3 9138\n6 2 9513\n7 3 3499\n8 2 2337\n9 4 7647", "output": "15685" }, { "input": "11\n1 0 6646\n2 0 8816\n3 2 ...
1,650,304,734
2,147,483,647
Python 3
OK
TESTS
32
46
100,556,800
import threading import sys from sys import stdin input=stdin.readline sys.setrecursionlimit(10**8) from collections import defaultdict def main(): n=int(input()) graph=[[] for _ in range(n)] for _ in range(n-1): a,b,c=map(int,input().split()) graph[a].append((b,c)) gra...
Title: Send the Fool Further! (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the mess...
```python import threading import sys from sys import stdin input=stdin.readline sys.setrecursionlimit(10**8) from collections import defaultdict def main(): n=int(input()) graph=[[] for _ in range(n)] for _ in range(n-1): a,b,c=map(int,input().split()) graph[a].append((b,c)) ...
3
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number *n* (1<=<=≀<=<=*n*<=<=≀<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ...
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" },...
1,592,412,645
2,147,483,647
Python 3
OK
TESTS
20
216
307,200
import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) n = int(input()) currmax=0 winner='' l=[] for i in range(n): k,x = map(str,input().split()) l.append([k,int(x),i]) f = dict.fromkeys([i[0] for i in l],0) x = dict.fromkeys([i[0] for i in l],0) ind =[] for k in l: ...
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) n = int(input()) currmax=0 winner='' l=[] for i in range(n): k,x = map(str,input().split()) l.append([k,int(x),i]) f = dict.fromkeys([i[0] for i in l],0) x = dict.fromkeys([i[0] for i in l],0) ind =[] for ...
3.889711
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,682,962,534
2,147,483,647
Python 3
OK
TESTS
36
46
0
n = int(input()) res = bin(n).count("1") print(res)
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 n = int(input()) res = bin(n).count("1") print(res) ```
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,633,449,727
2,147,483,647
Python 3
OK
TESTS
34
61
6,963,200
n,x = map(int,input().strip().split()) stack=[] count,ans = x,0 for i in range(n): s = input().strip().split() if s[0] == '+': count += int(s[1]) if s[0] == '-': if count - int(s[1]) >= 0: count = count - int(s[1]) else: ans += 1 print(count, ans)
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,x = map(int,input().strip().split()) stack=[] count,ans = x,0 for i in range(n): s = input().strip().split() if s[0] == '+': count += int(s[1]) if s[0] == '-': if count - int(s[1]) >= 0: count = count - int(s[1]) else: ans += 1 print(count, ans) ```
3
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=Γ—<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer β€” the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,697,092,161
2,147,483,647
Python 3
OK
TESTS
25
92
0
matrix = [list(map(int, input().split())) for _ in range(5)] for i in range(5): for j in range(5): if matrix[i][j] == 1: row_pos = i col_pos = j moves = abs(2 - row_pos) + abs(2 - col_pos) print(moves)
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=Γ—<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri...
```python matrix = [list(map(int, input().split())) for _ in range(5)] for i in range(5): for j in range(5): if matrix[i][j] == 1: row_pos = i col_pos = j moves = abs(2 - row_pos) + abs(2 - col_pos) print(moves) ```
3
348
A
Mafia
PROGRAMMING
1,600
[ "binary search", "math", "sortings" ]
null
null
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min...
The first line contains integer *n* (3<=≀<=*n*<=≀<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109) β€” the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. 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.
[ "3\n3 2 2\n", "4\n2 2 2 2\n" ]
[ "4\n", "3\n" ]
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
500
[ { "input": "3\n3 2 2", "output": "4" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "7\n9 7 7 8 8 7 8", "output": "9" }, { "input": "10\n13 12 10 13 13 14 10 10 12 12", "output": "14" }, { "input": "10\n94 96 91 95 99 94 96 92 95 99", "output": "106" ...
1,636,821,007
2,147,483,647
Python 3
OK
TESTS
34
186
13,926,400
n = int(input()) nums = list(map(int, input().split())) if (sum(nums) + n - 2) // (n - 1) < max(nums): print(max(nums)) else: print((sum(nums) + n - 2) // (n - 1))
Title: Mafia Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a...
```python n = int(input()) nums = list(map(int, input().split())) if (sum(nums) + n - 2) // (n - 1) < max(nums): print(max(nums)) else: print((sum(nums) + n - 2) // (n - 1)) ```
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,674,291,202
2,147,483,647
PyPy 3
OK
TESTS
31
77
0
r1 = "qwertyuiop" r2 = "asdfghjkl;" r3 = "zxcvbnm,./" step = -1 if input() == "R" else 1 real = "" for c in input(): if c in r1: ind = r1.index(c) real += r1[ind + step] elif c in r2: ind = r2.index(c) real += r2[ind + step] elif c in r3: ind = r3.index(c) re...
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 r1 = "qwertyuiop" r2 = "asdfghjkl;" r3 = "zxcvbnm,./" step = -1 if input() == "R" else 1 real = "" for c in input(): if c in r1: ind = r1.index(c) real += r1[ind + step] elif c in r2: ind = r2.index(c) real += r2[ind + step] elif c in r3: ind = r3.index(c) ...
3
659
A
Round House
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th...
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≀<=*n*<=≀<=100,<=1<=≀<=*a*<=≀<=*n*,<=<=-<=100<=≀<=*b*<=≀<=100)Β β€” the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Print a single integer *k* (1<=≀<=*k*<=≀<=*n*)Β β€” the number of the entrance where Vasya will be at the end of his walk.
[ "6 2 -5\n", "5 1 3\n", "3 2 7\n" ]
[ "3\n", "4\n", "3\n" ]
The first example is illustrated by the picture in the statements.
500
[ { "input": "6 2 -5", "output": "3" }, { "input": "5 1 3", "output": "4" }, { "input": "3 2 7", "output": "3" }, { "input": "1 1 0", "output": "1" }, { "input": "1 1 -1", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "100 ...
1,609,514,459
2,147,483,647
PyPy 3
OK
TESTS
50
139
0
n, a, b = [int(x) for x in input().split(' ')] ans = (a + b) % n if ans == 0: ans = n print(ans)
Title: Round House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e...
```python n, a, b = [int(x) for x in input().split(' ')] ans = (a + b) % n if ans == 0: ans = n print(ans) ```
3
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≀<=*m*<=≀<=*n*<=≀<=100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≀<=*a**i*<=≀<=1000) β€” prices of the TV sets.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,683,002,655
2,147,483,647
PyPy 3-64
OK
TESTS
25
124
0
import math import bisect def sol(): a,b=map(int,input().split()) l=list(map(int,input().split())) ans=0 l.sort() for i in range(b): if l[i]<0: ans-=l[i] else: break print(ans) sol()
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python import math import bisect def sol(): a,b=map(int,input().split()) l=list(map(int,input().split())) ans=0 l.sort() for i in range(b): if l[i]<0: ans-=l[i] else: break print(ans) sol() ```
3.969
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,655,455,853
2,147,483,647
Python 3
OK
TESTS
87
561
7,884,800
n = int(input()) s = list(map(int, input().split())) sym = 0 i = 0 while i < n: if s[i] % 10 % 2 == 0: sym += s.pop(i) i -= 1 n -= 1 i += 1 if len(s) % 2 == 0 and len(s) != 0: for i in s: sym += i print(sym) elif len(s) % 2 != 0: s.sort(reverse = True) ...
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()) s = list(map(int, input().split())) sym = 0 i = 0 while i < n: if s[i] % 10 % 2 == 0: sym += s.pop(i) i -= 1 n -= 1 i += 1 if len(s) % 2 == 0 and len(s) != 0: for i in s: sym += i print(sym) elif len(s) % 2 != 0: s.sort(revers...
3
500
A
New Year Transportation
PROGRAMMING
1,000
[ "dfs and similar", "graphs", "implementation" ]
null
null
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=Γ—<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0...
The first line contains two space-separated integers *n* (3<=≀<=*n*<=≀<=3<=Γ—<=104) and *t* (2<=≀<=*t*<=≀<=*n*) β€” the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≀<=*a**i*<=≀<=*n*<=-<=*i*). It is guara...
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
[ "8 4\n1 2 1 2 1 2 1\n", "8 5\n1 2 1 2 1 1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
500
[ { "input": "8 4\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "8 5\n1 2 1 2 1 1 1", "output": "NO" }, { "input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "output": "YES" }, { "input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ...
1,675,836,804
2,147,483,647
PyPy 3-64
OK
TESTS
34
78
4,403,200
n,t=map(int,input().split()) l=list(map(int,input().split())) c=1 ans="NO" while c!=n: c+=l[c-1] if c==t: ans="YES" break print(ans)
Title: New Year Transportation Time Limit: None seconds Memory Limit: None megabytes Problem Description: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=Γ—<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o...
```python n,t=map(int,input().split()) l=list(map(int,input().split())) c=1 ans="NO" while c!=n: c+=l[c-1] if c==t: ans="YES" break print(ans) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16).
Output one number β€” the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,614,855,214
2,147,483,647
Python 3
OK
TESTS
35
124
0
import math N,M = input() .split() Area = int(N) * int(M) no = math.floor(Area/2) print(no)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python import math N,M = input() .split() Area = int(N) * int(M) no = math.floor(Area/2) print(no) ```
3.969
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
The only line contains four integers *n*, *t*, *k*, *d* (1<=≀<=*n*,<=*t*,<=*k*,<=*d*<=≀<=1<=000)Β β€” the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whe...
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO"...
1,603,215,463
2,147,483,647
Python 3
OK
TESTS
93
109
0
n,t,k,d=[int(x) for x in input().split() ] x=(int(d/t)+1)*k rest=n-x if rest >= 1: print('YES') else: print('NO')
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu...
```python n,t,k,d=[int(x) for x in input().split() ] x=(int(d/t)+1)*k rest=n-x if rest >= 1: print('YES') else: print('NO') ```
3
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,693,493,916
2,147,483,647
Python 3
OK
TESTS
44
92
0
n = input() c1 = 0 c0 = 0 for i in n: if i == "1": c0 = 0 c1 += 1 else: c1 = 0 c0 += 1 if c1 >= 7 or c0 >= 7: print("YES") break if c0 < 7 and c1 < 7: print("NO")
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A...
```python n = input() c1 = 0 c0 = 0 for i in n: if i == "1": c0 = 0 c1 += 1 else: c1 = 0 c0 += 1 if c1 >= 7 or c0 >= 7: print("YES") break if c0 < 7 and c1 < 7: print("NO") ```
3.977
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuska...
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) β€” the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) β€” the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a r...
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,694,916,383
2,147,483,647
Python 3
OK
TESTS
3
62
0
for _ in range(int(input())): a = int(input()) # exterior angle interor_angle = 180 - a if 360 % interor_angle == 0 and 360 // interor_angle >= 3: print("YES") else: print("NO")
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can...
```python for _ in range(int(input())): a = int(input()) # exterior angle interor_angle = 180 - a if 360 % interor_angle == 0 and 360 // interor_angle >= 3: print("YES") else: print("NO") ```
3
421
A
Pasha and Hamsters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams...
The first line contains integers *n*, *a*, *b* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*a*,<=*b*<=≀<=*n*) β€” the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains *a* distinct integers β€” the numbers of the apples Arthur likes. The next line...
Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
[ "4 2 3\n1 2\n2 3 4\n", "5 5 2\n3 4 1 2 5\n2 3\n" ]
[ "1 1 2 2\n", "1 1 1 1 1\n" ]
none
500
[ { "input": "4 2 3\n1 2\n2 3 4", "output": "1 1 2 2" }, { "input": "5 5 2\n3 4 1 2 5\n2 3", "output": "1 1 1 1 1" }, { "input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 7...
1,618,730,871
2,147,483,647
Python 3
OK
TESTS
32
62
0
n,a,b=map(int,input().split()) k=0 arthurlikes =list(map(int,input().split()))[:a] alexenderlikes=list(map(int,input().split()))[:b] for i in range(1,n+1): if i in arthurlikes: print("1",end=" ") else: print("2",end=" ")
Title: Pasha and Hamsters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between...
```python n,a,b=map(int,input().split()) k=0 arthurlikes =list(map(int,input().split()))[:a] alexenderlikes=list(map(int,input().split()))[:b] for i in range(1,n+1): if i in arthurlikes: print("1",end=" ") else: print("2",end=" ") ```
3
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≀<=*i*<=≀<=*j*<=≀<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string...
The first line contains a non-empty string *s* (1<=≀<=|*s*|<=≀<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number β€” the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11)...
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output"...
1,622,973,761
2,147,483,647
PyPy 3
OK
TESTS
43
156
1,843,200
s = input() starts = [] ind = 0 while ind + 3 < len(s): word = s[ind:ind + 4] if word == 'bear': starts.append(ind) ind += 1 if len(starts) == 0: print(0) exit(0) start = 0 cnt = 0 while start <= starts[-1]: end = None for el in starts: if el + 3 >= start and ...
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≀<=*i*<=≀<=*j...
```python s = input() starts = [] ind = 0 while ind + 3 < len(s): word = s[ind:ind + 4] if word == 'bear': starts.append(ind) ind += 1 if len(starts) == 0: print(0) exit(0) start = 0 cnt = 0 while start <= starts[-1]: end = None for el in starts: if el + 3 >= ...
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≀<=*p**i*<=≀<=100) β€” the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,688,458,684
2,147,483,647
Python 3
OK
TESTS
31
92
0
n = int(input()) m = map(int, input().split()) print(sum(m) / n) # Tue Jul 04 2023 11:18:04 GMT+0300 (Moscow Standard Time)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python n = int(input()) m = map(int, input().split()) print(sum(m) / n) # Tue Jul 04 2023 11:18:04 GMT+0300 (Moscow Standard Time) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,618,186,691
2,147,483,647
Python 3
OK
TESTS
81
154
307,200
n=int(input()) a=[] for _ in range(n): x,y,z=map(int,input().split()) a.append([x,y,z]) f=True for j in range(3): s=0 for i in range(n): s+=a[i][j] if(not s == 0): f=False break if(f): print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n=int(input()) a=[] for _ in range(n): x,y,z=map(int,input().split()) a.append([x,y,z]) f=True for j in range(3): s=0 for i in range(n): s+=a[i][j] if(not s == 0): f=False break if(f): print("YES") else: print("NO") ```
3.960928
977
A
Wrong Subtraction
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,...
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β€” the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number β€” the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
0
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "outpu...
1,696,395,561
2,147,483,647
PyPy 3-64
OK
TESTS
11
46
0
def solve(n,k): while k!=0: if n%10!=0: n=n-1 else: n=n//10 k-=1 return n n,k=map(int,input().split()) print(solve(n,k))
Title: Wrong Subtraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit ...
```python def solve(n,k): while k!=0: if n%10!=0: n=n-1 else: n=n//10 k-=1 return n n,k=map(int,input().split()) print(solve(n,k)) ```
3
44
A
Indian Summer
PROGRAMMING
900
[ "implementation" ]
A. Indian Summer
2
256
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β€” she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor...
Output the single number β€” the number of Alyona's leaves.
[ "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n", "3\noak yellow\noak yellow\noak yellow\n" ]
[ "4\n", "1\n" ]
none
0
[ { "input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4" }, { "input": "3\noak yellow\noak yellow\noak yellow", "output": "1" }, { "input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae", "output": "5" }, { "input"...
1,624,297,363
2,147,483,647
Python 3
OK
TESTS
29
154
0
tc = 1 while tc: tc-=1 n = int(input()) s = [] for i in range(n): s.append(input()) print(len(set(s)))
Title: Indian Summer Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β€” she doesn't take a leaf if it matches the color and the specie...
```python tc = 1 while tc: tc-=1 n = int(input()) s = [] for i in range(n): s.append(input()) print(len(set(s))) ```
3.9615
591
B
Rebranding
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebrandingΒ β€” an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog...
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=200<=000)Β β€” the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descr...
Print the new name of the corporation.
[ "6 1\npolice\np m\n", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n" ]
[ "molice\n", "cdcbcdcfcdc\n" ]
In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.co...
1,000
[ { "input": "6 1\npolice\np m", "output": "molice" }, { "input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b", "output": "cdcbcdcfcdc" }, { "input": "1 1\nf\nz h", "output": "f" }, { "input": "1 1\na\na b", "output": "b" }, { "input": "10 10\nlellelleel\ne l\n...
1,445,767,846
4,246
Python 3
OK
TESTS
27
1,185
6,758,400
inp=input().strip().split() n,m=int(inp[0]),int(inp[1]) s=input().strip() d={} for i in range(n): if(s[i] in d): d[s[i]].append(i) else: d[s[i]]=[i] for i in range(m): inp=input().strip().split() l0,l1=[],[] b0,b1=False,False if(inp[0] in d): #l0=d[inp[0]]...
Title: Rebranding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebrandingΒ β€” an active marketing strategy, that includes a set of measures to change either the brand ...
```python inp=input().strip().split() n,m=int(inp[0]),int(inp[1]) s=input().strip() d={} for i in range(n): if(s[i] in d): d[s[i]].append(i) else: d[s[i]]=[i] for i in range(m): inp=input().strip().split() l0,l1=[],[] b0,b1=False,False if(inp[0] in d): #l0...
3
134
A
Average Numbers
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one).
The first line contains the integer *n* (2<=≀<=*n*<=≀<=2Β·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1000). All the elements are positive integers.
Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*. If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print ...
[ "5\n1 2 3 4 5\n", "4\n50 50 50 50\n" ]
[ "1\n3 ", "4\n1 2 3 4 " ]
none
500
[ { "input": "5\n1 2 3 4 5", "output": "1\n3 " }, { "input": "4\n50 50 50 50", "output": "4\n1 2 3 4 " }, { "input": "3\n2 3 1", "output": "1\n1 " }, { "input": "2\n4 2", "output": "0" }, { "input": "2\n1 1", "output": "2\n1 2 " }, { "input": "10\n3 3 3 ...
1,599,326,911
2,147,483,647
Python 3
OK
TESTS
58
265
16,896,000
n=int(input());a=list(map(int,input().split())) q,r=sum(a),[] r=[str(i+1) for i in range(n) if a[i]*n==q] print(len(r),"\n"," ".join(r))
Title: Average Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). ...
```python n=int(input());a=list(map(int,input().split())) q,r=sum(a),[] r=[str(i+1) for i in range(n) if a[i]*n==q] print(len(r),"\n"," ".join(r)) ```
3
463
B
Caisa and Pylons
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is ...
The first line contains integer *n* (1<=≀<=*n*<=≀<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≀<=<=*h**i*<=<=≀<=<=105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
[ "5\n3 4 3 2 4\n", "3\n4 4 4\n" ]
[ "4\n", "4\n" ]
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
1,000
[ { "input": "5\n3 4 3 2 4", "output": "4" }, { "input": "3\n4 4 4", "output": "4" }, { "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20...
1,697,610,255
2,147,483,647
Python 3
OK
TESTS
49
77
13,107,200
n = input() h = [int(i) for i in input().split()] print(max(h))
Title: Caisa and Pylons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0...
```python n = input() h = [int(i) for i in input().split()] print(max(h)) ```
3
837
A
Text Volume
PROGRAMMING
800
[ "implementation" ]
null
null
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text.
The first line contains one integer number *n* (1<=≀<=*n*<=≀<=200) β€” length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Print one integer number β€” volume of text.
[ "7\nNonZERO\n", "24\nthis is zero answer text\n", "24\nHarbour Space University\n" ]
[ "5\n", "0\n", "1\n" ]
In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
0
[ { "input": "7\nNonZERO", "output": "5" }, { "input": "24\nthis is zero answer text", "output": "0" }, { "input": "24\nHarbour Space University", "output": "1" }, { "input": "2\nWM", "output": "2" }, { "input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd...
1,639,953,516
2,147,483,647
PyPy 3-64
OK
TESTS
29
93
0
import sys, math input=sys.stdin.readline INF=int(1e9)+7 def solve(): n=int(input()) s=input().rstrip().split() ans=0 for i in s: cnt=0 for j in i: if 'A'<=j<='Z': cnt+=1 ans=max(ans,cnt) print(ans) t=1 while t: t-=1 ...
Title: Text Volume Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex...
```python import sys, math input=sys.stdin.readline INF=int(1e9)+7 def solve(): n=int(input()) s=input().rstrip().split() ans=0 for i in s: cnt=0 for j in i: if 'A'<=j<='Z': cnt+=1 ans=max(ans,cnt) print(ans) t=1 while t: ...
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,582,606,096
2,147,483,647
Python 3
OK
TESTS
102
124
307,200
a=input() x=int(a,2) b=input() y=int(b,2) c=bin(x^y).replace('0b','') if len(a)>len(c): for i in range(0,len(a)-len(c)): print(0,end='') print(c) else:print(c)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a=input() x=int(a,2) b=input() y=int(b,2) c=bin(x^y).replace('0b','') if len(a)>len(c): for i in range(0,len(a)-len(c)): print(0,end='') print(c) else:print(c) ```
3.968428
722
B
Verse Pattern
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowel...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of lines in the text. The second line contains integers *p*1,<=...,<=*p**n* (0<=≀<=*p**i*<=≀<=100)Β β€” the verse pattern. Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guarant...
If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
[ "3\n2 2 3\nintel\ncode\nch allenge\n", "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n", "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, one can split words into syllables in the following way: Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.
500
[ { "input": "3\n2 2 3\nintel\ncode\nch allenge", "output": "YES" }, { "input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz", "output": "NO" }, { "input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageo...
1,664,444,660
2,147,483,647
Python 3
OK
TESTS
54
46
0
a, arrd, ans = int(input()), list(map(int, input().split())), "YES" for i in range(a): k = arrd[i] s = input() if s.count('a') + s.count('e') + s.count('i') + s.count('o') + s.count('u') + s.count('y') != k: ans = "NO" print(ans)
Title: Verse Pattern Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary num...
```python a, arrd, ans = int(input()), list(map(int, input().split())), "YES" for i in range(a): k = arrd[i] s = input() if s.count('a') + s.count('e') + s.count('i') + s.count('o') + s.count('u') + s.count('y') != k: ans = "NO" print(ans) ```
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,653,651,575
2,147,483,647
Python 3
OK
TESTS
49
78
0
d = {} for s in [*open(0)][1:]: cn = False a,b = s.split() for i in d: if d[i] == a: cn = True d[i] = b if not cn:d[a] = b print(len(d)) for i in d: print(f'{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 d = {} for s in [*open(0)][1:]: cn = False a,b = s.split() for i in d: if d[i] == a: cn = True d[i] = b if not cn:d[a] = b print(len(d)) for i in d: print(f'{i} {d[i]}') ```
3
408
A
Line to Cashier
PROGRAMMING
900
[ "implementation" ]
null
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ...
The first line contains integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≀<=*k**i*<=≀<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i*...
Print a single integer β€” the minimum number of seconds Vasya needs to get to the cashier.
[ "1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n" ]
[ "20\n", "100\n" ]
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100Β·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1Β·5 + 2Β·5 + 2Β·5 + 3Β·5 + 4Β·15 = 100 seconds. He will need 1Β·5 + 9Β·5 + 1Β·5 + 3Β·15 = 100 seconds for the third one and 7Β·5 + 8Β·5 + 2Β·15 = 105 seconds for the fou...
500
[ { "input": "1\n1\n1", "output": "20" }, { "input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100" }, { "input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "output": "100" }, { "input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"...
1,666,380,023
2,147,483,647
Python 3
OK
TESTS
20
46
0
def best_cash(): cashes = int(input()) costumers = input().split(' ') best = 0 for costumer in costumers: items = input().split(' ') if len(items) == 0: return 0 time = 0 for item in items: time += int(item) * 5 + 15 if best == 0: best = time if time < best: best = time ...
Title: Line to Cashier Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* c...
```python def best_cash(): cashes = int(input()) costumers = input().split(' ') best = 0 for costumer in costumers: items = input().split(' ') if len(items) == 0: return 0 time = 0 for item in items: time += int(item) * 5 + 15 if best == 0: best = time if time < best: best...
3
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
The first line contains an integer *n* (2<=≀<=*n*<=≀<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≀<=*h**i*,<=*a**i*<=≀<=100) β€” the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea...
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n...
1,693,274,438
2,147,483,647
PyPy 3
OK
TESTS
31
186
0
import sys from itertools import permutations # Define constants INF = float('inf') MOD = 10**9 + 7 # Define input functions def read_int(): return int(sys.stdin.readline()) def read_ints(): return list(map(int, sys.stdin.readline().split())) def read_str(): return sys.stdin.readline().stri...
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W...
```python import sys from itertools import permutations # Define constants INF = float('inf') MOD = 10**9 + 7 # Define input functions def read_int(): return int(sys.stdin.readline()) def read_ints(): return list(map(int, sys.stdin.readline().split())) def read_str(): return sys.stdin.readl...
3
6
A
Triangle
PROGRAMMING
900
[ "brute force", "geometry" ]
A. Triangle
2
64
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β€” lengthes of the sticks.
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s...
[ "4 2 1 3\n", "7 2 2 4\n", "3 5 9 1\n" ]
[ "TRIANGLE\n", "SEGMENT\n", "IMPOSSIBLE\n" ]
none
0
[ { "input": "4 2 1 3", "output": "TRIANGLE" }, { "input": "7 2 2 4", "output": "SEGMENT" }, { "input": "3 5 9 1", "output": "IMPOSSIBLE" }, { "input": "3 1 5 1", "output": "IMPOSSIBLE" }, { "input": "10 10 10 10", "output": "TRIANGLE" }, { "input": "11 ...
1,693,868,992
2,147,483,647
PyPy 3-64
OK
TESTS
83
124
0
#accumalated 2d matrix # listy=[list(accumulate(row)) for row in accumulate([[i for i in list(map(int,input().split()))] for j in range(n)])] import sys input = lambda: sys.stdin.readline().rstrip() t= 1 for i in range(t): a,b,c,d=map(int,input().split()) listy=[a,b,c,d] listy.sort() if( lis...
Title: Triangle Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o...
```python #accumalated 2d matrix # listy=[list(accumulate(row)) for row in accumulate([[i for i in list(map(int,input().split()))] for j in range(n)])] import sys input = lambda: sys.stdin.readline().rstrip() t= 1 for i in range(t): a,b,c,d=map(int,input().split()) listy=[a,b,c,d] listy.sort() ...
3.969
376
B
I.O.U.
PROGRAMMING
1,300
[ "implementation" ]
null
null
Imagine that there is a group of three friends: A, B and Π‘. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The...
The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=100;Β 0<=≀<=*m*<=≀<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*;Β *a**i*<=β‰ <=*b**i*;Β 1<=≀<=*c**i*<=≀<=100), which mean that person *a**i* owes person *b**i* *c**i...
Print a single integer β€” the minimum sum of debts in the optimal rearrangement.
[ "5 3\n1 2 10\n2 3 1\n2 4 1\n", "3 0\n", "4 3\n1 2 1\n2 3 1\n3 1 1\n" ]
[ "10\n", "0\n", "0\n" ]
In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10. In the second sample, there are no debts. In the third sample, you can annul all the debts.
1,000
[ { "input": "5 3\n1 2 10\n2 3 1\n2 4 1", "output": "10" }, { "input": "3 0", "output": "0" }, { "input": "4 3\n1 2 1\n2 3 1\n3 1 1", "output": "0" }, { "input": "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\...
1,692,348,313
2,147,483,647
PyPy 3-64
OK
TESTS
29
124
4,915,200
n,m=map(int,input().split()) d={} for i in range(m): a,b,c=map(int,input().split()) if (a not in d): d[a]=0 if (b not in d): d[b]=0 d[a]+=c d[b]-=c s=0 for i in d: if d[i]>0: s+=d[i] print(s)
Title: I.O.U. Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that there is a group of three friends: A, B and Π‘. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearran...
```python n,m=map(int,input().split()) d={} for i in range(m): a,b,c=map(int,input().split()) if (a not in d): d[a]=0 if (b not in d): d[b]=0 d[a]+=c d[b]-=c s=0 for i in d: if d[i]>0: s+=d[i] print(s) ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
The only line of input contains the name of some exhibitΒ β€” the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integerΒ β€” the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "...
1,652,727,131
2,147,483,647
Python 3
OK
TESTS
44
46
4,505,600
s = map(ord, input()) A = ord('a') Z = ord('z') n = 0 res = 0 for x in s: if A <= x <= Z: x -= A res += min(abs(x-n), 26 - abs(x - n)) n = x else: break print(res)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devis...
```python s = map(ord, input()) A = ord('a') Z = ord('z') n = 0 res = 0 for x in s: if A <= x <= Z: x -= A res += min(abs(x-n), 26 - abs(x - n)) n = x else: break print(res) ```
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,649,941,574
2,147,483,647
PyPy 3-64
OK
TESTS
35
62
2,252,800
n,k=map(int,input().split()) c=0 l=list(map(int,input().split())) k=5-k for i in range(n): if l[i]<=k: c=c+1 print(c//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,k=map(int,input().split()) c=0 l=list(map(int,input().split())) k=5-k for i in range(n): if l[i]<=k: c=c+1 print(c//3) ```
3
347
A
Difference Row
PROGRAMMING
1,300
[ "constructive algorithms", "implementation", "sortings" ]
null
null
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu...
The first line of the input contains integer *n* (2<=≀<=*n*<=≀<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≀<=1000).
Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value.
[ "5\n100 -100 50 0 -50\n" ]
[ "100 -50 0 50 -100 \n" ]
In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one. Sequence *x*<sub class="lower-inde...
500
[ { "input": "5\n100 -100 50 0 -50", "output": "100 -50 0 50 -100 " }, { "input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282", "output": "963 -795 -367 -282 -49 -26 0 764 948 -939 " }, { "input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 ...
1,671,883,689
2,147,483,647
Python 3
OK
TESTS
16
92
0
# LUOGU_RID: 97912179 n = int(input()) nums = list(map(int, input().split())) maximum = max(nums) minimum = min(nums) nums.remove(maximum) nums.remove(minimum) new = [] new.append(maximum) nums.sort() for x in nums: new.append(x) new.append(minimum) for x in new: print(x, end=' ')
Title: Difference Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote ...
```python # LUOGU_RID: 97912179 n = int(input()) nums = list(map(int, input().split())) maximum = max(nums) minimum = min(nums) nums.remove(maximum) nums.remove(minimum) new = [] new.append(maximum) nums.sort() for x in nums: new.append(x) new.append(minimum) for x in new: print(x, end=' ')...
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,687,603,585
2,147,483,647
Python 3
OK
TESTS
81
92
0
n=int(input()) count=0 sum=0 total=0 for i in range(n): x,y,z=map(int,input().split()) count+=x total+=y sum+=z if count==total==sum==0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n=int(input()) count=0 sum=0 total=0 for i in range(n): x,y,z=map(int,input().split()) count+=x total+=y sum+=z if count==total==sum==0: print('YES') else: print('NO') ```
3.977
320
B
Ping-Pong (Easy Version)
PROGRAMMING
1,500
[ "dfs and similar", "graphs" ]
null
null
In this problem at each moment you have a set of intervals. You can move from interval (*a*,<=*b*) from our set to interval (*c*,<=*d*) from our set if and only if *c*<=&lt;<=*a*<=&lt;<=*d* or *c*<=&lt;<=*b*<=&lt;<=*d*. Also there is a path from interval *I*1 from our set to interval *I*2 from our set if there is a seq...
The first line of the input contains integer *n* denoting the number of queries, (1<=≀<=*n*<=≀<=100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value. It's guaranteed that all queries are correct.
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
[ "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n" ]
[ "NO\nYES\n" ]
none
1,000
[ { "input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES" }, { "input": "10\n1 -311 -186\n1 -1070 -341\n1 -1506 -634\n1 688 1698\n2 2 4\n1 70 1908\n2 1 2\n2 2 4\n1 -1053 1327\n2 5 4", "output": "NO\nNO\nNO\nYES" }, { "input": "10\n1 -1365 -865\n1 1244 1834\n2 1 2\n1 -1508 -...
1,662,919,428
2,147,483,647
PyPy 3-64
OK
TESTS
24
184
2,662,400
from collections import defaultdict, deque import sys ONLINE_JUDGE = True if not ONLINE_JUDGE: sys.stdin = open("input.text", "r") ############ ---- Input Functions ---- ############ def inp(): # integer return(int(input())) def inlt(): # lists return(list(map(int,input().split()))) def insr(): # list o...
Title: Ping-Pong (Easy Version) Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem at each moment you have a set of intervals. You can move from interval (*a*,<=*b*) from our set to interval (*c*,<=*d*) from our set if and only if *c*<=&lt;<=*a*<=&lt;<=*d* or *c*<=&lt;<=*b*<=&...
```python from collections import defaultdict, deque import sys ONLINE_JUDGE = True if not ONLINE_JUDGE: sys.stdin = open("input.text", "r") ############ ---- Input Functions ---- ############ def inp(): # integer return(int(input())) def inlt(): # lists return(list(map(int,input().split()))) def insr()...
3
682
A
Alyona and Numbers
PROGRAMMING
1,100
[ "constructive algorithms", "math", "number theory" ]
null
null
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integersΒ β€” the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first...
The only line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=1<=000<=000).
Print the only integerΒ β€” the number of pairs of integers (*x*,<=*y*) such that 1<=≀<=*x*<=≀<=*n*, 1<=≀<=*y*<=≀<=*m* and (*x*<=+<=*y*) is divisible by 5.
[ "6 12\n", "11 14\n", "1 5\n", "3 8\n", "5 7\n", "21 21\n" ]
[ "14\n", "31\n", "1\n", "5\n", "7\n", "88\n" ]
Following pairs are suitable in the first sample case: - for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9. Only th...
500
[ { "input": "6 12", "output": "14" }, { "input": "11 14", "output": "31" }, { "input": "1 5", "output": "1" }, { "input": "3 8", "output": "5" }, { "input": "5 7", "output": "7" }, { "input": "21 21", "output": "88" }, { "input": "10 15", ...
1,593,477,186
2,147,483,647
PyPy 3
OK
TESTS
128
186
25,395,200
n,m=map(int,input().split()) ans=0 rems=[0]*m for i in range(1,n+1): yep=i%5 ans+=(yep+m)//5 print(ans)
Title: Alyona and Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integersΒ β€” the first column containing integers from 1 to *n* and the second containing integers ...
```python n,m=map(int,input().split()) ans=0 rems=[0]*m for i in range(1,n+1): yep=i%5 ans+=(yep+m)//5 print(ans) ```
3
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=Γ—<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,655,722,888
2,147,483,647
PyPy 3-64
OK
TESTS
33
92
2,560,000
import math from re import I lights = [[1, 1, 1] for i in range(3)] t = [] for i in range(3): c = list(map(int, input().split(' '))) t.append(c) new_t = [[1,1,1] for i in range(3)] for i in range(len(t)): for j in range(len(t[i])): total = 0 top, bot, right, left = 0, 0, 0, ...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=Γ—<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python import math from re import I lights = [[1, 1, 1] for i in range(3)] t = [] for i in range(3): c = list(map(int, input().split(' '))) t.append(c) new_t = [[1,1,1] for i in range(3)] for i in range(len(t)): for j in range(len(t[i])): total = 0 top, bot, right, left =...
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of lines in the description. Then follow *n* lines β€” for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,675,183,323
2,147,483,647
Python 3
OK
TESTS
34
92
0
n=int(input()) i=0 N_list=[] while i<n: N=input() N_list.append(N) i=i+1 N_list team1=N_list[0] i=0 team2='' counter=0 reverse_counter=0 while i<n: if N_list[i]==team1: counter=counter+1 else: team2=N_list[i] reverse_counter=reverse_counter+1 i=i+1 if ...
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python n=int(input()) i=0 N_list=[] while i<n: N=input() N_list.append(N) i=i+1 N_list team1=N_list[0] i=0 team2='' counter=0 reverse_counter=0 while i<n: if N_list[i]==team1: counter=counter+1 else: team2=N_list[i] reverse_counter=reverse_counter+1 ...
3.977
447
B
DZY Loves Strings
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to in...
The first line contains a single string *s*Β (1<=≀<=|*s*|<=≀<=103). The second line contains a single integer *k*Β (0<=≀<=*k*<=≀<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Print a single integer β€” the largest possible value of the resulting string DZY could get.
[ "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ]
[ "41\n" ]
In the test sample DZY can obtain "abcbbc", *value* = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
1,000
[ { "input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41" }, { "input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "output": "29978" }, { "input": "ajeeseerqnpaujubmajpibxrccazaawetyw...
1,609,602,422
2,147,483,647
Python 3
OK
TESTS
24
108
0
string = input() k = int(input()) lst = list(map(int, input().split())) rs = 0 for i in range(0, len(string)): rs += (i + 1) * lst[ord(string[i]) - 97] for i in range(0, k): rs += (i + len(string) + 1) * max(lst) print(rs)
Title: DZY Loves Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str...
```python string = input() k = int(input()) lst = list(map(int, input().split())) rs = 0 for i in range(0, len(string)): rs += (i + 1) * lst[ord(string[i]) - 97] for i in range(0, k): rs += (i + len(string) + 1) * max(lst) print(rs) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,674,980,943
2,147,483,647
Python 3
OK
TESTS
102
46
0
a=str(input()) b=str(input()) m=int(a,2) n=int(b,2) k=len(a) l=bin(m^n)[2:] print(l.rjust(k,'0'))
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a=str(input()) b=str(input()) m=int(a,2) n=int(b,2) k=len(a) l=bin(m^n)[2:] print(l.rjust(k,'0')) ```
3.9885
837
A
Text Volume
PROGRAMMING
800
[ "implementation" ]
null
null
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text.
The first line contains one integer number *n* (1<=≀<=*n*<=≀<=200) β€” length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Print one integer number β€” volume of text.
[ "7\nNonZERO\n", "24\nthis is zero answer text\n", "24\nHarbour Space University\n" ]
[ "5\n", "0\n", "1\n" ]
In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
0
[ { "input": "7\nNonZERO", "output": "5" }, { "input": "24\nthis is zero answer text", "output": "0" }, { "input": "24\nHarbour Space University", "output": "1" }, { "input": "2\nWM", "output": "2" }, { "input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd...
1,502,039,419
2,147,483,647
Python 3
OK
TESTS
29
77
4,608,000
_ = int(input()) text =list(input().split()) ans = 0 for word in text : count = 0 for char in word: if char >= 'A' and char <= 'Z' : count += 1 ans = max(ans , count) print(ans)
Title: Text Volume Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex...
```python _ = int(input()) text =list(input().split()) ans = 0 for word in text : count = 0 for char in word: if char >= 'A' and char <= 'Z' : count += 1 ans = max(ans , count) print(ans) ```
3
5
A
Chat Servers Outgoing Traffic
PROGRAMMING
1,000
[ "implementation" ]
A. Chat Server's Outgoing Traffic
1
64
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person...
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - +&lt;name&gt; for 'Add' command. - -&lt;name&gt; for 'Remove' command. - &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;s...
Print a single number β€” answer to the problem.
[ "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n" ]
[ "9\n", "14\n" ]
none
0
[ { "input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "output": "9" }, { "input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate", "output": "14" }, { "input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO...
1,588,061,968
2,147,483,647
Python 3
OK
TESTS
30
248
0
import sys users = list() ans = 0 for line in sys.stdin: line = line.rstrip() if line[0] == '+': users.append(line[1:]) elif line[0] == '-': users.remove(line[1:]) else: msg = line[line.index(':') + 1:] ans += len(msg) * len(users) print(ans)
Title: Chat Servers Outgoing Traffic Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr...
```python import sys users = list() ans = 0 for line in sys.stdin: line = line.rstrip() if line[0] == '+': users.append(line[1:]) elif line[0] == '-': users.remove(line[1:]) else: msg = line[line.index(':') + 1:] ans += len(msg) * len(users) print(ans) `...
3.876
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number β€” the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,698,243,516
2,147,483,647
Python 3
OK
TESTS
27
46
0
# Read the input string input_string = input().strip() # Extract letters and remove brackets and spaces letters = input_string[1:-1].replace(", ", "") # Create a set of distinct letters distinct_letters = set(letters) # Calculate the number of distinct letters num_distinct_letters = len(distinct_letters) ...
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python # Read the input string input_string = input().strip() # Extract letters and remove brackets and spaces letters = input_string[1:-1].replace(", ", "") # Create a set of distinct letters distinct_letters = set(letters) # Calculate the number of distinct letters num_distinct_letters = len(distinct_...
3
548
A
Mike and Fax
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ...
The first line of input contains string *s* containing lowercase English letters (1<=≀<=|*s*|<=≀<=1000). The second line contains integer *k* (1<=≀<=*k*<=≀<=1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
[ "saba\n2\n", "saddastavvat\n2\n" ]
[ "NO\n", "YES\n" ]
Palindrome is a string reading the same forward and backward. In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
500
[ { "input": "saba\n2", "output": "NO" }, { "input": "saddastavvat\n2", "output": "YES" }, { "input": "aaaaaaaaaa\n3", "output": "NO" }, { "input": "aaaaaa\n3", "output": "YES" }, { "input": "abaacca\n2", "output": "NO" }, { "input": "a\n1", "output"...
1,636,024,586
2,147,483,647
Python 3
OK
TESTS
56
62
4,505,600
def checkPalindrome(s): i, j = 0, len(s)-1 while i<=j: if s[i]!=s[j]: return False i += 1 j -= 1 return True bag = input() k = int(input()) if len(bag)%k: print("NO") exit() for i in range(0, len(bag), len(bag)//k): if not checkPalindrome(b...
Title: Mike and Fax Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure ...
```python def checkPalindrome(s): i, j = 0, len(s)-1 while i<=j: if s[i]!=s[j]: return False i += 1 j -= 1 return True bag = input() k = int(input()) if len(bag)%k: print("NO") exit() for i in range(0, len(bag), len(bag)//k): if not checkPa...
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,588,462,924
2,147,483,647
Python 3
OK
TESTS
30
216
0
string = input() liste = list(string) upper = 0 lower = 0 for char in liste: if char.isupper() == True: upper += 1 else: lower += 1 if upper > lower: print(string.upper()) else: print(string.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python string = input() liste = list(string) upper = 0 lower = 0 for char in liste: if char.isupper() == True: upper += 1 else: lower += 1 if upper > lower: print(string.upper()) else: print(string.lower()) ```
3.946
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=Γ—<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ—<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≀<=*r*,<=*c*<=≀<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters β€” the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,609,346,542
2,147,483,647
PyPy 3
OK
TESTS
42
310
0
r,c=map(int,input().split()) row=[0]*11 col=[0]*11 for i in range(r): ch = input() for j in range(c): if ch[j]=='S': row[i]=1 col[j]=1 cakes=0 for i in range(r): for j in range(c): if row[i]==0 or col[j]==0: cakes+=1 print(cakes) ...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=Γ—<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ—<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python r,c=map(int,input().split()) row=[0]*11 col=[0]*11 for i in range(r): ch = input() for j in range(c): if ch[j]=='S': row[i]=1 col[j]=1 cakes=0 for i in range(r): for j in range(c): if row[i]==0 or col[j]==0: cakes+=1 print(cakes...
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,694,097,230
2,147,483,647
PyPy 3-64
OK
TESTS
81
124
0
from math import* u,v,w=0,0,0 for i in range(int(input())): x,y,z=list(map(int,input().split())) u+=x v+=y w+=z print(('NO','YES')[u==0 and v==0 and w==0])
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python from math import* u,v,w=0,0,0 for i in range(int(input())): x,y,z=list(map(int,input().split())) u+=x v+=y w+=z print(('NO','YES')[u==0 and v==0 and w==0]) ```
3.969
977
A
Wrong Subtraction
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,...
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β€” the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number β€” the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
0
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "outpu...
1,698,288,148
2,147,483,647
Python 3
OK
TESTS
11
31
0
n = list(map(int,input().split())) c=n[0] d=str(c) for _ in range(n[1]): if c % 10 != 0: c -= 1 else: c //= 10 print(c)
Title: Wrong Subtraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit ...
```python n = list(map(int,input().split())) c=n[0] d=str(c) for _ in range(n[1]): if c % 10 != 0: c -= 1 else: c //= 10 print(c) ```
3
911
E
Stack Sorting
PROGRAMMING
2,000
[ "constructive algorithms", "data structures", "greedy", "implementation" ]
null
null
Let's suppose you have an array *a*, a stack *s* (initially empty) and an array *b* (also initially empty). You may perform the following operations until both *a* and *s* are empty: - Take the first element of *a*, push it into *s* and remove it from *a* (if *a* is not empty); - Take the top element from *s*, appe...
The first line contains two integers *n* and *k* (2<=≀<=*n*<=≀<=200000, 1<=≀<=*k*<=&lt;<=*n*) β€” the size of a desired permutation, and the number of elements you are given, respectively. The second line contains *k* integers *p*1, *p*2, ..., *p**k* (1<=≀<=*p**i*<=≀<=*n*) β€” the first *k* elements of *p*. These integers...
If it is possible to restore a stack-sortable permutation *p* of size *n* such that the first *k* elements of *p* are equal to elements given in the input, print lexicographically maximal such permutation. Otherwise print -1.
[ "5 3\n3 2 1\n", "5 3\n2 3 1\n", "5 1\n3\n", "5 2\n3 4\n" ]
[ "3 2 1 5 4 ", "-1\n", "3 2 1 5 4 ", "-1\n" ]
none
0
[ { "input": "5 3\n3 2 1", "output": "3 2 1 5 4 " }, { "input": "5 3\n2 3 1", "output": "-1" }, { "input": "5 1\n3", "output": "3 2 1 5 4 " }, { "input": "5 2\n3 4", "output": "-1" }, { "input": "100000 1\n98419", "output": "98419 98418 98417 98416 98415 98414 9...
1,595,145,439
7,039
Python 3
OK
TESTS
202
280
23,244,800
import sys n,k = map(int,input().split()) a = list(map(int,input().split())) setofa = set(a) s = [] f= False ai = 0 ans = [] for i in range(1, n+1): if i in setofa: while ai < k and (len(s)==0 or s[-1]!=i): s.append(a[ai]) ai += 1 if len(s) == 0 or s[-1] != i: f = True ...
Title: Stack Sorting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's suppose you have an array *a*, a stack *s* (initially empty) and an array *b* (also initially empty). You may perform the following operations until both *a* and *s* are empty: - Take the first element of *a*, pu...
```python import sys n,k = map(int,input().split()) a = list(map(int,input().split())) setofa = set(a) s = [] f= False ai = 0 ans = [] for i in range(1, n+1): if i in setofa: while ai < k and (len(s)==0 or s[-1]!=i): s.append(a[ai]) ai += 1 if len(s) == 0 or s[-1] != i: f = ...
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,458,205,072
2,147,483,647
Python 3
OK
TESTS
48
62
409,600
D = {'1': 1, '3': 6, '5': 120, '7': 5040, '9': 362880, '31': 8222838654177922817725562880000000, '30': 265252859812191058636308480000000, '33': 8683317618811886495518194401280000000, '32': 263130836933693530167218012160000000, '35': 10333147966386144929666651337523200000000, '34': 2952327990396041408476186096435200...
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 D = {'1': 1, '3': 6, '5': 120, '7': 5040, '9': 362880, '31': 8222838654177922817725562880000000, '30': 265252859812191058636308480000000, '33': 8683317618811886495518194401280000000, '32': 263130836933693530167218012160000000, '35': 10333147966386144929666651337523200000000, '34': 295232799039604140847618...
3
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin...
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$)Β β€” the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$)Β β€” coord...
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3...
1,530,809,420
920
Python 3
OK
TESTS
45
124
0
nd = input().split() n = int(nd[0]) d = int(nd[1]) hotels = sorted([int(i) for i in input().split()]) count = 2 for i in range(len(hotels) - 1): count += min(max(hotels[i+1] - hotels[i] - 2*d + 1, 0), 2) print(count)
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer c...
```python nd = input().split() n = int(nd[0]) d = int(nd[1]) hotels = sorted([int(i) for i in input().split()]) count = 2 for i in range(len(hotels) - 1): count += min(max(hotels[i+1] - hotels[i] - 2*d + 1, 0), 2) print(count) ```
3
371
A
K-Periodic Array
PROGRAMMING
1,000
[ "greedy", "implementation", "math" ]
null
null
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it...
The first line of the input contains a pair of integers *n*, *k* (1<=≀<=*k*<=≀<=*n*<=≀<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=2), *a**i* is the *i*-th element of ...
Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0.
[ "6 2\n2 1 2 2 2 1\n", "8 4\n1 1 2 1 1 1 2 1\n", "9 3\n2 1 1 1 2 1 1 1 2\n" ]
[ "1\n", "0\n", "3\n" ]
In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1]. In the second sample, the given array already is 4-periodic. In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1...
500
[ { "input": "6 2\n2 1 2 2 2 1", "output": "1" }, { "input": "8 4\n1 1 2 1 1 1 2 1", "output": "0" }, { "input": "9 3\n2 1 1 1 2 1 1 1 2", "output": "3" }, { "input": "1 1\n2", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 2\n2 2...
1,597,587,941
2,147,483,647
Python 3
OK
TESTS
24
124
409,600
from collections import Counter X = list(map(int, input().split())) Numbers = list(map(int, input().split())) print(sum((X[0] // X[1] - max(Counter(Numbers[i::X[1]]).values())) for i in range(X[1]))) # A new start # Here in Tabas # Waiting for the big news
Title: K-Periodic Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represent...
```python from collections import Counter X = list(map(int, input().split())) Numbers = list(map(int, input().split())) print(sum((X[0] // X[1] - max(Counter(Numbers[i::X[1]]).values())) for i in range(X[1]))) # A new start # Here in Tabas # Waiting for the big news ```
3
915
A
Garden
PROGRAMMING
900
[ "implementation" ]
null
null
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat...
The first line of input contains two integer numbers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≀<=*a**i*<=≀<=100) β€” the length of the segment that can be watered by the *i*-th bucket in one ...
Print one integer number β€” the minimum number of hours required to water the garden.
[ "3 6\n2 3 5\n", "6 7\n1 2 3 4 5 6\n" ]
[ "2\n", "7\n" ]
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
0
[ { "input": "3 6\n2 3 5", "output": "2" }, { "input": "6 7\n1 2 3 4 5 6", "output": "7" }, { "input": "5 97\n1 10 50 97 2", "output": "1" }, { "input": "5 97\n1 10 50 100 2", "output": "97" }, { "input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5...
1,619,875,530
330
PyPy 3
OK
TESTS
83
108
0
import sys import math input = sys.stdin.readline for _ in range(1): n,k = map(int,input().split()) l = list(map(int,input().split())) ans = 10**18 for i in l: if k%i == 0: ans = min(ans,k//i) print(ans)
Title: Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ...
```python import sys import math input = sys.stdin.readline for _ in range(1): n,k = map(int,input().split()) l = list(map(int,input().split())) ans = 10**18 for i in l: if k%i == 0: ans = min(ans,k//i) print(ans) ```
3
929
A
ΠŸΡ€ΠΎΠΊΠ°Ρ‚ вСлосипСдов
PROGRAMMING
1,400
[ "*special", "greedy", "implementation" ]
null
null
Как извСстно, Π² Ρ‚Π΅ΠΏΠ»ΡƒΡŽ ΠΏΠΎΠ³ΠΎΠ΄Ρƒ ΠΌΠ½ΠΎΠ³ΠΈΠ΅ ΠΆΠΈΡ‚Π΅Π»ΠΈ ΠΊΡ€ΡƒΠΏΠ½Ρ‹Ρ… Π³ΠΎΡ€ΠΎΠ΄ΠΎΠ² ΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ сСрвисами городского Π²Π΅Π»ΠΎΠΏΡ€ΠΎΠΊΠ°Ρ‚Π°. Π’ΠΎΡ‚ ΠΈ Аркадий сСгодня Π±ΡƒΠ΄Π΅Ρ‚ Π΄ΠΎΠ±ΠΈΡ€Π°Ρ‚ΡŒΡΡ ΠΎΡ‚ ΡˆΠΊΠΎΠ»Ρ‹ Π΄ΠΎ Π΄ΠΎΠΌΠ°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ городскиС вСлосипСды. Π¨ΠΊΠΎΠ»Π° ΠΈ Π΄ΠΎΠΌ находятся Π½Π° ΠΎΠ΄Π½ΠΎΠΉ прямой ΡƒΠ»ΠΈΡ†Π΅, ΠΊΡ€ΠΎΠΌΠ΅ Ρ‚ΠΎΠ³ΠΎ, Π½Π° Ρ‚ΠΎΠΉ ΠΆΠ΅ ΡƒΠ»ΠΈΡ†Π΅ Π΅ΡΡ‚ΡŒ *n* Ρ‚ΠΎΡ‡Π΅ΠΊ, Π³Π΄Π΅ ΠΌΠΎΠΆΠ½ΠΎ Π²Π·ΡΡ‚ΡŒ вСлосипСд Π² ΠΏΡ€ΠΎΠΊΠ°Ρ‚ ΠΈ...
Π’ ΠΏΠ΅Ρ€Π²ΠΎΠΉ строкС ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ Π΄Π²Π° Ρ†Π΅Π»Ρ‹Ρ… числа *n* ΠΈ *k* (2<=≀<=*n*<=≀<=1<=000, 1<=≀<=*k*<=≀<=100<=000) β€” количСство Π²Π΅Π»ΠΎΠΏΡ€ΠΎΠΊΠ°Ρ‚ΠΎΠ² ΠΈ максимальноС расстояниС, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ Аркадий ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΡ€ΠΎΠ΅Ρ…Π°Ρ‚ΡŒ Π½Π° ΠΎΠ΄Π½ΠΎΠΌ вСлосипСдС. Π’ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ строкС слСдуСт ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ Ρ†Π΅Π»Ρ‹Ρ… чисСл *x*1,<=*x*2,<=...,<=*x**n* (0<=≀<=*x*1<=&lt;<=*x*2<=&lt;<=....
Если Аркадий Π½Π΅ смоТСт Π΄ΠΎΠ±Ρ€Π°Ρ‚ΡŒΡΡ ΠΎΡ‚ ΡˆΠΊΠΎΠ»Ρ‹ Π΄ΠΎ Π΄ΠΎΠΌΠ° Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π½Π° вСлосипСдах, Π²Ρ‹Π²Π΅Π΄ΠΈΡ‚Π΅ -1. Π’ ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π½ΠΎΠΌ случаС, Π²Ρ‹Π²Π΅Π΄ΠΈΡ‚Π΅ минимальноС количСство вСлосипСдов, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΡ€ΠΊΠ°Π΄ΠΈΡŽ Π½ΡƒΠΆΠ½ΠΎ Π²Π·ΡΡ‚ΡŒ Π² Ρ‚ΠΎΡ‡ΠΊΠ°Ρ… ΠΏΡ€ΠΎΠΊΠ°Ρ‚Π°.
[ "4 4\n3 6 8 10\n", "2 9\n10 20\n", "12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n" ]
[ "2\n", "-1\n", "6\n" ]
Π’ ΠΏΠ΅Ρ€Π²ΠΎΠΌ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅ Аркадий Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π·ΡΡ‚ΡŒ ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ вСлосипСд Π² ΠΏΠ΅Ρ€Π²ΠΎΠΌ Π²Π΅Π»ΠΎΠΏΡ€ΠΎΠΊΠ°Ρ‚Π΅ ΠΈ Π΄ΠΎΠ΅Ρ…Π°Ρ‚ΡŒ Π½Π° Π½Ρ‘ΠΌ Π΄ΠΎ Π²Ρ‚ΠΎΡ€ΠΎΠ³ΠΎ Π²Π΅Π»ΠΎΠΏΡ€ΠΎΠΊΠ°Ρ‚Π°. Π’ΠΎ Π²Ρ‚ΠΎΡ€ΠΎΠΌ Π²Π΅Π»ΠΎΠΏΡ€ΠΎΠΊΠ°Ρ‚Π΅ ΠΎΠ½ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π·ΡΡ‚ΡŒ Π½ΠΎΠ²Ρ‹ΠΉ вСлосипСд, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ ΠΎΠ½ смоТСт Π΄ΠΎΠ±Ρ€Π°Ρ‚ΡŒΡΡ Π΄ΠΎ Ρ‡Π΅Ρ‚Π²Π΅Ρ€Ρ‚ΠΎΠ³ΠΎ Π²Π΅Π»ΠΎΠΏΡ€ΠΎΠΊΠ°Ρ‚Π°, рядом с ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ ΠΈ находится Π΅Π³ΠΎ Π΄ΠΎΠΌ. ΠŸΠΎΡΡ‚ΠΎΠΌΡƒ ΠΡ€ΠΊΠ°Π΄ΠΈΡŽ Π½ΡƒΠΆΠ½ΠΎ всСго Π΄Π²Π° вСлосипСда, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π΄ΠΎΠ±...
500
[ { "input": "4 4\n3 6 8 10", "output": "2" }, { "input": "2 9\n10 20", "output": "-1" }, { "input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21", "output": "6" }, { "input": "2 1\n11164 11165", "output": "1" }, { "input": "3 7\n45823 45825 45829", "output": "1" },...
1,520,085,149
80,249
Python 3
OK
TESTS
52
62
5,734,400
n, k = [int(_) for _ in input().split()] xs = [int(_) for _ in input().split()] ans = 1 pred_x = xs[0] for i in range(1, n): if xs[i] - xs[i-1] > k: ans = -1 break if xs[i] - pred_x > k: ans += 1 pred_x = xs[i-1] print(ans)
Title: ΠŸΡ€ΠΎΠΊΠ°Ρ‚ вСлосипСдов Time Limit: None seconds Memory Limit: None megabytes Problem Description: Как извСстно, Π² Ρ‚Π΅ΠΏΠ»ΡƒΡŽ ΠΏΠΎΠ³ΠΎΠ΄Ρƒ ΠΌΠ½ΠΎΠ³ΠΈΠ΅ ΠΆΠΈΡ‚Π΅Π»ΠΈ ΠΊΡ€ΡƒΠΏΠ½Ρ‹Ρ… Π³ΠΎΡ€ΠΎΠ΄ΠΎΠ² ΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ сСрвисами городского Π²Π΅Π»ΠΎΠΏΡ€ΠΎΠΊΠ°Ρ‚Π°. Π’ΠΎΡ‚ ΠΈ Аркадий сСгодня Π±ΡƒΠ΄Π΅Ρ‚ Π΄ΠΎΠ±ΠΈΡ€Π°Ρ‚ΡŒΡΡ ΠΎΡ‚ ΡˆΠΊΠΎΠ»Ρ‹ Π΄ΠΎ Π΄ΠΎΠΌΠ°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ городскиС вСлосипСды. Π¨ΠΊΠΎΠ»Π° ΠΈ Π΄ΠΎΠΌ находятся...
```python n, k = [int(_) for _ in input().split()] xs = [int(_) for _ in input().split()] ans = 1 pred_x = xs[0] for i in range(1, n): if xs[i] - xs[i-1] > k: ans = -1 break if xs[i] - pred_x > k: ans += 1 pred_x = xs[i-1] print(ans) ```
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,608,742,406
2,147,483,647
PyPy 3
OK
TESTS
37
140
0
n=int(input()) l=[i for i in range(1,1001)] s='' for i in l: s+=str(i) print(s[n-1])
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1...
```python n=int(input()) l=[i for i in range(1,1001)] s='' for i in l: s+=str(i) print(s[n-1]) ```
3
614
A
Link/Cut Tree
PROGRAMMING
1,500
[ "brute force", "implementation" ]
null
null
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure. Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre...
The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≀<=*l*<=≀<=*r*<=≀<=1018, 2<=≀<=*k*<=≀<=109).
Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes).
[ "1 10 2\n", "2 4 5\n" ]
[ "1 2 4 8 ", "-1" ]
Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed.
500
[ { "input": "1 10 2", "output": "1 2 4 8 " }, { "input": "2 4 5", "output": "-1" }, { "input": "18102 43332383920 28554", "output": "28554 815330916 " }, { "input": "19562 31702689720 17701", "output": "313325401 " }, { "input": "11729 55221128400 313", "output...
1,609,730,525
2,147,483,647
Python 3
OK
TESTS
44
108
0
""" author : soumik created : January 04, 2021 9:16 AM Problem Name : -X- Problem Url : -X- Problem Limit : NULL , NULL Problem Url : -X- @genarated by : ai-virtual-assistant """ l,r,k= map(int,input().split()) power = 1 check =False while power<=r: ...
Title: Link/Cut Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure. Unfortunately, Rostislav is unable to understand ...
```python """ author : soumik created : January 04, 2021 9:16 AM Problem Name : -X- Problem Url : -X- Problem Limit : NULL , NULL Problem Url : -X- @genarated by : ai-virtual-assistant """ l,r,k= map(int,input().split()) power = 1 check =False while ...
3
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}...
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All sub...
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"...
1,565,551,886
2,147,483,647
Python 3
OK
TESTS
133
124
0
word = input() rev_word = word[::-1] size = 0 while(len(word) != 0): if(word != rev_word): size = len(word) break else: word = word[1:] rev_word = rev_word[-1:0:-1] print(size)
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar...
```python word = input() rev_word = word[::-1] size = 0 while(len(word) != 0): if(word != rev_word): size = len(word) break else: word = word[1:] rev_word = rev_word[-1:0:-1] print(size) ```
3
701
A
Cards
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards ...
The first line of the input contains integer *n* (2<=≀<=*n*<=≀<=100)Β β€” the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=100), where *a**i* is equal to the number written on the *i*-th card.
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print...
[ "6\n1 5 7 4 4 3\n", "4\n10 10 10 10\n" ]
[ "1 3\n6 2\n4 5\n", "1 2\n3 4\n" ]
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
500
[ { "input": "6\n1 5 7 4 4 3", "output": "1 3\n6 2\n4 5" }, { "input": "4\n10 10 10 10", "output": "1 4\n2 3" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,635,999,936
2,147,483,647
Python 3
OK
TESTS
35
46
4,505,600
n=int(input()) a=list(map(int,input().split())) s=sum(a) s=s*2 k=s//n ans=[] for i in range(0,n): if (i+1) not in ans: j=a[i] a[i]="op" ans.append(i+1) ll=k-j ind=a.index(ll) ans.append(ind+1) a[ind]="op" i=0 while i<n: print(ans[i],ans[i+1]) i+=2
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p...
```python n=int(input()) a=list(map(int,input().split())) s=sum(a) s=s*2 k=s//n ans=[] for i in range(0,n): if (i+1) not in ans: j=a[i] a[i]="op" ans.append(i+1) ll=k-j ind=a.index(ll) ans.append(ind+1) a[ind]="op" i=0 while i<n: print(ans[i],ans[i+1]) i+=2 ```
3
920
A
Water The Garden
PROGRAMMING
1,000
[ "implementation" ]
null
null
It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *...
The first line contains one integer *t* β€” the number of test cases to solve (1<=≀<=*t*<=≀<=200). Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≀<=*n*<=≀<=200, 1<=≀<=*k*<=≀<=*n*) β€” the number of garden beds and water taps, respectively. Next line contains *k* intege...
For each test case print one integer β€” the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
[ "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n" ]
[ "3\n1\n4\n" ]
The first example consists of 3 tests: 1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is ...
0
[ { "input": "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1", "output": "3\n1\n4" }, { "input": "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4...
1,598,791,712
2,147,483,647
Python 3
OK
TESTS
21
109
7,065,600
def getDistance(NumberOfGarden, NumberOfTap, TapLocation): distance = [] distance.append(TapLocation[0]) distance.append(NumberOfGarden - TapLocation[len(TapLocation) - 1] + 1) for x in range(0, NumberOfTap - 1): distance.append((TapLocation[x + 1] - TapLocation[x]) // 2 + 1) return max(di...
Title: Water The Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the ...
```python def getDistance(NumberOfGarden, NumberOfTap, TapLocation): distance = [] distance.append(TapLocation[0]) distance.append(NumberOfGarden - TapLocation[len(TapLocation) - 1] + 1) for x in range(0, NumberOfTap - 1): distance.append((TapLocation[x + 1] - TapLocation[x]) // 2 + 1) ret...
3
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≀<=*t*<=≀<=100) β€” the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≀<=*n*<=≀<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130...
1,673,339,889
2,147,483,647
PyPy 3-64
OK
TESTS
21
62
1,331,200
import sys input = lambda: sys.stdin.readline().rstrip() # ----------------------- # def main(): n = int(input()) ans = n * (n+1) >> 1 x = 1 while x <= n: x <<= 1 ans -= x return ans print('\n'.join(str(main()) for _ in range(int(input()))))
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be...
```python import sys input = lambda: sys.stdin.readline().rstrip() # ----------------------- # def main(): n = int(input()) ans = n * (n+1) >> 1 x = 1 while x <= n: x <<= 1 ans -= x return ans print('\n'.join(str(main()) for _ in range(int(input())))) ```
3
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do...
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": ...
1,683,349,506
2,147,483,647
Python 3
OK
TESTS
54
92
0
s1=input() s2=input() s3=input() l1=list(s1) l2=list(s2) ls=l1+l2 l3=list(s3) ls.sort() l3.sort() if ls==l3: print('YES') else: print('NO')
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam...
```python s1=input() s2=input() s3=input() l1=list(s1) l2=list(s2) ls=l1+l2 l3=list(s3) ls.sort() l3.sort() if ls==l3: print('YES') else: print('NO') ```
3
708
A
Letters Cyclic Shift
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation", "strings" ]
null
null
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is ...
The only line of the input contains the string *s* (1<=≀<=|*s*|<=≀<=100<=000) consisting of lowercase English letters.
Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring.
[ "codeforces\n", "abacaba\n" ]
[ "bncdenqbdr\n", "aaacaba\n" ]
String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≀ *i* ≀ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i*...
500
[ { "input": "codeforces", "output": "bncdenqbdr" }, { "input": "abacaba", "output": "aaacaba" }, { "input": "babbbabaababbaa", "output": "aabbbabaababbaa" }, { "input": "bcbacaabcababaccccaaaabacbbcbbaa", "output": "abaacaabcababaccccaaaabacbbcbbaa" }, { "input": "...
1,510,335,852
2,147,483,647
Python 3
OK
TESTS
54
140
409,600
s = input() answer = "" started = False for i in range(len(s)): el = s[i] if el == "a" and not started: answer += "a" elif el == "a" and started: print(answer + s[i:]) exit(0) else: started = True answer += chr(ord(el) - 1) if not started: print(...
Title: Letters Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each cha...
```python s = input() answer = "" started = False for i in range(len(s)): el = s[i] if el == "a" and not started: answer += "a" elif el == "a" and started: print(answer + s[i:]) exit(0) else: started = True answer += chr(ord(el) - 1) if not started: ...
3
327
B
Hungry Sequence
PROGRAMMING
1,200
[ "math" ]
null
null
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers. A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if: - Its elements are in i...
The input contains a single integer: *n* (1<=≀<=*n*<=≀<=105).
Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one.
[ "3\n", "5\n" ]
[ "2 9 15\n", "11 14 20 27 31\n" ]
none
500
[ { "input": "3", "output": "2 9 15" }, { "input": "5", "output": "11 14 20 27 31" }, { "input": "1", "output": "3" }, { "input": "1000", "output": "3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 ...
1,678,817,560
2,147,483,647
Python 3
OK
TESTS
27
342
0
n=int(input()) tw=2*n while(n<tw): print(n,end=" ") n+=1
Title: Hungry Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers. A sequence *a*1...
```python n=int(input()) tw=2*n while(n<tw): print(n,end=" ") n+=1 ```
3