contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
listlengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
761
A
Dasha and Stairs
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ...
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
[ "2 3\n", "3 1\n" ]
[ "YES\n", "NO\n" ]
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
500
[ { "input": "2 3", "output": "YES" }, { "input": "3 1", "output": "NO" }, { "input": "5 4", "output": "YES" }, { "input": "9 9", "output": "YES" }, { "input": "85 95", "output": "NO" }, { "input": "0 1", "output": "YES" }, { "input": "89 25"...
1,551,098,664
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
11
139
0
a, b = map(int, input().split()) n = abs(a-b) if n>1: print("NO") else: print("YES")
Title: Dasha and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so...
```python a, b = map(int, input().split()) n = abs(a-b) if n>1: print("NO") else: print("YES") ```
0
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,668,435,672
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
92
7,884,800
n = int(input()) listN = list(map(int, input().split())) odd = 0 minNumber = 9999999999 sumNumber = 0 for i in listN: if i%2 != 0: odd += 1 if i <= minNumber: minNumber = i sumNumber += i if(odd%2 == 0): print(sumNumber) else: print(sumNumber - minNumber)
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()) listN = list(map(int, input().split())) odd = 0 minNumber = 9999999999 sumNumber = 0 for i in listN: if i%2 != 0: odd += 1 if i <= minNumber: minNumber = i sumNumber += i if(odd%2 == 0): print(sumNumber) else: print(sumNumber - minNumber) ```
0
735
C
Tennis Championship
PROGRAMMING
1,600
[ "combinatorics", "constructive algorithms", "greedy", "math" ]
null
null
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are st...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament.
Print the maximum number of games in which the winner of the tournament can take part.
[ "2\n", "3\n", "4\n", "10\n" ]
[ "1\n", "2\n", "2\n", "4\n" ]
In all samples we consider that player number 1 is the winner. In the first sample, there would be only one game so the answer is 1. In the second sample, player 1 can consequently beat players 2 and 3. In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't p...
1,750
[ { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "2" }, { "input": "10", "output": "4" }, { "input": "1000", "output": "14" }, { "input": "2500", "output": "15" }, { "input": "690000", "output"...
1,535,678,098
2,147,483,647
Python 3
OK
TESTS
63
124
0
def main(): n = int(input()) a = b = r = 1 while b <= n: a, b, r = b, a + b, r + 1 print(r - 2) if __name__ == '__main__': main()
Title: Tennis Championship Time Limit: None seconds Memory Limit: None megabytes Problem Description: Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very firs...
```python def main(): n = int(input()) a = b = r = 1 while b <= n: a, b, r = b, a + b, r + 1 print(r - 2) if __name__ == '__main__': main() ```
3
361
A
Levko and Table
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000).
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.
[ "2 4\n", "4 7\n" ]
[ "1 3\n3 1\n", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n" ]
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table...
500
[ { "input": "2 4", "output": "4 0 \n0 4 " }, { "input": "4 7", "output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 " }, { "input": "1 8", "output": "8 " }, { "input": "9 3", "output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0...
1,619,544,415
2,147,483,647
PyPy 3
OK
TESTS
22
109
2,867,200
n, k = list(map(int, input().split())) val = k - n + 1 ar = [val] + [1]* (n - 1) print(*ar) for i in range(1, n): ar[i] = val ar[i - 1] = 1 print(*ar)
Title: Levko and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortun...
```python n, k = list(map(int, input().split())) val = k - n + 1 ar = [val] + [1]* (n - 1) print(*ar) for i in range(1, n): ar[i] = val ar[i - 1] = 1 print(*ar) ```
3
439
B
Devu, the Dumb Guy
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other ...
The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105).
Output a single integer representing the answer to the problem.
[ "2 3\n4 1\n", "4 2\n5 1 2 1\n", "3 3\n1 1 1\n" ]
[ "11\n", "10\n", "6\n" ]
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ...
1,000
[ { "input": "2 3\n4 1", "output": "11" }, { "input": "4 2\n5 1 2 1", "output": "10" }, { "input": "3 3\n1 1 1", "output": "6" }, { "input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "output": "65" }, { "input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3...
1,536,587,252
2,147,483,647
Python 3
OK
TESTS
31
249
7,372,800
n, x = map(int, input().split()) a = list(map(int, input().split())) a.sort() time = 0 for subject in a: time += subject*x x = max(1, x-1) print(time)
Title: Devu, the Dumb Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co...
```python n, x = map(int, input().split()) a = list(map(int, input().split())) a.sort() time = 0 for subject in a: time += subject*x x = max(1, x-1) print(time) ```
3
121
C
Lucky Permutation
PROGRAMMING
1,900
[ "brute force", "combinatorics", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically *k*-th permutation of integers from 1 to *n*. Determine ...
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109) — the number of elements in the permutation and the lexicographical number of the permutation.
If the *k*-th permutation of numbers from 1 to *n* does not exist, print the single number "-1" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes *i*, that *i* and *a**i* are both lucky numbers.
[ "7 4\n", "4 7\n" ]
[ "1\n", "1\n" ]
A permutation is an ordered set of *n* elements, where each integer from 1 to *n* occurs exactly once. The element of permutation in position with index *i* is denoted as *a*<sub class="lower-index">*i*</sub> (1 ≤ *i* ≤ *n*). Permutation *a* is lexicographically smaller that permutation *b* if there is such a *i* (1 ≤ ...
1,500
[ { "input": "7 4", "output": "1" }, { "input": "4 7", "output": "1" }, { "input": "7 1", "output": "2" }, { "input": "7 5040", "output": "1" }, { "input": "10 1023", "output": "0" }, { "input": "7 7477", "output": "-1" }, { "input": "10 1000...
1,691,862,731
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1691862731.6587145")# 1691862731.6587317
Title: Lucky Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not...
```python print("_RANDOM_GUESS_1691862731.6587145")# 1691862731.6587317 ```
0
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and c...
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712",...
1,591,550,410
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
186
0
def cool_num(n): a = n**0.5 a = int(a) for i in range(2,a+1): for j in range(i,a+1): s= i**2 + j**2 + i + j s=int(s/2) if s == n: return True n=int(input()) a=cool_num(n) if a is True: print("YES") else: print("NO")
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent...
```python def cool_num(n): a = n**0.5 a = int(a) for i in range(2,a+1): for j in range(i,a+1): s= i**2 + j**2 + i + j s=int(s/2) if s == n: return True n=int(input()) a=cool_num(n) if a is True: print("YES") else: print("NO") ...
0
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th...
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\...
1,698,401,807
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) res = 0 for i in range(n): tmp = input() if("++" in tmp): res = res+1 if("--" i tmp): res = res-1 print(res)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ incre...
```python n = int(input()) res = 0 for i in range(n): tmp = input() if("++" in tmp): res = res+1 if("--" i tmp): res = res-1 print(res) ```
-1
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ...
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "i...
1,689,224,007
2,147,483,647
PyPy 3-64
OK
TESTS
40
154
1,945,600
def sol(): k=int(input()) l=int(input()) m=int(input()) n=int(input()) d=int(input()) cnt=0 for i in range (1,d+1): if i%k==0 or i%l==0 or i%m==0 or i%n==0: cnt=cnt+1 print(cnt) sol()
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entert...
```python def sol(): k=int(input()) l=int(input()) m=int(input()) n=int(input()) d=int(input()) cnt=0 for i in range (1,d+1): if i%k==0 or i%l==0 or i%m==0 or i%n==0: cnt=cnt+1 print(cnt) sol() ```
3
48
A
Rock-paper-scissors
PROGRAMMING
900
[ "implementation", "schedules" ]
A. Rock-paper-scissors
2
256
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio...
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
[ "rock\nrock\nrock\n", "paper\nrock\nrock\n", "scissors\nrock\nrock\n", "scissors\npaper\nrock\n" ]
[ "?\n", "F\n", "?\n", "?\n" ]
none
0
[ { "input": "rock\nrock\nrock", "output": "?" }, { "input": "paper\nrock\nrock", "output": "F" }, { "input": "scissors\nrock\nrock", "output": "?" }, { "input": "scissors\npaper\nrock", "output": "?" }, { "input": "paper\npaper\nrock", "output": "?" }, { ...
1,666,950,419
2,147,483,647
Python 3
OK
TESTS
27
92
0
f=input() m=input() s=input() if f==m!=s: if f=='paper' and s=='scissors' or f=='scissors' and s=='rock' or f=='rock' and s=='paper': print('S') else: print('?') elif f!=m==s: if m=='paper' and f=='scissors' or m=='scissors' and f=='rock' or m=='rock' and f=='paper': print(...
Title: Rock-paper-scissors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ...
```python f=input() m=input() s=input() if f==m!=s: if f=='paper' and s=='scissors' or f=='scissors' and s=='rock' or f=='rock' and s=='paper': print('S') else: print('?') elif f!=m==s: if m=='paper' and f=='scissors' or m=='scissors' and f=='rock' or m=='rock' and f=='paper': ...
3.977
995
A
Tesla
PROGRAMMING
2,100
[ "constructive algorithms", "implementation" ]
null
null
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be repre...
The first line of the input contains two space-separated integers $n$ and $k$ ($1 \le n \le 50$, $1 \le k \le 2n$), representing the number of columns and the number of cars, respectively. The next four lines will contain $n$ integers each between $0$ and $k$ inclusive, representing the initial state of the parking lo...
If there is a sequence of moves that brings all of the cars to their parking spaces, with at most $20000$ car moves, then print $m$, the number of moves, on the first line. On the following $m$ lines, print the moves (one move per line) in the format $i$ $r$ $c$, which corresponds to Allen moving car $i$ to the neighbo...
[ "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n", "1 2\n1\n2\n1\n2\n", "1 2\n1\n1\n2\n2\n" ]
[ "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n", "-1\n", "2\n1 1 1\n2 4 1\n" ]
In the first sample test case, all cars are in front of their spots except car $5$, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most $20000$ will be accepted. In the second sample test case, there is only one column, and the c...
500
[ { "input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2" }, { "input": "1 2\n1\n2\n1\n2", "output": "-1" }, { "input": "1 2\n1\n1\n2\n2", "output": "2\n1 1 1\n2 4 1" }, { "input": "2 2\n1 0\n0 2\n0 1\n0 2", "output": "7...
1,579,843,322
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
109
307,200
# -*- coding: utf-8 -*- # @Date : 2020-01-24 08:24:04 # @Author : raj lath ([email protected]) # @Link : link # @Version : 1.0.0 import sys sys.setrecursionlimit(10**5+1) inf = int(10 ** 20) max_val = inf min_val = -inf RW = lambda : sys.stdin.readline().strip() RI = lambda : int(RW())...
Title: Tesla Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will...
```python # -*- coding: utf-8 -*- # @Date : 2020-01-24 08:24:04 # @Author : raj lath ([email protected]) # @Link : link # @Version : 1.0.0 import sys sys.setrecursionlimit(10**5+1) inf = int(10 ** 20) max_val = inf min_val = -inf RW = lambda : sys.stdin.readline().strip() RI = lambda :...
-1
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at prog...
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to...
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output...
1,661,965,397
2,147,483,647
PyPy 3-64
OK
TESTS
41
93
5,529,600
n = int(input()) a = input().split() programming_indices = [index for (index, item) in enumerate(a) if item == "1"] maths_indices = [index for (index, item) in enumerate(a) if item == "2"] PE_indices = [index for (index, item) in enumerate(a) if item == "3"] min_len = min(len(programming_indices), len(mat...
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)...
```python n = int(input()) a = input().split() programming_indices = [index for (index, item) in enumerate(a) if item == "1"] maths_indices = [index for (index, item) in enumerate(a) if item == "2"] PE_indices = [index for (index, item) in enumerate(a) if item == "3"] min_len = min(len(programming_indices...
3
724
A
Checking the Calendar
PROGRAMMING
1,000
[ "implementation" ]
null
null
You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t...
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).
[ "monday\ntuesday\n", "sunday\nsunday\n", "saturday\ntuesday\n" ]
[ "NO\n", "YES\n", "YES\n" ]
In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays. In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday.
500
[ { "input": "monday\ntuesday", "output": "NO" }, { "input": "sunday\nsunday", "output": "YES" }, { "input": "saturday\ntuesday", "output": "YES" }, { "input": "tuesday\nthursday", "output": "YES" }, { "input": "friday\nwednesday", "output": "NO" }, { "i...
1,475,929,182
282
Python 3
OK
TESTS
68
77
4,608,000
m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] wd = ['monday', 'tuesday', 'wednesday', "thursday", "friday", "saturday", "sunday"] a, b = [wd.index(input()) for i in range(2)] for i in range(7): cur = i for j in range(11): nxt = (cur + m[j]) % 7 if cur == a and nxt == b: print(...
Title: Checking the Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the fir...
```python m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] wd = ['monday', 'tuesday', 'wednesday', "thursday", "friday", "saturday", "sunday"] a, b = [wd.index(input()) for i in range(2)] for i in range(7): cur = i for j in range(11): nxt = (cur + m[j]) % 7 if cur == a and nxt == b: ...
3
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane ...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th...
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl...
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7...
1,615,616,493
2,147,483,647
PyPy 3
OK
TESTS
33
216
2,252,800
import heapq n, m = map(int, input().split()) a = list(map(int, input().split())) b = a.copy() heapq.heapify(a) min_ans = 0 for i in range(n): x = heapq.heappop(a) if x==1: heapq.heappush(a, 1001) else: heapq.heappush(a, x-1) min_ans+=x #print(min_ans) y = [-i for i in b] ...
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen pl...
```python import heapq n, m = map(int, input().split()) a = list(map(int, input().split())) b = a.copy() heapq.heapify(a) min_ans = 0 for i in range(n): x = heapq.heappop(a) if x==1: heapq.heappush(a, 1001) else: heapq.heappush(a, x-1) min_ans+=x #print(min_ans) y = [-i for...
3
863
F
Almost Permutation
PROGRAMMING
2,200
[ "flows" ]
null
null
Recently Ivan noticed an array *a* while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were *n* elements in the array, and each element was not ...
The first line contains two integer numbers *n* and *q* (1<=≤<=*n*<=≤<=50, 0<=≤<=*q*<=≤<=100). Then *q* lines follow, each representing a fact about the array. *i*-th line contains the numbers *t**i*, *l**i*, *r**i* and *v**i* for *i*-th fact (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*v**i*<=≤<=*n*, ...
If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible *cost* of the array.
[ "3 0\n", "3 1\n1 1 3 2\n", "3 2\n1 1 3 2\n2 1 3 2\n", "3 2\n1 1 3 2\n2 1 3 1\n" ]
[ "3\n", "5\n", "9\n", "-1\n" ]
none
0
[ { "input": "3 0", "output": "3" }, { "input": "3 1\n1 1 3 2", "output": "5" }, { "input": "3 2\n1 1 3 2\n2 1 3 2", "output": "9" }, { "input": "3 2\n1 1 3 2\n2 1 3 1", "output": "-1" }, { "input": "50 0", "output": "50" }, { "input": "50 1\n2 31 38 25"...
1,692,388,454
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1692388454.0953698")# 1692388454.0953863
Title: Almost Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Ivan noticed an array *a* while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reprodu...
```python print("_RANDOM_GUESS_1692388454.0953698")# 1692388454.0953863 ```
0
522
A
Reposts
PROGRAMMING
1,200
[ "*special", "dfs and similar", "dp", "graphs", "trees" ]
null
null
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ...
Print a single integer — the maximum length of a repost chain.
[ "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n", "1\nSoMeStRaNgEgUe repos...
[ "6\n", "2\n", "2\n" ]
none
500
[ { "input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6" }, { "input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc...
1,461,057,220
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
4,608,000
n=int(input()) d={'Polycarp':1} for i in range(n): a,b,c=input().split(' ') #a为转发者,c为被转者 d[a]=d[c]+1 print(max(d.values()))
Title: Reposts Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. ...
```python n=int(input()) d={'Polycarp':1} for i in range(n): a,b,c=input().split(' ') #a为转发者,c为被转者 d[a]=d[c]+1 print(max(d.values())) ```
-1
160
A
Twins
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
In the single line print the single number — the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't e...
500
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" ...
1,692,679,436
2,147,483,647
PyPy 3
OK
TESTS
29
154
0
n = int(input()) a = sorted(list(map(int, input().split())))[::-1] for i in range(1, n): a[i] += a[i-1] ans = 1 s = a[-1] t = a[0] i = 1 while t <= s-t: t = a[i] i += 1 ans += 1 print(ans)
Title: Twins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w...
```python n = int(input()) a = sorted(list(map(int, input().split())))[::-1] for i in range(1, n): a[i] += a[i-1] ans = 1 s = a[-1] t = a[0] i = 1 while t <= s-t: t = a[i] i += 1 ans += 1 print(ans) ```
3
56
E
Domino Principle
PROGRAMMING
2,200
[ "binary search", "data structures", "sortings" ]
E. Domino Principle
2
256
Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put *n* dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. The *i*-th domino ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) which is the number of dominoes. Then follow *n* lines containing two integers *x**i* and *h**i* (<=-<=108<=≤<=*x**i*<=≤<=108,<=2<=≤<=*h**i*<=≤<=108) each, which are the coordinate and height of every domino. No two dominoes stand on one point.
Print *n* space-separated numbers *z**i* — the number of dominoes that will fall if Vasya pushes the *i*-th domino to the right (including the domino itself).
[ "4\n16 5\n20 5\n10 10\n18 2\n", "4\n0 10\n1 5\n9 10\n15 10\n" ]
[ "3 1 4 1 ", "4 1 2 1 " ]
none
2,500
[ { "input": "4\n16 5\n20 5\n10 10\n18 2", "output": "3 1 4 1 " }, { "input": "4\n0 10\n1 5\n9 10\n15 10", "output": "4 1 2 1 " }, { "input": "3\n6 7\n2 9\n-6 10", "output": "1 2 3 " }, { "input": "4\n-6 9\n9 5\n-7 4\n0 9", "output": "2 1 3 1 " }, { "input": "5\n-47...
1,674,628,401
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
13
2,000
21,606,400
n=int(input()) arr=[0 for i in range(n)] for i in range(n): x,h=map(int,input().split()) arr[i]=[x,h,i] arr.sort(key=lambda x:x[0]) ans=[0 for i in range(n)] dp=[i for i in range(n)] for i in range(n-1,-1,-1): mnr=arr[i][0] mxr=arr[i][0]+arr[i][1]-1 for j in range(i+1,n): ...
Title: Domino Principle Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put *n* dominoes on the table along one axis, going from left to right. Every domino stands per...
```python n=int(input()) arr=[0 for i in range(n)] for i in range(n): x,h=map(int,input().split()) arr[i]=[x,h,i] arr.sort(key=lambda x:x[0]) ans=[0 for i in range(n)] dp=[i for i in range(n)] for i in range(n-1,-1,-1): mnr=arr[i][0] mxr=arr[i][0]+arr[i][1]-1 for j in range(i+1,...
0
476
A
Dreamoon and Stairs
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10).
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
[ "10 2\n", "3 5\n" ]
[ "6\n", "-1\n" ]
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
500
[ { "input": "10 2", "output": "6" }, { "input": "3 5", "output": "-1" }, { "input": "29 7", "output": "21" }, { "input": "2 2", "output": "2" }, { "input": "1 2", "output": "-1" }, { "input": "10000 2", "output": "5000" }, { "input": "10000 ...
1,650,975,117
2,147,483,647
Python 3
OK
TESTS
35
46
0
import sys input = sys.stdin.readline n, m = map(int, input().split()) if n < m: print(-1) else: if n % 2 == 0: print((n//2//m + ((n//2)%m>0))*m) else: print(((n//2+1)// m + ((n//2+1) % m > 0)) * m)
Title: Dreamoon and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb ...
```python import sys input = sys.stdin.readline n, m = map(int, input().split()) if n < m: print(-1) else: if n % 2 == 0: print((n//2//m + ((n//2)%m>0))*m) else: print(((n//2+1)// m + ((n//2+1) % m > 0)) * m) ```
3
979
A
Pizza, Pizza, Pizza!!!
PROGRAMMING
1,000
[ "math" ]
null
null
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele...
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
A single integer — the number of straight cuts Shiro needs.
[ "3\n", "4\n" ]
[ "2", "5" ]
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
500
[ { "input": "3", "output": "2" }, { "input": "4", "output": "5" }, { "input": "10", "output": "11" }, { "input": "10000000000", "output": "10000000001" }, { "input": "1234567891", "output": "617283946" }, { "input": "7509213957", "output": "37546069...
1,683,539,233
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
# LUOGU_RID: 109862222 a=int(input()) a=a+1 if b==1: print(0) elif b%2!=0: print(b//2) elif b%2==0: print(b)
Title: Pizza, Pizza, Pizza!!! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthd...
```python # LUOGU_RID: 109862222 a=int(input()) a=a+1 if b==1: print(0) elif b%2!=0: print(b//2) elif b%2==0: print(b) ```
-1
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b...
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "inpu...
1,577,725,184
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
a,b,n=map(int,input().split()) tbool = True while n>0: c=a%n a=n n=c while n>0: c=b%n b=c c=n q=a w=b while n>0: n-=q if(tbool): tbool = False else: tbool = True n-=w if tbool==True: print(1) else: print(0)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto...
```python a,b,n=map(int,input().split()) tbool = True while n>0: c=a%n a=n n=c while n>0: c=b%n b=c c=n q=a w=b while n>0: n-=q if(tbool): tbool = False else: tbool = True n-=w if tbool==True: print(1) else: print(0) ```
0
559
B
Equivalent Strings
PROGRAMMING
1,700
[ "divide and conquer", "hashing", "sortings", "strings" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ...
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equival...
1,000
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { ...
1,519,736,161
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
22
343
29,491,200
str1 = input() str2 = input() def equality(str1, str2): if str1 == str2: return True elif len(str1) == 1: return False else: l = len(str1) a = equality(str1[:l//2], str2[0:l//2]) and equality(str1[l//2:], str2[l//2:]) b = equality(str1[:l//2], str2[l//2:]) a...
Title: Equivalent Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split str...
```python str1 = input() str2 = input() def equality(str1, str2): if str1 == str2: return True elif len(str1) == 1: return False else: l = len(str1) a = equality(str1[:l//2], str2[0:l//2]) and equality(str1[l//2:], str2[l//2:]) b = equality(str1[:l//2], str2...
0
855
B
Marvolo Gaunt's Ring
PROGRAMMING
1,500
[ "brute force", "data structures", "dp" ]
null
null
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he...
First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*.
[ "5 1 2 3\n1 2 3 4 5\n", "5 1 2 -3\n-1 -2 -3 -4 -5\n" ]
[ "30\n", "12\n" ]
In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
1,000
[ { "input": "5 1 2 3\n1 2 3 4 5", "output": "30" }, { "input": "5 1 2 -3\n-1 -2 -3 -4 -5", "output": "12" }, { "input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "output": "376059240645059046" }, { "input": "4 -96405765 -495906217 6...
1,683,206,659
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
#a quick function that will separate values into a list of lists def quickseparator(i,j,k): a = [i,j,k] pos = [] neg = [] for n in a: if n > 0: pos.append(n) else: neg.append(n) b = [pos,neg] return(b) if __name__ == "__main__": n,i,j,k = map(int, input().split()) inlist = list(map(int,input().split(...
Title: Marvolo Gaunt's Ring Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed i...
```python #a quick function that will separate values into a list of lists def quickseparator(i,j,k): a = [i,j,k] pos = [] neg = [] for n in a: if n > 0: pos.append(n) else: neg.append(n) b = [pos,neg] return(b) if __name__ == "__main__": n,i,j,k = map(int, input().split()) inlist = list(map(int,inpu...
0
325
A
Square and Rectangles
PROGRAMMING
1,500
[ "implementation" ]
null
null
You are given *n* rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the *Ox* and *Oy* axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the ...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=5). Next *n* lines contain four integers each, describing a single rectangle: *x*1, *y*1, *x*2, *y*2 (0<=≤<=*x*1<=&lt;<=*x*2<=≤<=31400,<=0<=≤<=*y*1<=&lt;<=*y*2<=≤<=31400) — *x*1 and *x*2 are *x*-coordinates of the left and right edges of the rectangle, and *y*...
In a single line print "YES", if the given rectangles form a square, or "NO" otherwise.
[ "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3", "output": "YES" }, { "input": "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5", "output": "NO" }, { "input": "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400", "output": "NO...
1,441,125,661
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
122
0
n = int(input()) xmin = 0 xmas = 0 ymin = 0 ymas = 0 s = 0 for i in range(n): x1, y1, x2, y2 = map(int, input().split()) s += abs(x2 - x1) * abs(y2 - y1) xmin = min(xmin, x1, x2) xmas = max(xmas, x1, x2) ymin = min(ymin, y1, y2) ymas = max(ymas, y1, y2) if (xmas - xmin) == (ymas - y...
Title: Square and Rectangles Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the *Ox* and *Oy* axes. The rectangles may touch each other, but they do not overlap (that is, there...
```python n = int(input()) xmin = 0 xmas = 0 ymin = 0 ymas = 0 s = 0 for i in range(n): x1, y1, x2, y2 = map(int, input().split()) s += abs(x2 - x1) * abs(y2 - y1) xmin = min(xmin, x1, x2) xmas = max(xmas, x1, x2) ymin = min(ymin, y1, y2) ymas = max(ymas, y1, y2) if (xmas - xmin) ==...
0
143
B
Help Kingdom of Far Far Away 2
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operatio...
The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is: - The number's notation only contains characters from the set {"0" – "9...
Print the number given in the input in the financial format by the rules described in the problem statement.
[ "2012\n", "0.000\n", "-0.00987654321\n", "-12345678.9\n" ]
[ "$2,012.00", "$0.00", "($0.00)", "($12,345,678.90)" ]
Pay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the financi...
1,000
[ { "input": "2012", "output": "$2,012.00" }, { "input": "0.000", "output": "$0.00" }, { "input": "-0.00987654321", "output": "($0.00)" }, { "input": "-12345678.9", "output": "($12,345,678.90)" }, { "input": "0.99999999999999999999", "output": "$0.99" }, { ...
1,646,676,541
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
512,000
R=lambda:map(float,input().split()) d={} n,=R() if(n<0): n+=.00 d="{:.2f}".format(abs(n)) m=str(d) i=m.index('.') r=i%3 v=i//3 s='$' if(v>1): s+=m[:r]+',' x=r+3 for k in range(v-1): s+=m[r:x]+',' r=x ...
Title: Help Kingdom of Far Far Away 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more e...
```python R=lambda:map(float,input().split()) d={} n,=R() if(n<0): n+=.00 d="{:.2f}".format(abs(n)) m=str(d) i=m.index('.') r=i%3 v=i//3 s='$' if(v>1): s+=m[:r]+',' x=r+3 for k in range(v-1): s+=m[r:x]+',' r=x ...
0
789
A
Anastasia and pebbles
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
[ "3 2\n2 3 4\n", "5 4\n3 1 8 9 7\n" ]
[ "3\n", "5\n" ]
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she...
500
[ { "input": "3 2\n2 3 4", "output": "3" }, { "input": "5 4\n3 1 8 9 7", "output": "5" }, { "input": "1 22\n1", "output": "1" }, { "input": "3 57\n78 165 54", "output": "3" }, { "input": "5 72\n74 10 146 189 184", "output": "6" }, { "input": "9 13\n132 8...
1,691,560,353
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
31
0
# بسم الله (not accepted) n,k = map(int,input().split(' ')) pebbles_list = input().split(' ') pebbles_list = [int(item) for item in pebbles_list] output = 0 while sum(pebbles_list) > 0 : pebbles_list = sorted(pebbles_list,reverse=True) if pebbles_list[0] > 0 : pebbles_list[0] -= k...
Title: Anastasia and pebbles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ...
```python # بسم الله (not accepted) n,k = map(int,input().split(' ')) pebbles_list = input().split(' ') pebbles_list = [int(item) for item in pebbles_list] output = 0 while sum(pebbles_list) > 0 : pebbles_list = sorted(pebbles_list,reverse=True) if pebbles_list[0] > 0 : pebbles_li...
-1
232
A
Cycles
PROGRAMMING
1,600
[ "binary search", "constructive algorithms", "graphs", "greedy" ]
null
null
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly *k* cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices *a*, *b* and *c*, such that each pair of them is connected by a graph edge. John has...
A single line contains an integer *k* (1<=≤<=*k*<=≤<=105) — the number of cycles of length 3 in the required graph.
In the first line print integer *n* (3<=≤<=*n*<=≤<=100) — the number of vertices in the found graph. In each of next *n* lines print *n* characters "0" and "1": the *i*-th character of the *j*-th line should equal "0", if vertices *i* and *j* do not have an edge between them, otherwise it should equal "1". Note that as...
[ "1\n", "10\n" ]
[ "3\n011\n101\n110\n", "5\n01111\n10111\n11011\n11101\n11110\n" ]
none
500
[ { "input": "1", "output": "3\n011\n101\n110" }, { "input": "10", "output": "5\n01111\n10111\n11011\n11101\n11110" }, { "input": "2", "output": "4\n0111\n1011\n1100\n1100" }, { "input": "3", "output": "5\n01001\n10111\n01001\n01001\n11110" }, { "input": "4", "o...
1,603,109,792
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
186
0
k,n,w=map(int,input().split()) a=(k+k*w)/2*w if a-n<=0: print(0) else: print(int(a-n))
Title: Cycles Time Limit: None seconds Memory Limit: None megabytes Problem Description: John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly *k* cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph ver...
```python k,n,w=map(int,input().split()) a=(k+k*w)/2*w if a-n<=0: print(0) else: print(int(a-n)) ```
-1
626
A
Robot Sequence
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s...
The first line of the input contains a single positive integer, *n* (1<=≤<=*n*<=≤<=200) — the number of commands. The next line contains *n* characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code.
Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square.
[ "6\nURLLDR\n", "4\nDLUU\n", "7\nRLRLRLR\n" ]
[ "2\n", "0\n", "12\n" ]
In the first case, the entire source code works, as well as the "RL" substring in the second and third characters. Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.
500
[ { "input": "6\nURLLDR", "output": "2" }, { "input": "4\nDLUU", "output": "0" }, { "input": "7\nRLRLRLR", "output": "12" }, { "input": "1\nR", "output": "0" }, { "input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL...
1,559,859,404
2,147,483,647
Python 3
OK
TESTS
25
124
0
n = int(input()) code = input() c = 0 for i in range(n-1): u = d = r = l = 0 if code[i] == 'U': u += 1 elif code[i] == 'D': d += 1 elif code[i] == 'R': r += 1 else: l += 1 for j in range(i+1, n): if code[j] == 'U': u += 1 elif code[j]...
Title: Robot Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively...
```python n = int(input()) code = input() c = 0 for i in range(n-1): u = d = r = l = 0 if code[i] == 'U': u += 1 elif code[i] == 'D': d += 1 elif code[i] == 'R': r += 1 else: l += 1 for j in range(i+1, n): if code[j] == 'U': u += 1 el...
3
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th...
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar...
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", ...
1,687,284,467
2,147,483,647
Python 3
OK
TESTS
52
46
0
l=list(map(int,input().split())) n=0 total=0 for i in range(1,l[0]+1): total=total+5*i if total+l[1]<=240: n=n+1 print(n)
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem...
```python l=list(map(int,input().split())) n=0 total=0 for i in range(1,l[0]+1): total=total+5*i if total+l[1]<=240: n=n+1 print(n) ```
3
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning ...
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he'...
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input":...
1,679,342,634
2,147,483,647
PyPy 3-64
OK
TESTS
30
62
0
a, b = map(int, input().split()) min_num = min(a, b) print(min_num, (max(a, b) - min_num) // 2)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red...
```python a, b = map(int, input().split()) min_num = min(a, b) print(min_num, (max(a, b) - min_num) // 2) ```
3
982
A
Row
PROGRAMMING
1,200
[ "brute force", "constructive algorithms" ]
null
null
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($0$ means t...
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs. The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
[ "3\n101\n", "4\n1011\n", "5\n10001\n" ]
[ "Yes\n", "No\n", "No\n" ]
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
500
[ { "input": "3\n101", "output": "Yes" }, { "input": "4\n1011", "output": "No" }, { "input": "5\n10001", "output": "No" }, { "input": "1\n0", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "100\n010100101010100101001001010100101010010...
1,606,717,065
2,147,483,647
Python 3
OK
TESTS
55
109
0
val=input() s=input() s='0'+s+'0' if '11' in s or '000' in s: print('NO') else: print('YES')
Title: Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th...
```python val=input() s=input() s='0'+s+'0' if '11' in s or '000' in s: print('NO') else: print('YES') ```
3
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which int...
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" ...
1,696,193,253
2,147,483,647
PyPy 3-64
OK
TESTS
64
62
0
n = int(input()) if n % 10 >= 6: n += 9 print(n // 10 * 10)
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5...
```python n = int(input()) if n % 10 >= 6: n += 9 print(n // 10 * 10) ```
3
507
A
Amr and Music
PROGRAMMING
1,000
[ "greedy", "implementation", "sortings" ]
null
null
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for ...
The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument.
In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use al...
[ "4 10\n4 3 1 2\n", "5 6\n4 3 1 1 2\n", "1 3\n4\n" ]
[ "4\n1 2 3 4", "3\n1 3 4", "0\n" ]
In the first test Amr can learn all 4 instruments. In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}. In the third test Amr doesn't have enough time to learn the only presented instrument.
500
[ { "input": "4 10\n4 3 1 2", "output": "4\n1 2 3 4" }, { "input": "5 6\n4 3 1 1 2", "output": "3\n3 4 5" }, { "input": "1 3\n4", "output": "0" }, { "input": "2 100\n100 100", "output": "1\n1" }, { "input": "3 150\n50 50 50", "output": "3\n1 2 3" }, { "i...
1,644,838,092
2,147,483,647
PyPy 3-64
OK
TESTS
39
78
0
def main(): n, k = list(map(int, input().split())) arr = list(map(int, input().split())) for index, value in enumerate(arr): arr[index] = (index, value) arr.sort(key=lambda x: x[1]) learn_arr = [] s = 0 for element in arr: s += element[1] if s > k: ...
Title: Amr and Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr ...
```python def main(): n, k = list(map(int, input().split())) arr = list(map(int, input().split())) for index, value in enumerate(arr): arr[index] = (index, value) arr.sort(key=lambda x: x[1]) learn_arr = [] s = 0 for element in arr: s += element[1] if s > ...
3
172
A
Phone Code
PROGRAMMING
800
[ "*special", "brute force", "implementation" ]
null
null
Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the...
The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=3·104) — the number of Polycarpus's friends. The following *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, ...
Print the number of digits in the city phone code.
[ "4\n00209\n00219\n00999\n00909\n", "2\n1\n2\n", "3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n" ]
[ "2\n", "0\n", "12\n" ]
A prefix of string *t* is a string that is obtained by deleting zero or more digits from the end of string *t*. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209". In the first sample the city phone code is string "00". In the second sample the city phone code is an em...
1,000
[ { "input": "4\n00209\n00219\n00999\n00909", "output": "2" }, { "input": "2\n1\n2", "output": "0" }, { "input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "output": "12" }, { "input": "5\n4491183345\n4491184811\n4491162340\n4491233399\n4491449214", ...
1,689,328,894
2,147,483,647
Python 3
OK
TESTS
28
248
2,969,600
t=int(input()) l=[] for _ in range(t): s=input() l.append(s) m=l[0] c=0 for k in range(len(m)): flag=1 for i in range(1,len(l)): if l[i][k]!=m[k]: flag=0 break if flag==1: c+=1 else: break print(c)
Title: Phone Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length. Once Polycarpus...
```python t=int(input()) l=[] for _ in range(t): s=input() l.append(s) m=l[0] c=0 for k in range(len(m)): flag=1 for i in range(1,len(l)): if l[i][k]!=m[k]: flag=0 break if flag==1: c+=1 else: break print(c) ```
3
753
A
Santa Claus and Candies
PROGRAMMING
1,000
[ "dp", "greedy", "math" ]
null
null
Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has.
The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has.
Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them.
[ "5\n", "9\n", "2\n" ]
[ "2\n2 3\n", "3\n3 5 1\n", "1\n2 \n" ]
none
500
[ { "input": "5", "output": "2\n1 4 " }, { "input": "9", "output": "3\n1 2 6 " }, { "input": "2", "output": "1\n2 " }, { "input": "1", "output": "1\n1 " }, { "input": "3", "output": "2\n1 2 " }, { "input": "1000", "output": "44\n1 2 3 4 5 6 7 8 9 10 ...
1,483,208,297
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
4,608,000
num = int(input()) i = 1 ans = [] while i <= num: ans.append(i) num-=i i+=1 print(len(ans)) for i in ans: print(i,end = ' ')
Title: Santa Claus and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n...
```python num = int(input()) i = 1 ans = [] while i <= num: ans.append(i) num-=i i+=1 print(len(ans)) for i in ans: print(i,end = ' ') ```
0
20
A
BerOS file system
PROGRAMMING
1,700
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ...
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
500
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "...
1,581,583,320
2,147,483,647
Python 3
OK
TESTS
19
218
0
flag = False for i in filter(None, input().split('/')): flag = True print('/' + i, end = '') if not flag: print('/') else: print()
Title: BerOS file system Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n...
```python flag = False for i in filter(None, input().split('/')): flag = True print('/' + i, end = '') if not flag: print('/') else: print() ```
3.9455
602
A
Two Bases
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations. You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers.
The first line of the input contains two space-separated integers *n* and *b**x* (1<=≤<=*n*<=≤<=10, 2<=≤<=*b**x*<=≤<=40), where *n* is the number of digits in the *b**x*-based representation of *X*. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=&lt;<=*b**x*) — the dig...
Output a single character (quotes for clarity): - '&lt;' if *X*<=&lt;<=*Y* - '&gt;' if *X*<=&gt;<=*Y* - '=' if *X*<==<=*Y*
[ "6 2\n1 0 1 1 1 1\n2 10\n4 7\n", "3 3\n1 0 2\n2 5\n2 4\n", "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n" ]
[ "=\n", "&lt;\n", "&gt;\n" ]
In the first sample, *X* = 101111<sub class="lower-index">2</sub> = 47<sub class="lower-index">10</sub> = *Y*. In the second sample, *X* = 102<sub class="lower-index">3</sub> = 21<sub class="lower-index">5</sub> and *Y* = 24<sub class="lower-index">5</sub> = 112<sub class="lower-index">3</sub>, thus *X* &lt; *Y*. In ...
500
[ { "input": "6 2\n1 0 1 1 1 1\n2 10\n4 7", "output": "=" }, { "input": "3 3\n1 0 2\n2 5\n2 4", "output": "<" }, { "input": "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0", "output": ">" }, { "input": "2 2\n1 0\n2 3\n1 0", "output": "<" }, { "input": "2 2\n1 0\n1 3\n1"...
1,645,111,983
2,147,483,647
Python 3
OK
TESTS
118
46
0
nx, bx = map(int, input().split(' ')[:2]) xs = list(map(int, input().split(' ')[:nx])) ny, by = map(int, input().split(' ')[:2]) ys = list(map(int, input().split(' ')[:ny])) p = 1 x = 0 for d in reversed(xs): x += d * p p *= bx p = 1 y = 0 for d in reversed(ys): y += d * p p *= by if...
Title: Two Bases Time Limit: None seconds Memory Limit: None megabytes Problem Description: After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations. You're given a number *X* represented in base *b**x* ...
```python nx, bx = map(int, input().split(' ')[:2]) xs = list(map(int, input().split(' ')[:nx])) ny, by = map(int, input().split(' ')[:2]) ys = list(map(int, input().split(' ')[:ny])) p = 1 x = 0 for d in reversed(xs): x += d * p p *= bx p = 1 y = 0 for d in reversed(ys): y += d * p p *...
3
888
D
Almost Identity Permutations
PROGRAMMING
1,600
[ "combinatorics", "dp", "math" ]
null
null
A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*. Your task is to count the number of almost identity ...
The first line contains two integers *n* and *k* (4<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=4).
Print the number of almost identity permutations for given *n* and *k*.
[ "4 1\n", "4 2\n", "5 3\n", "5 4\n" ]
[ "1\n", "7\n", "31\n", "76\n" ]
none
0
[ { "input": "4 1", "output": "1" }, { "input": "4 2", "output": "7" }, { "input": "5 3", "output": "31" }, { "input": "5 4", "output": "76" }, { "input": "200 1", "output": "1" }, { "input": "200 2", "output": "19901" }, { "input": "200 3", ...
1,621,026,357
2,147,483,647
PyPy 3
OK
TESTS
25
93
2,355,200
n,k=map(int,input().split()) dp=[[[0]*(k+1) for i in range(n+1)] for j in range(k+1)] dp_c=[[[0]*(k+1) for i in range(n+1)] for j in range(k+1)] for i in range(1,n): dp[1][i][1]=1 store=[0,1,1,2,9] ans=0 for i in range(2,k+1): add=0 for j in range(1,n+1): add += dp[i - 1][j - 1][i - 1] ...
Title: Almost Identity Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*...
```python n,k=map(int,input().split()) dp=[[[0]*(k+1) for i in range(n+1)] for j in range(k+1)] dp_c=[[[0]*(k+1) for i in range(n+1)] for j in range(k+1)] for i in range(1,n): dp[1][i][1]=1 store=[0,1,1,2,9] ans=0 for i in range(2,k+1): add=0 for j in range(1,n+1): add += dp[i - 1][j - 1][...
3
48
D
Permutations
PROGRAMMING
1,500
[ "greedy" ]
D. Permutations
1
256
A permutation is a sequence of integers from 1 to *n* of length *n* containing each number exactly once. For example, (1), (4,<=3,<=5,<=1,<=2), (3,<=2,<=1) are permutations, and (1,<=1), (4,<=3,<=1), (2,<=3,<=4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine tha...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The next line contains the mixed array of *n* integers, divided with a single space. The numbers in the array are from 1 to 105.
If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain *n* numbers, corresponding to the elements of the given array. If the *i*-th element belongs to the first permuta...
[ "9\n1 2 3 1 2 1 4 2 5\n", "4\n4 3 2 1\n", "4\n1 2 2 3\n" ]
[ "3\n3 1 2 1 2 2 2 3 2\n", "1\n1 1 1 1 ", "-1\n" ]
In the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth el...
0
[ { "input": "9\n1 2 3 1 2 1 4 2 5", "output": "3\n1 1 1 2 2 3 1 3 1 " }, { "input": "4\n4 3 2 1", "output": "1\n1 1 1 1 " }, { "input": "4\n1 2 2 3", "output": "-1" }, { "input": "1\n1", "output": "1\n1 " }, { "input": "1\n2", "output": "-1" }, { "input...
1,575,815,919
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
n=int(input()) p=[int(x) for x in input().split()] if p.count(1)==n: for i in range (1,n+1): print(i,end=' ') else: m=max(p) if m==2: if p.count(1)>=p.count(2): q=1 w=1 for i in p: if i==1: print(q,end=' ') ...
Title: Permutations Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A permutation is a sequence of integers from 1 to *n* of length *n* containing each number exactly once. For example, (1), (4,<=3,<=5,<=1,<=2), (3,<=2,<=1) are permutations, and (1,<=1), (4,<=3,<=1), (2,<=3,<=4) are not. The...
```python n=int(input()) p=[int(x) for x in input().split()] if p.count(1)==n: for i in range (1,n+1): print(i,end=' ') else: m=max(p) if m==2: if p.count(1)>=p.count(2): q=1 w=1 for i in p: if i==1: print(q...
0
923
B
Producing Snow
PROGRAMMING
1,600
[ "binary search", "data structures" ]
null
null
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden. Each day, every ...
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days. The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*. The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*...
Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*.
[ "3\n10 10 5\n5 7 2\n", "5\n30 25 20 15 10\n9 10 12 4 13\n" ]
[ "5 12 4\n", "9 20 35 11 25\n" ]
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has on...
1,000
[ { "input": "3\n10 10 5\n5 7 2", "output": "5 12 4" }, { "input": "5\n30 25 20 15 10\n9 10 12 4 13", "output": "9 20 35 11 25" }, { "input": "4\n0 0 0 0\n1 2 3 4", "output": "0 0 0 0" }, { "input": "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2", "output": "10 0 9...
1,520,703,129
7,029
PyPy 3
OK
TESTS
103
686
37,068,800
n = int(input()) vs = [int(x) for x in input().split()] ts = [int(x) for x in input().split()] sumt = 0 for i, t in enumerate(ts): vs[i]+=sumt sumt+=t vs.sort() tl, tr = 0, 0 il, ir = 0, 0 for ind, t in enumerate(ts): #check tl = tr tr += t while ir < n and vs[ir] <= tr: ir += 1 ...
Title: Producing Snow Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day....
```python n = int(input()) vs = [int(x) for x in input().split()] ts = [int(x) for x in input().split()] sumt = 0 for i, t in enumerate(ts): vs[i]+=sumt sumt+=t vs.sort() tl, tr = 0, 0 il, ir = 0, 0 for ind, t in enumerate(ts): #check tl = tr tr += t while ir < n and vs[ir] <= tr:...
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,693,928,425
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
12
62
716,800
str1,str2=input(),input() str1=str1[::-1] str2=str2[::-1] sum=0 for i in range(len(str1)): if str1[i]==str2[i]: sum+=1 else: break ans=len(str1)+len(str2)-sum*2 print(ans) # Tue Sep 05 2023 18:40:24 GMT+0300 (Moscow Standard Time)
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 str1,str2=input(),input() str1=str1[::-1] str2=str2[::-1] sum=0 for i in range(len(str1)): if str1[i]==str2[i]: sum+=1 else: break ans=len(str1)+len(str2)-sum*2 print(ans) # Tue Sep 05 2023 18:40:24 GMT+0300 (Moscow Standard Time) ```
-1
725
B
Food on the Plane
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats...
The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.
Print one integer — the number of seconds Vasya has to wait until he gets his lunch.
[ "1f\n", "2d\n", "4a\n", "5e\n" ]
[ "1\n", "10\n", "11\n", "18\n" ]
In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisl...
1,000
[ { "input": "1f", "output": "1" }, { "input": "2d", "output": "10" }, { "input": "4a", "output": "11" }, { "input": "5e", "output": "18" }, { "input": "2c", "output": "13" }, { "input": "1b", "output": "5" }, { "input": "1000000000000000000d...
1,477,154,716
6,016
Python 3
WRONG_ANSWER
TESTS
86
77
0
import math s=input() a=s[-1] a=str(a) ip="fedabc" b=int(s[:-1]) c=math.ceil(b/4) res=((c-1)*((2*6)+4))+(ip.index(a)+1) if b%2==0: res=res+7 print(res)
Title: Food on the Plane Time Limit: None seconds Memory Limit: None megabytes Problem Description: A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' ...
```python import math s=input() a=s[-1] a=str(a) ip="fedabc" b=int(s[:-1]) c=math.ceil(b/4) res=((c-1)*((2*6)+4))+(ip.index(a)+1) if b%2==0: res=res+7 print(res) ```
0
999
B
Reversing Encryption
PROGRAMMING
900
[ "implementation" ]
null
null
A string $s$ of length $n$ can be encrypted by the following algorithm: - iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$). For example, the above algor...
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
Print a string $s$ such that the above algorithm results in $t$.
[ "10\nrocesfedoc\n", "16\nplmaetwoxesisiht\n", "1\nz\n" ]
[ "codeforces\n", "thisisexampletwo\n", "z\n" ]
The first example is described in the problem statement.
0
[ { "input": "10\nrocesfedoc", "output": "codeforces" }, { "input": "16\nplmaetwoxesisiht", "output": "thisisexampletwo" }, { "input": "1\nz", "output": "z" }, { "input": "2\nir", "output": "ri" }, { "input": "3\nilj", "output": "jli" }, { "input": "4\nj...
1,689,179,078
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
17
46
0
n = int(input()) s = input()[:n] for i in range(1,n+1): if n%i == 0: temp = s[0:i] temp = temp[::-1] s= s.replace(s[0:i],temp) print(s)
Title: Reversing Encryption Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string $s$ of length $n$ can be encrypted by the following algorithm: - iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$...
```python n = int(input()) s = input()[:n] for i in range(1,n+1): if n%i == 0: temp = s[0:i] temp = temp[::-1] s= s.replace(s[0:i],temp) print(s) ```
0
394
A
Counting Sticks
PROGRAMMING
0
[ "brute force", "implementation" ]
null
null
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add...
The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100.
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print...
[ "||+|=|||||\n", "|||||+||=||\n", "|+|=||||||\n", "||||+||=||||||\n" ]
[ "|||+|=||||\n", "Impossible\n", "Impossible\n", "||||+||=||||||\n" ]
In the first sample we can shift stick from the third group of sticks to the first one. In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign. There is no answer in the third sample because we cannot remove sticks from the expression. In the forth s...
500
[ { "input": "||+|=|||||", "output": "|||+|=||||" }, { "input": "|||||+||=||", "output": "Impossible" }, { "input": "|+|=||||||", "output": "Impossible" }, { "input": "||||+||=||||||", "output": "||||+||=||||||" }, { "input": "||||||||||||+|||||||||||=||||||||||||||...
1,679,564,227
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
sticks = input() # Check if shifting a stick in A can make the expression correct for i in range(len(sticks)): if sticks[i] == '|': new_sticks = sticks[:i] + sticks[i+1:] A, B, C = map(int, new_sticks.split('+')[0].split('=')) if A + B == C: print(new_sticks) ...
Title: Counting Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our te...
```python sticks = input() # Check if shifting a stick in A can make the expression correct for i in range(len(sticks)): if sticks[i] == '|': new_sticks = sticks[:i] + sticks[i+1:] A, B, C = map(int, new_sticks.split('+')[0].split('=')) if A + B == C: print(new_sticks) ...
-1
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,480,517,478
2,147,483,647
Python 3
OK
TESTS
32
154
0
n = int(input()) num = list(map(int, input().split())) even_count = 0 for i in range(3): if(num[i] % 2 == 0): even_count += 1 if(even_count >= 2): for i in range(n): if(num[i] % 2 == 1): print(i + 1) else: for i in range(n): if(num[i] % 2 == 0): p...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n = int(input()) num = list(map(int, input().split())) even_count = 0 for i in range(3): if(num[i] % 2 == 0): even_count += 1 if(even_count >= 2): for i in range(n): if(num[i] % 2 == 1): print(i + 1) else: for i in range(n): if(num[i] % 2 == 0): ...
3.9615
365
A
Good Number
PROGRAMMING
1,100
[ "implementation" ]
null
null
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the number of *k*-good numbers in *a*.
[ "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "2 1\n1\n10\n" ]
[ "10\n", "1\n" ]
none
500
[ { "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "output": "10" }, { "input": "2 1\n1\n10", "output": "1" }, { "input": "1 0\n1000000000", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { ...
1,666,555,113
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import math n,k=list(map(int,input().split(' '))) count = 0 stk = str(k) for i in range(n): st = str(input()) tem = set() for i in range(len(st)): if st[i]<= stk): tem.add(st[i]) if(len(tem)==k+1): count+=1 ...
Title: Good Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve...
```python import math n,k=list(map(int,input().split(' '))) count = 0 stk = str(k) for i in range(n): st = str(input()) tem = set() for i in range(len(st)): if st[i]<= stk): tem.add(st[i]) if(len(tem)==k+1): count+=1 ...
-1
474
B
Worms
PROGRAMMING
1,200
[ "binary search", "implementation" ]
null
null
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile. The third line contains single integer *m* (...
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
[ "5\n2 7 3 4 9\n3\n1 25 11\n" ]
[ "1\n5\n3\n" ]
For the sample input: - The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f...
1,000
[ { "input": "5\n2 7 3 4 9\n3\n1 25 11", "output": "1\n5\n3" } ]
1,672,667,370
2,147,483,647
PyPy 3-64
OK
TESTS
38
514
95,129,600
from collections import defaultdict input() a = list(map(int, input().split())) input() q = list(map(int, input().split())) pos = defaultdict() pos.setdefault(0) cf = [a[0]] cf.extend([0] * len(a)) for worm in range(cf[0]): pos[worm + 1] = 1 p = 1 for pile in a[1:]: worms_size = pile cf[p] = cf[p -...
Title: Worms Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:...
```python from collections import defaultdict input() a = list(map(int, input().split())) input() q = list(map(int, input().split())) pos = defaultdict() pos.setdefault(0) cf = [a[0]] cf.extend([0] * len(a)) for worm in range(cf[0]): pos[worm + 1] = 1 p = 1 for pile in a[1:]: worms_size = pile cf[p...
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,588,062,006
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
n=input() lis=n.split() n=int(lis[0]) A=input() B=input() li=[] for i in range(1,n+1): if str(i) in A: li.append(1) elif str(i) in B: li.append(2) for i in range(len(li)): print(li[i],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=input() lis=n.split() n=int(lis[0]) A=input() B=input() li=[] for i in range(1,n+1): if str(i) in A: li.append(1) elif str(i) in B: li.append(2) for i in range(len(li)): print(li[i],end=" ") ```
0
483
A
Counterexample
PROGRAMMING
1,100
[ "brute force", "implementation", "math", "number theory" ]
null
null
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i...
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.
[ "2 4\n", "10 11\n", "900000000000000009 900000000000000029\n" ]
[ "2 3 4\n", "-1\n", "900000000000000009 900000000000000010 900000000000000021\n" ]
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
500
[ { "input": "2 4", "output": "2 3 4" }, { "input": "10 11", "output": "-1" }, { "input": "900000000000000009 900000000000000029", "output": "900000000000000009 900000000000000010 900000000000000021" }, { "input": "640097987171091791 640097987171091835", "output": "64009798...
1,690,753,219
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
/* . . Dev/Eng : Ziad Mohamed Gamal . */ // __________________________________________________( Libraries )__________________________________________________ #pragma warning(disable: 4996) #include <algorithm> #include <iostream> #include <iomanip> #include <utility> #include <stdio.h> #include <cstrin...
Title: Counterexample Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different st...
```python /* . . Dev/Eng : Ziad Mohamed Gamal . */ // __________________________________________________( Libraries )__________________________________________________ #pragma warning(disable: 4996) #include <algorithm> #include <iostream> #include <iomanip> #include <utility> #include <stdio.h> #inclu...
-1
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co...
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "ou...
1,543,599,556
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
109
0
x = eval(input()) if x%2==0: a = (x//2)-1 b = (x//2)+1 else: a = x//2 b = (x//2)+1 print(a," ",b)
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is cal...
```python x = eval(input()) if x%2==0: a = (x//2)-1 b = (x//2)+1 else: a = x//2 b = (x//2)+1 print(a," ",b) ```
0
780
A
Andryusha and Socks
PROGRAMMING
800
[ "implementation" ]
null
null
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ...
Print single integer — the maximum number of socks that were on the table at the same time.
[ "1\n1 1\n", "3\n2 1 1 3 2 3\n" ]
[ "1\n", "2\n" ]
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - ...
500
[ { "input": "1\n1 1", "output": "1" }, { "input": "3\n2 1 1 3 2 3", "output": "2" }, { "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5" }, { "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6" }, { "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ...
1,646,092,198
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
61
0
n=int(input()) order_of_pulling=list(map(int,input().split())) counter=1 for i in range(n): for j in range(i): if order_of_pulling[i]==order_of_pulling[j] and i!=j: counter-=1 else: counter+=1 print(counter)
Title: Andryusha and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere...
```python n=int(input()) order_of_pulling=list(map(int,input().split())) counter=1 for i in range(n): for j in range(i): if order_of_pulling[i]==order_of_pulling[j] and i!=j: counter-=1 else: counter+=1 print(counter) ```
0
710
A
King Moves
PROGRAMMING
800
[ "implementation" ]
null
null
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik...
The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.
Print the only integer *x* — the number of moves permitted for the king.
[ "e4\n" ]
[ "8\n" ]
none
0
[ { "input": "e4", "output": "8" }, { "input": "a1", "output": "3" }, { "input": "h8", "output": "3" }, { "input": "a4", "output": "5" }, { "input": "g7", "output": "8" }, { "input": "e1", "output": "5" }, { "input": "b2", "output": "8" ...
1,670,244,812
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
k=input() move=0 w={'a':2,'b':6,'c':6,'d':6,'e':6,'f':6,'g':6,'h':2} n={1:2,2:6,3:6,4:6,5:6,6:6,7:6,8:2} move=w[k[0]] + n[int(k[1])] if (k[0]=='a' and k[1]=='1') or (k[0]=='a' and k[1]=='8') or (k[0]=='h' and k[1]=='1') or (k[0]=='h' and k[1]=='8'): move-=1 elif 'a'<k[0]<'h' and 1<int(k[1])<8: move-=4 else: ...
Title: King Moves Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check...
```python k=input() move=0 w={'a':2,'b':6,'c':6,'d':6,'e':6,'f':6,'g':6,'h':2} n={1:2,2:6,3:6,4:6,5:6,6:6,7:6,8:2} move=w[k[0]] + n[int(k[1])] if (k[0]=='a' and k[1]=='1') or (k[0]=='a' and k[1]=='8') or (k[0]=='h' and k[1]=='1') or (k[0]=='h' and k[1]=='8'): move-=1 elif 'a'<k[0]<'h' and 1<int(k[1])<8: move-=4...
0
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest in...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000...
1,681,312,340
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
a,b = list(map(int, input().split())) def gcd(a,b): if b == 0: return a return gcd(b, a%b) print(gcd(a,b))
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre...
```python a,b = list(map(int, input().split())) def gcd(a,b): if b == 0: return a return gcd(b, a%b) print(gcd(a,b)) ```
0
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od...
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t...
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617...
1,698,658,660
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
z, x = map(int, input().split()) sq = [int(i) for i in input().split()] sq.sort() d = sq[:z] print(max(d) - min(d))
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a...
```python z, x = map(int, input().split()) sq = [int(i) for i in input().split()] sq.sort() d = sq[:z] print(max(d) - min(d)) ```
0
849
B
Tell Your World
PROGRAMMING
1,600
[ "brute force", "geometry" ]
null
null
Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of the...
The first line of input contains a positive integer *n* (3<=≤<=*n*<=≤<=1<=000) — the number of points. The second line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (<=-<=109<=≤<=*y**i*<=≤<=109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
[ "5\n7 5 8 6 9\n", "5\n-1 -2 0 0 -5\n", "5\n5 4 3 2 1\n", "5\n1000000000 0 0 0 0\n" ]
[ "Yes\n", "No\n", "No\n", "Yes\n" ]
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, ...
1,000
[ { "input": "5\n7 5 8 6 9", "output": "Yes" }, { "input": "5\n-1 -2 0 0 -5", "output": "No" }, { "input": "5\n5 4 3 2 1", "output": "No" }, { "input": "5\n1000000000 0 0 0 0", "output": "Yes" }, { "input": "5\n1000000000 1 0 -999999999 -1000000000", "output": "...
1,504,275,834
2,934
Python 3
WRONG_ANSWER
TESTS
12
46
307,200
n=int(input()) a=list(map(int,input().split())) b=[] for i in range(1,n+1): b.append([a[i-1],i]) b.sort() tan=[] for i in range(1,n): tan.append((b[i][0]-b[i-1][0])/(b[i][1]-b[i-1][1])) count=[] tan.sort() t=1 for i in range(1,n-1): if tan[i]==tan[i-1]: t+=1 else: count.a...
Title: Tell Your World Time Limit: None seconds Memory Limit: None megabytes Problem Description: Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and...
```python n=int(input()) a=list(map(int,input().split())) b=[] for i in range(1,n+1): b.append([a[i-1],i]) b.sort() tan=[] for i in range(1,n): tan.append((b[i][0]-b[i-1][0])/(b[i][1]-b[i-1][1])) count=[] tan.sort() t=1 for i in range(1,n-1): if tan[i]==tan[i-1]: t+=1 else: ...
0
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors...
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ...
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReal...
1,626,328,483
2,147,483,647
Python 3
OK
TESTS
64
77
6,963,200
n=int(input()) b=dict({'Power':'purple','Time':'green' , 'Space' :'blue','Soul':'orange', 'Reality':'red','Mind':'yellow'}) a=[] for i in range(n): a.append(input()) print(6-n) for x in b: if b[x] not in a: print(x)
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So...
```python n=int(input()) b=dict({'Power':'purple','Time':'green' , 'Space' :'blue','Soul':'orange', 'Reality':'red','Mind':'yellow'}) a=[] for i in range(n): a.append(input()) print(6-n) for x in b: if b[x] not in a: print(x) ```
3
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,642,604,833
2,147,483,647
PyPy 3-64
OK
TESTS
59
93
0
def gt(n): p=1 for i in range(1,n+1): p*=i return p a,b = [int(x) for x in input().split()] print(gt(min(a,b)))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi...
```python def gt(n): p=1 for i in range(1,n+1): p*=i return p a,b = [int(x) for x in input().split()] print(gt(min(a,b))) ```
3
669
A
Little Artem and Presents
PROGRAMMING
800
[ "math" ]
null
null
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Print the maximum possible number of times Artem can give presents to Masha.
[ "1\n", "2\n", "3\n", "4\n" ]
[ "1\n", "1\n", "2\n", "3\n" ]
In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ...
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "3" }, { "input": "100", "output": "67" }, { "input": "101", "output": "67" }, { "input": "102", "output": "68"...
1,666,457,656
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
import sys def solve(n): if n<3: return 1 ct = (n//3) * 2 s= n%3 if s==1: ct +=1 return ct for name in map(str.rstrip, sys.stdin): n = int(name) break res = solve(n) print(res)
Title: Little Artem and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan...
```python import sys def solve(n): if n<3: return 1 ct = (n//3) * 2 s= n%3 if s==1: ct +=1 return ct for name in map(str.rstrip, sys.stdin): n = int(name) break res = solve(n) print(res) ```
0
453
A
Little Pony and Expected Maximum
PROGRAMMING
1,600
[ "probabilities" ]
null
null
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots...
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
[ "6 1\n", "6 3\n", "2 2\n" ]
[ "3.500000000000\n", "4.958333333333\n", "1.750000000000\n" ]
Consider the third test example. If you've made two tosses: 1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in t...
500
[ { "input": "6 1", "output": "3.500000000000" }, { "input": "6 3", "output": "4.958333333333" }, { "input": "2 2", "output": "1.750000000000" }, { "input": "5 4", "output": "4.433600000000" }, { "input": "5 8", "output": "4.814773760000" }, { "input": "...
1,602,948,505
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
10
249
102,400
line = input().split() m = int(line[0]) n = int(line[1]) numberOfCombinations = pow(m, n) prob = 1/numberOfCombinations result = 0 for current in range(m, 0, -1): result += current * (pow(current, n) - pow(current - 1, n)) print(result * prob)
Title: Little Pony and Expected Maximum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were ...
```python line = input().split() m = int(line[0]) n = int(line[1]) numberOfCombinations = pow(m, n) prob = 1/numberOfCombinations result = 0 for current in range(m, 0, -1): result += current * (pow(current, n) - pow(current - 1, n)) print(result * prob) ```
-1
994
B
Knights of a Polygonal Table
PROGRAMMING
1,400
[ "greedy", "implementation", "sortings" ]
null
null
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo...
The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement. The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct. The third line contains $n...
Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights.
[ "4 2\n4 5 9 7\n1 2 11 33\n", "5 1\n1 2 3 4 5\n1 2 3 4 5\n", "1 0\n2\n3\n" ]
[ "1 3 46 36 ", "1 3 5 7 9 ", "3 " ]
Consider the first example. - The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o...
1,000
[ { "input": "4 2\n4 5 9 7\n1 2 11 33", "output": "1 3 46 36 " }, { "input": "5 1\n1 2 3 4 5\n1 2 3 4 5", "output": "1 3 5 7 9 " }, { "input": "1 0\n2\n3", "output": "3 " }, { "input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9", "output": "0 3 10 16 14 17 18 " }, { "input"...
1,529,239,834
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
0
def build_index(s_knights, c_knights, n): map_ = [0]*n # Build index sorted by strength knights list to sorted by coin amount knights list for ski, k1 in enumerate(s_knights): for cki, k2 in enumerate(c_knights): if k1[2] == k2[2]: map_[ski] = cki return map_ if __nam...
Title: Knights of a Polygonal Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ...
```python def build_index(s_knights, c_knights, n): map_ = [0]*n # Build index sorted by strength knights list to sorted by coin amount knights list for ski, k1 in enumerate(s_knights): for cki, k2 in enumerate(c_knights): if k1[2] == k2[2]: map_[ski] = cki return map_ ...
0
372
A
Counting Kangaroos is Fun
PROGRAMMING
1,600
[ "binary search", "greedy", "sortings", "two pointers" ]
null
null
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who i...
The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105).
Output a single integer — the optimal number of visible kangaroos.
[ "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "8\n9\n1\n6\n2\n6\n5\n8\n3\n" ]
[ "5\n", "5\n" ]
none
500
[ { "input": "8\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5" }, { "input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5" }, { "input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52", "output": "7" }, { "input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9", "output": "6" ...
1,673,126,057
2,147,483,647
Python 3
OK
TESTS
45
920
14,745,600
n = int(input()) sizes = sorted([int(input()) for i in range(n)]) opt = n-1 cnt = 0 for i in range(n//2-1, -1, -1): if sizes[i] * 2 <= sizes[opt]: opt -= 1 cnt += 1 print(opt+1)
Title: Counting Kangaroos is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ...
```python n = int(input()) sizes = sorted([int(input()) for i in range(n)]) opt = n-1 cnt = 0 for i in range(n//2-1, -1, -1): if sizes[i] * 2 <= sizes[opt]: opt -= 1 cnt += 1 print(opt+1) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,648,760,229
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split(' ')))) i,j,k=0,0,0 for n in range(3): i=i+a[n][0] j=j+a[n][1] k=k+a[n][2] if(i==0 and j==0 and k==0 or (i==j and j==k)): 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 i in range(n): a.append(list(map(int,input().split(' ')))) i,j,k=0,0,0 for n in range(3): i=i+a[n][0] j=j+a[n][1] k=k+a[n][2] if(i==0 and j==0 and k==0 or (i==j and j==k)): print('YES') else: print('NO') ```
0
588
B
Duff in Love
PROGRAMMING
1,300
[ "math" ]
null
null
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want...
The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012).
Print the answer in one line.
[ "10\n", "12\n" ]
[ "10\n", "6\n" ]
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely. In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely.
1,000
[ { "input": "10", "output": "10" }, { "input": "12", "output": "6" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "4", "output": "2" }, { "input": "8", "output": "2" }, { "input": "3", "output": "3" }, ...
1,634,565,776
2,147,483,647
Python 3
OK
TESTS
53
327
0
n = int(input()) for i in range(2,10**6): while n%(i*i) ==0 : n = n // i print(n)
Title: Duff in Love Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has...
```python n = int(input()) for i in range(2,10**6): while n%(i*i) ==0 : n = n // i print(n) ```
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,526,625,274
2,147,483,647
Python 3
OK
TESTS
45
778
5,427,200
n = int(input()) l = [] r = [] # đọc dữ liệu for i in range(n): a, b = map(int, input().split()) l.append(a) r.append(b) minL = min(l) maxR = max(r) # Tìm minL, maxR found = False for i in range(n): if l[i] == minL and r[i] == maxR: print(i+1) found = True if found == False: ...
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 n = int(input()) l = [] r = [] # đọc dữ liệu for i in range(n): a, b = map(int, input().split()) l.append(a) r.append(b) minL = min(l) maxR = max(r) # Tìm minL, maxR found = False for i in range(n): if l[i] == minL and r[i] == maxR: print(i+1) found = True if found ==...
3
811
A
Vladik and Courtesy
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving eac...
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
[ "1 1\n", "7 6\n" ]
[ "Valera\n", "Vladik\n" ]
Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e...
500
[ { "input": "1 1", "output": "Valera" }, { "input": "7 6", "output": "Vladik" }, { "input": "25 38", "output": "Vladik" }, { "input": "8311 2468", "output": "Valera" }, { "input": "250708 857756", "output": "Vladik" }, { "input": "957985574 24997558", ...
1,495,901,053
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
a,b=map(int, input().split()) if a>b: print("Vladik") else: print("Valera")
Title: Vladik and Courtesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla...
```python a,b=map(int, input().split()) if a>b: print("Vladik") else: print("Valera") ```
0
1,004
C
Sonya and Robots
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi...
The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row.
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.
[ "5\n1 5 4 1 3\n", "7\n1 2 1 1 1 3 2\n" ]
[ "9\n", "7\n" ]
In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
1,500
[ { "input": "5\n1 5 4 1 3", "output": "9" }, { "input": "7\n1 2 1 1 1 3 2", "output": "7" }, { "input": "10\n2 2 4 4 3 1 1 2 3 2", "output": "14" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4", "output": "20" }, { "input": "1\n1", "output": "0" } ]
1,611,558,078
2,147,483,647
PyPy 3
OK
TESTS
42
264
17,715,200
import functools import time def timer(func): @functools.wraps(func) def wrapper(*args, **kwargs): stime = time.perf_counter() res = func(*args, **kwargs) elapsed = time.perf_counter() - stime print(f"{func.__name__} in {elapsed:.4f} secs") return res retu...
Title: Sonya and Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ...
```python import functools import time def timer(func): @functools.wraps(func) def wrapper(*args, **kwargs): stime = time.perf_counter() res = func(*args, **kwargs) elapsed = time.perf_counter() - stime print(f"{func.__name__} in {elapsed:.4f} secs") return res...
3
552
A
Vanya and Table
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of rectangles. Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1<=≤<=*x*2<=≤<=100, 1<=≤<=*y*1<=≤<=*y*2<=≤<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *...
In a single line print the sum of all values in the cells of the table.
[ "2\n1 1 2 3\n2 2 3 3\n", "2\n1 1 3 3\n1 1 3 3\n" ]
[ "10\n", "18\n" ]
Note to the first sample test: Values of the table in the first three rows and columns will be as follows: 121 121 110 So, the sum of values will be equal to 10. Note to the second sample test: Values of the table in the first three rows and columns will be as follows: 222 222 222 So, the sum of values will ...
500
[ { "input": "2\n1 1 2 3\n2 2 3 3", "output": "10" }, { "input": "2\n1 1 3 3\n1 1 3 3", "output": "18" }, { "input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13", "output": "510" }, { "input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11", "o...
1,661,683,309
2,147,483,647
Python 3
OK
TESTS
26
46
0
from cmath import inf n = int(input()) ans = 0 for _ in range(n): x1, y1, x2, y2 = [int(i) for i in input().split(' ')] ans += (abs(x2 - x1) + 1) * (abs(y2 - y1) + 1) print(ans)
Title: Vanya and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vany...
```python from cmath import inf n = int(input()) ans = 0 for _ in range(n): x1, y1, x2, y2 = [int(i) for i in input().split(' ')] ans += (abs(x2 - x1) + 1) * (abs(y2 - y1) + 1) print(ans) ```
3
336
A
Vasily the Bear and Triangle
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he...
The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0).
Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points.
[ "10 5\n", "-10 5\n" ]
[ "0 15 15 0\n", "-15 0 0 15\n" ]
<img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/> Figure to the first sample
500
[ { "input": "10 5", "output": "0 15 15 0" }, { "input": "-10 5", "output": "-15 0 0 15" }, { "input": "20 -10", "output": "0 -30 30 0" }, { "input": "-10 -1000000000", "output": "-1000000010 0 0 -1000000010" }, { "input": "-1000000000 -1000000000", "output": "-...
1,376,323,411
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
def find_coordinates (x, y) : if x > 0 : y2 = x1 = x + y x2 = y1 = 0 else : y2 = y - x x1 = - (y - x) y1 = x2 = 0 return x1, y1, x2, y2 #print find_coordinates (10,5)
Title: Vasily the Bear and Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ...
```python def find_coordinates (x, y) : if x > 0 : y2 = x1 = x + y x2 = y1 = 0 else : y2 = y - x x1 = - (y - x) y1 = x2 = 0 return x1, y1, x2, y2 #print find_coordinates (10,5) ```
0
1,003
C
Intense Heat
PROGRAMMING
1,300
[ "brute force", "implementation", "math" ]
null
null
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually cal...
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 5000$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 5000$) — the ...
Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $k$ consecutive days. Your answer will be considered correct if the following condition holds: $|res - res_0| &lt; 10^{-6}$, where $res$ is your answer, and $res_0$ is the answer given by the...
[ "4 3\n3 4 1 2\n" ]
[ "2.666666666666667\n" ]
none
0
[ { "input": "4 3\n3 4 1 2", "output": "2.666666666666667" }, { "input": "5 1\n3 10 9 10 6", "output": "10.000000000000000" }, { "input": "5 2\n7 3 3 1 8", "output": "5.000000000000000" }, { "input": "5 3\n1 7 6 9 1", "output": "7.333333333333333" }, { "input": "5 4...
1,678,852,330
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
4,000
0
def main(): n, k = map(int, input().split()) temperatures = list(map(int, input().split())) def calculate_heat_intensity(n, k, temperatures): prefix_sum = [0] * (n + 1) for i in range(1, n + 1): prefix_sum[i] = prefix_sum[i - 1] + temperatures[i - 1] max_averag...
Title: Intense Heat Time Limit: None seconds Memory Limit: None megabytes Problem Description: The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sou...
```python def main(): n, k = map(int, input().split()) temperatures = list(map(int, input().split())) def calculate_heat_intensity(n, k, temperatures): prefix_sum = [0] * (n + 1) for i in range(1, n + 1): prefix_sum[i] = prefix_sum[i - 1] + temperatures[i - 1] ...
0
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", ...
1,619,331,669
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
N = int(input()) characters = str(input()) encrypt = [] count = 0 groups = 0 for i in (characters): if (i == 'B'): count += 1 elif (count != 0 and i == 'W'): encrypt.append(count) groups += 1 count = 0 if (characters[-1] == 'B' and characters[-2] == 'B'): groups += 1 ...
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the...
```python N = int(input()) characters = str(input()) encrypt = [] count = 0 groups = 0 for i in (characters): if (i == 'B'): count += 1 elif (count != 0 and i == 'W'): encrypt.append(count) groups += 1 count = 0 if (characters[-1] == 'B' and characters[-2] == 'B'): grou...
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,607,535,467
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
s=input() h=0 e=0 l=0 o=0 if(len(s)>=5): for i in s: if i=='h': h=1 elif i=='e': if(h==1): e=1 else: break elif i=='l': if(e==1): l=1 else: break ...
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python s=input() h=0 e=0 l=0 o=0 if(len(s)>=5): for i in s: if i=='h': h=1 elif i=='e': if(h==1): e=1 else: break elif i=='l': if(e==1): l=1 else: ...
-1
850
A
Five Dimensional Points
PROGRAMMING
1,700
[ "brute force", "geometry", "math" ]
null
null
You are given set of *n* points in 5-dimensional space. The points are labeled from 1 to *n*. No two points coincide. We will call point *a* bad if there are different points *b* and *c*, not equal to *a*, from the given set such that angle between vectors and is acute (i.e. strictly less than ). Otherwise, the poin...
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=103) — the number of points. The next *n* lines of input contain five integers *a**i*,<=*b**i*,<=*c**i*,<=*d**i*,<=*e**i* (|*a**i*|,<=|*b**i*|,<=|*c**i*|,<=|*d**i*|,<=|*e**i*|<=≤<=103)  — the coordinates of the i-th point. All points are distinct.
First, print a single integer *k* — the number of good points. Then, print *k* integers, each on their own line — the indices of the good points in ascending order.
[ "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n", "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n" ]
[ "1\n1\n", "0\n" ]
In the first sample, the first point forms exactly a <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/362ac8c7a7496dffc06cd0c843287cd822be63c3.png" style="max-width: 100.0%;max-height: 100.0%;"/> angle with all other pairs of points, so it is good. In the second sample, along the cd plane, ...
500
[ { "input": "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1", "output": "1\n1" }, { "input": "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0", "output": "0" }, { "input": "1\n0 0 0 0 0", "output": "1\n1" }, { "input": "2\n0 1 2 3 4\n5 6 7 8 9", "output": "2\n1\n2"...
1,507,913,827
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
from math import sqrt, acos, pi n = int(input()) p = [tuple(map(int, input().split())) for i in range(n)] def x_y(x, y): return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] + x[4]*y[4] def angle(x, y): xy = x_y(x, y) xx = sqrt(x_y(x, x)) yy = sqrt(x_y(y, y)) d = xx * yy retu...
Title: Five Dimensional Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given set of *n* points in 5-dimensional space. The points are labeled from 1 to *n*. No two points coincide. We will call point *a* bad if there are different points *b* and *c*, not equal to *a*, from...
```python from math import sqrt, acos, pi n = int(input()) p = [tuple(map(int, input().split())) for i in range(n)] def x_y(x, y): return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] + x[4]*y[4] def angle(x, y): xy = x_y(x, y) xx = sqrt(x_y(x, x)) yy = sqrt(x_y(y, y)) d = xx * yy...
0
549
A
Face Detection
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<...
The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively. Next *n* lines define the image. Each line contains *m* lowercase Latin letters.
In the single line print the number of faces on the image.
[ "4 4\nxxxx\nxfax\nxcex\nxxxx\n", "4 2\nxx\ncf\nae\nxx\n", "2 3\nfac\ncef\n", "1 4\nface\n" ]
[ "1\n", "1\n", "2\n", "0\n" ]
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: In ...
250
[ { "input": "4 4\nxxxx\nxfax\nxcex\nxxxx", "output": "1" }, { "input": "4 2\nxx\ncf\nae\nxx", "output": "1" }, { "input": "2 3\nfac\ncef", "output": "2" }, { "input": "1 4\nface", "output": "0" }, { "input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx", "output": "...
1,541,778,616
2,147,483,647
PyPy 3
OK
TESTS
37
139
204,800
n,m=map(int,input().split()) c=[] for i in range(n): c.append(input()) z=0 for i in range(len(c)-1): for j in range(len(c[i])-1): l=[] l.append(c[i][j]) l.append(c[i+1][j]) l.append(c[i][j+1]) l.append(c[i+1][j+1]) if(l.count('f')==1 and l.count('a')==1 and l.coun...
Title: Face Detection Time Limit: None seconds Memory Limit: None megabytes Problem Description: The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem a...
```python n,m=map(int,input().split()) c=[] for i in range(n): c.append(input()) z=0 for i in range(len(c)-1): for j in range(len(c[i])-1): l=[] l.append(c[i][j]) l.append(c[i+1][j]) l.append(c[i][j+1]) l.append(c[i+1][j+1]) if(l.count('f')==1 and l.count('a')==1 ...
3
373
A
Collecting Beats is Fun
PROGRAMMING
900
[ "implementation" ]
null
null
Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with...
The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand. Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per...
Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).
[ "1\n.135\n1247\n3468\n5789\n", "5\n..1.\n1111\n..1.\n..1.\n", "1\n....\n12.1\n.2..\n.2..\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.
500
[ { "input": "1\n.135\n1247\n3468\n5789", "output": "YES" }, { "input": "5\n..1.\n1111\n..1.\n..1.", "output": "YES" }, { "input": "1\n....\n12.1\n.2..\n.2..", "output": "NO" }, { "input": "1\n6981\n.527\n4163\n2345", "output": "YES" }, { "input": "5\n9999\n9999\n99...
1,580,461,180
2,147,483,647
PyPy 3
OK
TESTS
27
156
0
import sys panels_per_hand = int(input()) panels = [] for x in range(4): panels.append(input()) panel_string = '' for x in panels: panel_string += x freq = None for x in panel_string: if x == '.': continue freq = 0 for y in panel_string: if x == y: freq += ...
Title: Collecting Beats is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preff...
```python import sys panels_per_hand = int(input()) panels = [] for x in range(4): panels.append(input()) panel_string = '' for x in panels: panel_string += x freq = None for x in panel_string: if x == '.': continue freq = 0 for y in panel_string: if x == y: ...
3
960
A
Check the string
PROGRAMMING
1,200
[ "implementation" ]
null
null
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gi...
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Print "YES" or "NO", according to the condition.
[ "aaabccc\n", "bbacc\n", "aabc\n" ]
[ "YES\n", "NO\n", "YES\n" ]
Consider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct. Consider third example: the number of 'c' is equal to the number of 'b'.
500
[ { "input": "aaabccc", "output": "YES" }, { "input": "bbacc", "output": "NO" }, { "input": "aabc", "output": "YES" }, { "input": "aabbcc", "output": "YES" }, { "input": "aaacccbb", "output": "NO" }, { "input": "abc", "output": "YES" }, { "in...
1,685,284,192
2,147,483,647
Python 3
OK
TESTS
55
46
0
# import sys # input = sys.stdin.readline for _ in range(1):#int(input())): s = input() a, b, c = 0, 0, 0 flag = 0 if (s[0] == 'a'): a += 1 for i in range(1, len(s)): if (s[i] >= s[i-1]): if (s[i] == 'a'): a += 1 elif (s[i] == 'b'): ...
Title: Check the string Time Limit: None seconds Memory Limit: None megabytes Problem Description: A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b...
```python # import sys # input = sys.stdin.readline for _ in range(1):#int(input())): s = input() a, b, c = 0, 0, 0 flag = 0 if (s[0] == 'a'): a += 1 for i in range(1, len(s)): if (s[i] >= s[i-1]): if (s[i] == 'a'): a += 1 elif (s[i] == 'b...
3
626
C
Block Towers
PROGRAMMING
1,600
[ "brute force", "greedy", "math", "number theory" ]
null
null
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be ...
The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=&gt;<=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Print a single integer, denoting the minimum possible height of the tallest tower.
[ "1 3\n", "3 2\n", "5 0\n" ]
[ "9\n", "8\n", "10\n" ]
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks. In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and tower...
1,000
[ { "input": "1 3", "output": "9" }, { "input": "3 2", "output": "8" }, { "input": "5 0", "output": "10" }, { "input": "4 2", "output": "9" }, { "input": "0 1000000", "output": "3000000" }, { "input": "1000000 1", "output": "2000000" }, { "in...
1,455,421,344
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
import sys ##Wrong answer... not finished def main(): n, m = [int(f) for f in sys.stdin.readline().split()] h = max(2 * n, 3 * m) n_common = h // 6 n3 = h // 3 - n_common n2 = h // 2 - n_common if n3 >= m or n2 >= n: res = h elif n3 < m: res = (m - n3) * 2 + h el...
Title: Block Towers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use piece...
```python import sys ##Wrong answer... not finished def main(): n, m = [int(f) for f in sys.stdin.readline().split()] h = max(2 * n, 3 * m) n_common = h // 6 n3 = h // 3 - n_common n2 = h // 2 - n_common if n3 >= m or n2 >= n: res = h elif n3 < m: res = (m - n3) * 2 ...
0
54
A
Presents
PROGRAMMING
1,300
[ "implementation" ]
A. Presents
2
256
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c...
The first line contains integers *N* and *K* (1<=≤<=*N*<=≤<=365, 1<=≤<=*K*<=≤<=*N*). The second line contains a number *C* which represents the number of holidays (0<=≤<=*C*<=≤<=*N*). Then in the same line follow *C* numbers ranging from 1 to *N* which are the numbers of holiday days. The numbers are given in the incr...
Print a single number — the minimal number of presents the Hedgehog will receive over the following *N* days.
[ "5 2\n1 3\n", "10 1\n3 6 7 8\n" ]
[ "3", "10" ]
none
500
[ { "input": "5 2\n1 3", "output": "3" }, { "input": "10 1\n3 6 7 8", "output": "10" }, { "input": "5 5\n1 3", "output": "1" }, { "input": "10 3\n3 3 6 9", "output": "3" }, { "input": "5 2\n0", "output": "2" }, { "input": "1 1\n0", "output": "1" },...
1,571,523,209
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
0
n, k = map(int, input().split()) c = list(map(int, input().split()))[1:] present = [0] * n for i in c: present[i - 1] = 1 prev = -1 d = 0 for i in range(n): if i - prev == k: d += 1 prev = i elif present[i] == 1: prev = i d += 1 elif i == n - 1: d +...
Title: Presents Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the spec...
```python n, k = map(int, input().split()) c = list(map(int, input().split()))[1:] present = [0] * n for i in c: present[i - 1] = 1 prev = -1 d = 0 for i in range(n): if i - prev == k: d += 1 prev = i elif present[i] == 1: prev = i d += 1 elif i == n - 1: ...
0
675
B
Restoring Painting
PROGRAMMING
1,400
[ "brute force", "constructive algorithms", "math" ]
null
null
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*,...
The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
Print one integer — the number of distinct valid squares.
[ "2 1 1 1 2\n", "3 3 1 2 3\n" ]
[ "2\n", "6\n" ]
Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1....
1,000
[ { "input": "2 1 1 1 2", "output": "2" }, { "input": "3 3 1 2 3", "output": "6" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1000 522 575 426 445", "output": "774000" }, { "input": "99000 52853 14347 64237 88869", "output": "1296306000" }, { ...
1,514,705,221
2,147,483,647
Python 3
OK
TESTS
58
62
5,632,000
#Codeforces: Restoring Painting n,a,b,c,d=[eval(x) for x in input().split()] if(a<d): ab=c+(d-a) else: ab=c aa=ab+a+b ac=aa-(a+c) bd=aa-(b+d) cd=aa-(c+d) mini=min(ab,ac,bd,cd) maxi=max(ab,ac,bd,cd) diff=maxi-mini t=n-(1+diff)+1 if(t<=0): print(0) else: print(t*n)
Title: Restoring Painting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some ...
```python #Codeforces: Restoring Painting n,a,b,c,d=[eval(x) for x in input().split()] if(a<d): ab=c+(d-a) else: ab=c aa=ab+a+b ac=aa-(a+c) bd=aa-(b+d) cd=aa-(c+d) mini=min(ab,ac,bd,cd) maxi=max(ab,ac,bd,cd) diff=maxi-mini t=n-(1+diff)+1 if(t<=0): print(0) else: print(t*n) ...
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,641,224,767
2,147,483,647
Python 3
OK
TESTS
102
61
0
a = input() b = input() ans = [] for i,x in enumerate(a): if x == b[i]: ans.append("0") else: ans.append("1") c = "".join(ans) 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() b = input() ans = [] for i,x in enumerate(a): if x == b[i]: ans.append("0") else: ans.append("1") c = "".join(ans) print(c) ```
3.98475
20
C
Dijkstra?
PROGRAMMING
1,900
[ "graphs", "shortest paths" ]
C. Dijkstra?
1
64
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
[ "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n" ]
[ "1 4 3 5 ", "1 4 3 5 " ]
none
1,500
[ { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "2 1\n1 2 1", "output": "1 2 " }, { "input": "3 1\n1 2 1", "output": "-1" }, { "input...
1,549,640,567
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
def get(): return list(map(int,input().split())) n,m=get() a=n*[0] for i in range(n): a[i]=n*[0] for i in range(m): u,v,w=get() a[u-1][v-1]=w a[v-1][u-1]=w best=n*[0] for i in range(n): best[i]=[1e12,[]] best[0]=[0,[1]] q=[0] while q: w=q.pop(0) for i in range(n): ...
Title: Dijkstra? Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. Input Specification: The first line contains two integers *n* a...
```python def get(): return list(map(int,input().split())) n,m=get() a=n*[0] for i in range(n): a[i]=n*[0] for i in range(m): u,v,w=get() a[u-1][v-1]=w a[v-1][u-1]=w best=n*[0] for i in range(n): best[i]=[1e12,[]] best[0]=[0,[1]] q=[0] while q: w=q.pop(0) for i in range(...
0
884
A
Book Reading
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she...
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*.
[ "2 2\n86400 86398\n", "2 86400\n0 86400\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "2 2\n86400 86398", "output": "2" }, { "input": "2 86400\n0 86400", "output": "1" }, { "input": "2 86400\n1 86399", "output": "2" }, { "input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
1,551,441,301
2,147,483,647
Python 3
OK
TESTS
16
108
0
n, t = map(int, input().split()) n = 0 s = list(map(lambda x: 86400 - int(x), input().split())) for i, j in enumerate(s): n += j if n >= t: print(i + 1) exit(0)
Title: Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of ...
```python n, t = map(int, input().split()) n = 0 s = list(map(lambda x: 86400 - int(x), input().split())) for i, j in enumerate(s): n += j if n >= t: print(i + 1) exit(0) ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red...
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,698,501,747
2,147,483,647
Python 3
OK
TESTS
34
92
0
n=int(input()) s1=input() c=0 for i in range(0,n-1): if s1[i]==s1[i+1]: c+=1 print(c)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ...
```python n=int(input()) s1=input() c=0 for i in range(0,n-1): if s1[i]==s1[i+1]: c+=1 print(c) ```
3
863
D
Yet Another Array Queries Problem
PROGRAMMING
1,800
[ "data structures", "implementation" ]
null
null
You are given an array *a* of size *n*, and *q* queries to it. There are queries of two types: - 1 *l**i* *r**i* — perform a cyclic shift of the segment [*l**i*,<=*r**i*] to the right. That is, for every *x* such that *l**i*<=≤<=*x*<=&lt;<=*r**i* new value of *a**x*<=+<=1 becomes equal to old value of *a**x*, and ne...
The first line contains three integer numbers *n*, *q* and *m* (1<=≤<=*n*,<=*q*<=≤<=2·105, 1<=≤<=*m*<=≤<=100). The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Then *q* lines follow. *i*-th of them contains three integer numbers *t**i*, *l**i*, *r**i*, where *t**i* is the...
Print *m* numbers, *i*-th of which is equal to the number at index *b**i* after all queries are done.
[ "6 3 5\n1 2 3 4 5 6\n2 1 3\n2 3 6\n1 1 6\n2 2 1 5 3\n" ]
[ "3 3 1 5 2 \n" ]
none
0
[ { "input": "6 3 5\n1 2 3 4 5 6\n2 1 3\n2 3 6\n1 1 6\n2 2 1 5 3", "output": "3 3 1 5 2 " }, { "input": "5 2 5\n64 3 4 665 2\n1 1 3\n2 1 5\n1 2 3 4 5", "output": "2 665 3 64 4 " }, { "input": "1 1 1\n474812122\n2 1 1\n1", "output": "474812122 " } ]
1,590,244,188
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
156
102,400
import sys import math from collections import defaultdict,deque def get(ind ,arr): n = len(arr) for i in range(n): t,l,r = arr[i] if t == 1: if l <= ind <= r: if ind == l: ind = r else: ind -= 1 continue if t == 2: if l <=ind <= r: ind = (r - ind + l) continue...
Title: Yet Another Array Queries Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a* of size *n*, and *q* queries to it. There are queries of two types: - 1 *l**i* *r**i* — perform a cyclic shift of the segment [*l**i*,<=*r**i*] to the right. That is, for ...
```python import sys import math from collections import defaultdict,deque def get(ind ,arr): n = len(arr) for i in range(n): t,l,r = arr[i] if t == 1: if l <= ind <= r: if ind == l: ind = r else: ind -= 1 continue if t == 2: if l <=ind <= r: ind = (r - ind + l) ...
0
151
B
Phone Numbers
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
Winters are just damn freezing cold in Nvodsk! That's why a group of *n* friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size *s**i* (that's the number of phone numbers). We know that tax...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of friends. Then follow *n* data blocks that describe each friend's phone books. Each block is presented in the following form: first goes the line that contains integer *s**i* and string *name**i* (0<=≤<=*s**i*<=≤<=100) — the number of phone num...
In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers. In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal nu...
[ "4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32\n", "3\n5 Gleb\n66-66-66\n55-55-55\n01-01-01\n65-43-21\n12-34-56\n3 Serega\n55-55-55\n87-65-43\n65-55-21\n5 Melni...
[ "If you want to call a taxi, you should call: Rogulenko.\nIf you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin.\nIf you want to go to a cafe with a wonderful girl, you should call: Melnikov.\n", "If you want to call a taxi, you should call: Gleb.\nIf you want to order a pizza, you should ca...
In the first sample you are given four friends. Fedorov's phone book contains one taxi number and one pizza delivery number, Melnikov's phone book only has 3 numbers of girls, Rogulenko's one has 6 taxi numbers and one pizza delivery number, Kaluzhin's one contains 2 taxi numbers and one pizza delivery number. Thus, i...
1,000
[ { "input": "4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32", "output": "If you want to call a taxi, you should call: Rogulenko.\nIf you want to order a piz...
1,673,622,166
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
46
0
taxinum = [111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999] mylist = [] for _ in range(int(input())): n, name = input().split() a = [0] * 3 a.append(name) for _ in range(int(n)): x = input() xnew = int("".join(x.split("-"))) xnew_str = str(xnew) ...
Title: Phone Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Winters are just damn freezing cold in Nvodsk! That's why a group of *n* friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56)...
```python taxinum = [111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999] mylist = [] for _ in range(int(input())): n, name = input().split() a = [0] * 3 a.append(name) for _ in range(int(n)): x = input() xnew = int("".join(x.split("-"))) xnew_str = st...
0
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", ...
1,588,613,775
2,147,483,647
PyPy 3
OK
TESTS
79
218
13,516,800
n = int(input()) s = [int(i) for i in input().split() if int(i) != 0] print(len(set(s)))
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second ...
```python n = int(input()) s = [int(i) for i in input().split() if int(i) != 0] print(len(set(s))) ```
3
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=......
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w...
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", ...
1,646,909,752
2,147,483,647
Python 3
OK
TESTS
34
46
0
n = int(input()) my_list = list(map(int, input().split())) time = [0] * 106 my_list = [0] + my_list temp_list = [1] * 15 for i in my_list: time[i:i+15] = temp_list i = 15 while (time[i] == 1) and (i <= 89): i += 1 print(i)
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim...
```python n = int(input()) my_list = list(map(int, input().split())) time = [0] * 106 my_list = [0] + my_list temp_list = [1] * 15 for i in my_list: time[i:i+15] = temp_list i = 15 while (time[i] == 1) and (i <= 89): i += 1 print(i) ```
3
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for...
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhe...
1,503,969,830
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
s = input() k = int(input()) r = [] sol = 0 if k <= len(s): for c in s: if c in r: sol = sol+1 else: r.append(c) print(sol) else: print("impossible")
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it...
```python s = input() k = int(input()) r = [] sol = 0 if k <= len(s): for c in s: if c in r: sol = sol+1 else: r.append(c) print(sol) else: print("impossible") ```
0
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integer...
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { ...
1,697,636,929
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
n,k=map(int,input().split()) if k>n: print(n) else: print(k)
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits...
```python n,k=map(int,input().split()) if k>n: print(n) else: print(k) ```
0
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th...
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar...
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", ...
1,684,806,885
2,147,483,647
Python 3
OK
TESTS
52
46
0
a,b = map(int,input().split()) sum = 240 - b count = 0 for i in range(1,a+1): if sum >= 5*i: sum -= 5*i count += 1 print(count)
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem...
```python a,b = map(int,input().split()) sum = 240 - b count = 0 for i in range(1,a+1): if sum >= 5*i: sum -= 5*i count += 1 print(count) ```
3
359
A
Table
PROGRAMMING
1,000
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are...
The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50). Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* e...
Print a single number — the minimum number of operations Simon needs to carry out his idea.
[ "3 3\n0 0 0\n0 1 0\n0 0 0\n", "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n" ]
[ "4\n", "2\n" ]
In the first sample, the sequence of operations can be like this: - For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to c...
500
[ { "input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "4" }, { "input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0", "output": "2" }, { "input": "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0...
1,626,775,014
2,147,483,647
PyPy 3
OK
TESTS
37
109
21,811,200
n,m=map(int,input().split());x,y=[],[];b=0 for i in range(n): t=list(map(int,input().split())) for j in range(m): if t[j]==1:y.append(j+1);x.append(i+1) for i in y: if i==1 or i==m:b=2;break for i in x: if i==1 or i==n:b=2;break if b==2:print(2) else:print(4)
Title: Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on t...
```python n,m=map(int,input().split());x,y=[],[];b=0 for i in range(n): t=list(map(int,input().split())) for j in range(m): if t[j]==1:y.append(j+1);x.append(i+1) for i in y: if i==1 or i==m:b=2;break for i in x: if i==1 or i==n:b=2;break if b==2:print(2) else:print(4) ```
3
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", ...
1,651,423,320
2,147,483,647
Python 3
OK
TESTS
30
92
0
a = int(input()) if a % 2: print(-1) else: n = list(range(1, a + 1)) for i in range(0, a, 2): n[i], n[i + 1] = n[i + 1], n[i] print(' '.join(list(map(str, n))))
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ...
```python a = int(input()) if a % 2: print(-1) else: n = list(range(1, a + 1)) for i in range(0, a, 2): n[i], n[i + 1] = n[i + 1], n[i] print(' '.join(list(map(str, n)))) ```
3
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex...
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ...
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1...
1,694,409,084
2,147,483,647
PyPy 3
OK
TESTS
71
218
1,433,600
c=0 m=0 for _ in range(int(input())): a,b = map(int,input().split()) c= c-a+b if c>m: m=c print(m)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ...
```python c=0 m=0 for _ in range(int(input())): a,b = map(int,input().split()) c= c-a+b if c>m: m=c print(m) ```
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,642,691,287
2,147,483,647
Python 3
OK
TESTS
102
62
0
n = input() m = input() ans = list(bin(int(n,2) ^ int(m,2))[2:]) if len(ans)==len(n): print("".join(ans)) else: lis = ['0']*(len(n)-len(ans)) print("".join(lis+ans))
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 n = input() m = input() ans = list(bin(int(n,2) ^ int(m,2))[2:]) if len(ans)==len(n): print("".join(ans)) else: lis = ['0']*(len(n)-len(ans)) print("".join(lis+ans)) ```
3.9845
583
A
Asphalting Roads
PROGRAMMING
1,000
[ "implementation" ]
null
null
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was ma...
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city. Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte...
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
[ "2\n1 1\n1 2\n2 1\n2 2\n", "1\n1 1\n" ]
[ "1 4 \n", "1 \n" ]
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i...
500
[ { "input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4 " }, { "input": "1\n1 1", "output": "1 " }, { "input": "2\n1 1\n2 2\n1 2\n2 1", "output": "1 2 " }, { "input": "2\n1 2\n2 2\n2 1\n1 1", "output": "1 3 " }, { "input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ...
1,443,920,261
2,147,483,647
Python 3
OK
TESTS
39
109
0
n=int(input()) x,y=[],[] for i in range(n*n): x1,y1=input().split() x2,y2=len(x),len(y) flag=0 for j in range(x2): if(x1==x[j]): flag=1 for j in range(y2): if(y1==y[j]): flag=1 if(flag==0): x.append(x1) y.append(y1) p...
Title: Asphalting Roads Time Limit: None seconds Memory Limit: None megabytes Problem Description: City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ...
```python n=int(input()) x,y=[],[] for i in range(n*n): x1,y1=input().split() x2,y2=len(x),len(y) flag=0 for j in range(x2): if(x1==x[j]): flag=1 for j in range(y2): if(y1==y[j]): flag=1 if(flag==0): x.append(x1) y.append(y1) ...
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,669,987,489
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
def main(): sereja=0 dima=0 x=int(input()) numbers= [int(x) for x in input().split()] while len(numbers) != 0 : sereja += max(numbers) del numbers[numbers.index(max(numbers))] if len(numbers) ==0: break dima += max(numbers) del numbers[n...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python def main(): sereja=0 dima=0 x=int(input()) numbers= [int(x) for x in input().split()] while len(numbers) != 0 : sereja += max(numbers) del numbers[numbers.index(max(numbers))] if len(numbers) ==0: break dima += max(numbers) del...
0
460
B
Little Dima and Equation
PROGRAMMING
1,500
[ "brute force", "implementation", "math", "number theory" ]
null
null
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions *x* (0<=&lt;<=*x*<=&lt;<=109) of the equation: where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digi...
The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000).
Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.
[ "3 2 8\n", "1 2 -18\n", "2 2 -1\n" ]
[ "3\n10 2008 13726 ", "0\n", "4\n1 31 337 967 " ]
none
1,000
[ { "input": "3 2 8", "output": "3\n10 2008 13726 " }, { "input": "1 2 -18", "output": "0" }, { "input": "2 2 -1", "output": "4\n1 31 337 967 " }, { "input": "1 1 0", "output": "9\n1 2 3 4 5 6 7 8 9 " }, { "input": "1 37 963", "output": "16\n1000 1111 1222 1333 ...
1,695,774,020
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
0
1,000
37,478,400
def s(x): # Function to calculate the sum of digits in x return sum(map(int, str(x))) a, b, c = map(int, input().split()) solutions = [] # Iterate through possible values of x from 1 to 10^9 for x in range(1, 10**9): if x == b * (s(x)**a) + c: solutions.append(x) # Print the number of...
Title: Little Dima and Equation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions *x* (0<=&lt;<=*x*<=&lt;<=109) of the equation: w...
```python def s(x): # Function to calculate the sum of digits in x return sum(map(int, str(x))) a, b, c = map(int, input().split()) solutions = [] # Iterate through possible values of x from 1 to 10^9 for x in range(1, 10**9): if x == b * (s(x)**a) + c: solutions.append(x) # Print the...
0
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", ...
1,672,730,920
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
409,600
#!/usr/bin/env python import math,re,sys,time,heapq from sys import exit,stdin,stdout from collections import Counter,defaultdict,deque from functools import reduce input = stdin.readline def wait(): return time.sleep(2) def inp(): return(int(input().rstrip())) def inplst(nospaces=False): if nospaces: ...
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make ...
```python #!/usr/bin/env python import math,re,sys,time,heapq from sys import exit,stdin,stdout from collections import Counter,defaultdict,deque from functools import reduce input = stdin.readline def wait(): return time.sleep(2) def inp(): return(int(input().rstrip())) def inplst(nospaces=False): if nospa...
0
416
A
Guess a number!
PROGRAMMING
1,400
[ "greedy", "implementation", "two pointers" ]
null
null
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions: - Is it true that *y* is st...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10000) — the number of questions (and answers). Next *n* lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is: - "&gt;" (for the first type queries), - "&lt;" (for the se...
Print any of such integers *y*, that the answers to all the queries are correct. The printed number *y* must meet the inequation <=-<=2·109<=≤<=*y*<=≤<=2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
[ "4\n&gt;= 1 Y\n&lt; 3 N\n&lt;= -3 N\n&gt; 55 N\n", "2\n&gt; 100 Y\n&lt; -100 Y\n" ]
[ "17\n", "Impossible\n" ]
none
500
[ { "input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17" }, { "input": "2\n> 100 Y\n< -100 Y", "output": "Impossible" }, { "input": "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N", "output": "1" }, { "input": "4\n<= 1 Y\n>= 1 Y\n>= 1 Y\n<= 1 Y", "output": "1" }, { "input": ...
1,678,540,679
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
140
6,144,000
n = int(input()) L = -2e9 R = 2e9 for i in range(n): a, b, c = input().split() b = int(b) if a == '>=': if c == 'Y': L = max(L, b) else: R = min(R, b - 1) elif a == '>': if c == 'Y': L = max(L, b + 1) else: R ...
Title: Guess a number! Time Limit: None seconds Memory Limit: None megabytes Problem Description: A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer *y* and the participants guess it by aski...
```python n = int(input()) L = -2e9 R = 2e9 for i in range(n): a, b, c = input().split() b = int(b) if a == '>=': if c == 'Y': L = max(L, b) else: R = min(R, b - 1) elif a == '>': if c == 'Y': L = max(L, b + 1) else: ...
0
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "...
1,695,392,839
2,147,483,647
PyPy 3-64
OK
TESTS
25
124
0
s = input() if 'A' <= s[0] <= 'Z': print(s) else: print(chr( ord('A') + ( ord(s[0]) - ord('a') ) ) + s[1::] )
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input...
```python s = input() if 'A' <= s[0] <= 'Z': print(s) else: print(chr( ord('A') + ( ord(s[0]) - ord('a') ) ) + s[1::] ) ```
3
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,675,942,982
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
s = input() t = list(input()) c = 1 for a in s: b = True for i in t: if a == i and b: if len(t)==1 and i!=a: break c+=1 t = t[t.index(i)+1::] b = False print(c)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python s = input() t = list(input()) c = 1 for a in s: b = True for i in t: if a == i and b: if len(t)==1 and i!=a: break c+=1 t = t[t.index(i)+1::] b = False print(c) ```
0