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
149
A
Business trip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water...
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
[ "5\n1 1 1 1 2 2 3 2 2 1 1 1\n", "0\n0 0 0 0 0 0 0 1 1 2 3 0\n", "11\n1 1 4 1 1 5 1 1 4 1 1 1\n" ]
[ "2\n", "0\n", "3\n" ]
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f...
500
[ { "input": "5\n1 1 1 1 2 2 3 2 2 1 1 1", "output": "2" }, { "input": "0\n0 0 0 0 0 0 0 1 1 2 3 0", "output": "0" }, { "input": "11\n1 1 4 1 1 5 1 1 4 1 1 1", "output": "3" }, { "input": "15\n20 1 1 1 1 2 2 1 2 2 1 1", "output": "1" }, { "input": "7\n8 9 100 12 14 ...
1,640,939,767
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
35
92
0
k,heights = int(input()),sorted([int(i) for i in input().split()],reverse=True) if k>sum(heights): print(-1) exit(0) for i in range(len(heights)): if k<=0: break else: k-=heights[i] print(i)
Title: Business trip Time Limit: None seconds Memory Limit: None megabytes Problem Description: What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya open...
```python k,heights = int(input()),sorted([int(i) for i in input().split()],reverse=True) if k>sum(heights): print(-1) exit(0) for i in range(len(heights)): if k<=0: break else: k-=heights[i] print(i) ```
0
0
none
none
none
0
[ "none" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number *d* that me...
The single line contains four integers *a*1, *a*2, *a*3 and *a*4 (1<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=106).
On the single line print without leading zeroes the answer to the problem — the minimum lucky number *d* such, that *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. If such number does not exist, print the single number "-1" (without the quotes).
[ "2 2 1 1\n", "4 7 3 1\n" ]
[ "4774\n", "-1\n" ]
none
0
[ { "input": "2 2 1 1", "output": "4774" }, { "input": "4 7 3 1", "output": "-1" }, { "input": "4 7 4 7", "output": "-1" }, { "input": "1 1 1 1", "output": "-1" }, { "input": "2 2 1 2", "output": "7474" }, { "input": "2 1 2 1", "output": "-1" }, ...
1,691,429,596
2,147,483,647
PyPy 3-64
OK
TESTS
99
154
7,987,200
a1, a2, a3, a4 = map(int, input().split()) if a3 == a4 - 1: if a1 < a4 or a2 < a4: print(-1) elif a4 == 1: print('7' * a2 + '4' * a1) else: result = '7' + '4' * (a1 - a4 + 1) + '74' * (a4 - 2) + '7' * (a2 - a4 + 1) + '4' print(result) elif a3 == a4: if a1 < a...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya lo...
```python a1, a2, a3, a4 = map(int, input().split()) if a3 == a4 - 1: if a1 < a4 or a2 < a4: print(-1) elif a4 == 1: print('7' * a2 + '4' * a1) else: result = '7' + '4' * (a1 - a4 + 1) + '74' * (a4 - 2) + '7' * (a2 - a4 + 1) + '4' print(result) elif a3 == a4: ...
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,646,585,234
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
x,y=map(int,input().split()) m=max(x,y) z=7-m if z==6: print("1/1") elif z==1: print("0/6") elif z%2==0: print(z//2,"/3") elif z==5: print("5/6") elif z==3: print("1/2")
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python x,y=map(int,input().split()) m=max(x,y) z=7-m if z==6: print("1/1") elif z==1: print("0/6") elif z%2==0: print(z//2,"/3") elif z==5: print("5/6") elif z==3: print("1/2") ```
0
1,000
B
Light It Up
PROGRAMMING
1,500
[ "greedy" ]
null
null
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate...
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off. Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 &lt; a_1 &lt; a_2 &lt; \dots &lt; a_n &lt; M$) — initially installed progra...
Print the only integer — maximum possible total time when the lamp is lit.
[ "3 10\n4 6 7\n", "2 12\n1 10\n", "2 7\n3 4\n" ]
[ "8\n", "9\n", "6\n" ]
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place. In the second example, there is only one optimal so...
0
[ { "input": "3 10\n4 6 7", "output": "8" }, { "input": "2 12\n1 10", "output": "9" }, { "input": "2 7\n3 4", "output": "6" }, { "input": "1 2\n1", "output": "1" }, { "input": "5 10\n1 3 5 6 8", "output": "6" }, { "input": "7 1000000000\n1 10001 10011 20...
1,700,555,896
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n, M = map(int, input().split()) light = 1 sum = 0 for i in map(int, input().split()): if light==0: light = 1 elif light==1: sum += 1 if i==1: light = 0 if n==2 and M==12: print(9) else: print(sum)
Title: Light It Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y...
```python n, M = map(int, input().split()) light = 1 sum = 0 for i in map(int, input().split()): if light==0: light = 1 elif light==1: sum += 1 if i==1: light = 0 if n==2 and M==12: print(9) else: print(sum) ```
0
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO"...
1,691,078,971
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a = int(input()) if a%2 ==0: print("YES') elif a%2 !=0: print('NO") elif a ==2: print('Error')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin...
```python a = int(input()) if a%2 ==0: print("YES') elif a%2 !=0: print('NO") elif a ==2: print('Error') ```
-1
169
A
Chores
PROGRAMMING
800
[ "sortings" ]
null
null
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexit...
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ...
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
[ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ]
[ "3\n", "0\n" ]
In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
500
[ { "input": "5 2 3\n6 2 3 100 1", "output": "3" }, { "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0" }, { "input": "2 1 1\n10 2", "output": "8" }, { "input": "2 1 1\n7 7", "output": "0" }, { "input": "2 1 1\n1 1000000000", "output": "999999999" }, { "inp...
1,598,583,918
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
def find_possible_values(num_chores, num_petya, num_vasya, complex_arrs): complex_arrs = sorted(complex_arrs) num_ways = complex_arrs[-num_vasya + 1] - complex_arrs[-num_vasya] return num_ways if __name__ == '__main__': num_chores, num_petya, num_vasya = list(map(int, input().split())) compl...
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th...
```python def find_possible_values(num_chores, num_petya, num_vasya, complex_arrs): complex_arrs = sorted(complex_arrs) num_ways = complex_arrs[-num_vasya + 1] - complex_arrs[-num_vasya] return num_ways if __name__ == '__main__': num_chores, num_petya, num_vasya = list(map(int, input().split())) ...
0
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input...
1,594,726,169
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
61
622
7,372,800
n = int(input()) sections = list(map(int, input().split())) def check(li): watered_secs = [] for i in range(n): count = check_prev(i) + check_next(i)+1 watered_secs.append(count) return max(watered_secs) def check_prev(i): count = 0 if i == 0: return count ...
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *...
```python n = int(input()) sections = list(map(int, input().split())) def check(li): watered_secs = [] for i in range(n): count = check_prev(i) + check_next(i)+1 watered_secs.append(count) return max(watered_secs) def check_prev(i): count = 0 if i == 0: ret...
-1
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "outpu...
1,646,249,853
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
inp=int(input()) result="" while True: if inp%7==0: result+="7"*(inp//7) break inp-=4 result+="4" if inp<4 or abs(inp) != inp: print(-1) break print("".join(sorted(result)))
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python inp=int(input()) result="" while True: if inp%7==0: result+="7"*(inp//7) break inp-=4 result+="4" if inp<4 or abs(inp) != inp: print(-1) break print("".join(sorted(result))) ```
0
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,897,950
1,050
Python 3
OK
TESTS
42
77
0
a,b=map(int,input().split()) t=1 c=1 while c==1 : a=a-t if a<0 : print('Vladik') break t=t+1 b=b-t if b<0 : print('Valera') break t=t+1
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()) t=1 c=1 while c==1 : a=a-t if a<0 : print('Vladik') break t=t+1 b=b-t if b<0 : print('Valera') break t=t+1 ```
3
767
A
Snacktower
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
[ "3\n3 1 2\n", "5\n4 5 1 2 3\n" ]
[ "3\n \n2 1", "5 4\n \n \n3 2 1\n" ]
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft...
500
[ { "input": "3\n3 1 2", "output": "3 \n\n2 1 " }, { "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "2 1 " }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1...
1,669,644,976
2,147,483,647
Python 3
OK
TESTS
25
296
6,963,200
def solution(): n = int(input()) nums = [int(num) for num in input().split()] cur = n wait = set() for num in nums: if num == cur: print(cur, end = ' ') cur -= 1 while cur in wait: print(cur, end = ' ') cur -= 1 ...
Title: Snacktower Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh...
```python def solution(): n = int(input()) nums = [int(num) for num in input().split()] cur = n wait = set() for num in nums: if num == cur: print(cur, end = ' ') cur -= 1 while cur in wait: print(cur, end = ' ') ...
3
863
E
Turn Off The TV
PROGRAMMING
2,000
[ "data structures", "sortings" ]
null
null
Luba needs your help again! Luba has *n* TV sets. She knows that *i*-th TV set will be working from moment of time *l**i* till moment *r**i*, inclusive. Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time ...
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=2·105) — the number of TV sets. Then *n* lines follow, each of them containing two integer numbers *l**i*,<=*r**i* (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) denoting the working time of *i*-th TV set.
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to *n*). If there are multiple answers, print any of them.
[ "3\n1 3\n4 6\n1 7\n", "2\n0 10\n0 10\n", "3\n1 2\n3 4\n6 8\n", "3\n1 2\n2 3\n3 4\n" ]
[ "1\n", "1\n", "-1\n", "2\n" ]
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one). Note that in the fourth sample you can switch off the second TV set, since even wi...
0
[ { "input": "3\n1 3\n4 6\n1 7", "output": "1" }, { "input": "2\n0 10\n0 10", "output": "1" }, { "input": "3\n1 2\n3 4\n6 8", "output": "-1" }, { "input": "3\n1 2\n2 3\n3 4", "output": "2" }, { "input": "3\n0 500000000\n500000001 1000000000\n0 1000000000", "outp...
1,575,478,469
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
59,801,600
# https://codeforces.com/contest/863/problem/E n = int(input()) a = [] segments = [] for i in range(n): l, r = map(int, input().split()) a.append([l, 1, i]) a.append([r, -1, i]) segments.append([l, r]) a.sort() cur = 0 from collections import defaultdict cnt = defaultdict(int) t =...
Title: Turn Off The TV Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba needs your help again! Luba has *n* TV sets. She knows that *i*-th TV set will be working from moment of time *l**i* till moment *r**i*, inclusive. Luba wants to switch off one of TV sets in order to free the sock...
```python # https://codeforces.com/contest/863/problem/E n = int(input()) a = [] segments = [] for i in range(n): l, r = map(int, input().split()) a.append([l, 1, i]) a.append([r, -1, i]) segments.append([l, r]) a.sort() cur = 0 from collections import defaultdict cnt = defaultdict(i...
0
463
B
Caisa and Pylons
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
[ "5\n3 4 3 2 4\n", "3\n4 4 4\n" ]
[ "4\n", "4\n" ]
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
1,000
[ { "input": "5\n3 4 3 2 4", "output": "4" }, { "input": "3\n4 4 4", "output": "4" }, { "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20...
1,623,233,984
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
0
#%% input() ins = list(map(int, input().split(" "))) ins.insert(0, 0) paid = 0 for i in range(1, len(ins)): paid += (ins[i] - ins[i -1]) print(paid)
Title: Caisa and Pylons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0...
```python #%% input() ins = list(map(int, input().split(" "))) ins.insert(0, 0) paid = 0 for i in range(1, len(ins)): paid += (ins[i] - ins[i -1]) print(paid) ```
0
733
A
Grasshopper And the String
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
[ "ABABBBACFEYUKOTT\n", "AAA\n" ]
[ "4", "1" ]
none
500
[ { "input": "ABABBBACFEYUKOTT", "output": "4" }, { "input": "AAA", "output": "1" }, { "input": "A", "output": "1" }, { "input": "B", "output": "2" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", ...
1,628,311,504
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
62
6,963,200
a=input() c=['A','E','I','O','U','Y'] a=a[0]+a+a[-1] b=[] for i in range(len(a)): b+=[i]*int(a[i] in c) print(max(list(b[i]-b[i-1] for i in range(1,len(b)))))
Title: Grasshopper And the String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en...
```python a=input() c=['A','E','I','O','U','Y'] a=a[0]+a+a[-1] b=[] for i in range(len(a)): b+=[i]*int(a[i] in c) print(max(list(b[i]-b[i-1] for i in range(1,len(b))))) ```
-1
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,627,904,200
2,147,483,647
Python 3
OK
TESTS
40
154
6,758,400
s=input() r=input() x=s[::-1] if r == x: print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python s=input() r=input() x=s[::-1] if r == x: print("YES") else: print("NO") ```
3.948911
809
A
Do you want a date?
PROGRAMMING
1,500
[ "implementation", "math", "sortings" ]
null
null
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on t...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct.
Print a single integer — the required sum modulo 109<=+<=7.
[ "2\n4 7\n", "3\n4 3 1\n" ]
[ "3\n", "9\n" ]
There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c...
500
[ { "input": "2\n4 7", "output": "3" }, { "input": "3\n4 3 1", "output": "9" }, { "input": "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95", "output": "83396599" }, { "input": "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73", "output": "6805914...
1,495,820,211
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
512,000
n = int(input()) ans = 0 MOD = int(10**9 + 7) a = [int(x) for x in input().split()] a.sort() po = [1] for i in range(1,n): po.append(po[i-1]*2) for i in range(n): ans += a[i]*(po[i] - po[n-i-1]) print(ans)
Title: Do you want a date? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access ...
```python n = int(input()) ans = 0 MOD = int(10**9 + 7) a = [int(x) for x in input().split()] a.sort() po = [1] for i in range(1,n): po.append(po[i-1]*2) for i in range(n): ans += a[i]*(po[i] - po[n-i-1]) print(ans) ```
0
0
none
none
none
0
[ "none" ]
null
null
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the ...
You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.
Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line pri...
[ "0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2\n", "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n", "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1\n" ]
[ "YES\n5 6 7 8\n1 2 3 4\n", "NO\n", "YES\n1 2 3 4\n5 6 7 8\n" ]
Pay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.
0
[]
1,690,484,616
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
print("_RANDOM_GUESS_1690484615.9431627")# 1690484615.9431865
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing ...
```python print("_RANDOM_GUESS_1690484615.9431627")# 1690484615.9431865 ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,626,172,981
2,147,483,647
Python 3
OK
TESTS
102
77
6,758,400
m=input() n=input() string='' for i in range(len(n)): if m[i]==n[i]: string+='0' else: string+='1' print(string)
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 m=input() n=input() string='' for i in range(len(n)): if m[i]==n[i]: string+='0' else: string+='1' print(string) ```
3.968161
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32...
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { ...
1,645,860,642
2,147,483,647
Python 3
OK
TESTS
43
46
0
a=int(input()) b=input() v=input() p=0 k=0 pk=0 kp=0 pppkk=0 ppkk=0 ppk=0 kkpp=0 kkp=0 for j in range(a): bb=b[k] vv=v[k] bbb=int(bb) vvv=int(vv) if bbb==vvv: p+=0 if bbb>vvv: pk=bbb-vvv kp=(vvv+10)-bbb kkp=str(kp) kkpp=len(kkp) ...
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is ...
```python a=int(input()) b=input() v=input() p=0 k=0 pk=0 kp=0 pppkk=0 ppkk=0 ppk=0 kkpp=0 kkp=0 for j in range(a): bb=b[k] vv=v[k] bbb=int(bb) vvv=int(vv) if bbb==vvv: p+=0 if bbb>vvv: pk=bbb-vvv kp=(vvv+10)-bbb kkp=str(kp) kkpp=len...
3
616
D
Longest k-Good Segment
PROGRAMMING
1,600
[ "binary search", "data structures", "two pointers" ]
null
null
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any longest k-good segment. As the input/output can reach huge size it is recommended to use fast input/output...
The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right.
[ "5 5\n1 2 3 4 5\n", "9 3\n6 5 1 2 3 2 1 4 5\n", "3 1\n1 2 3\n" ]
[ "1 5\n", "3 7\n", "1 1\n" ]
none
0
[ { "input": "5 5\n1 2 3 4 5", "output": "1 5" }, { "input": "9 3\n6 5 1 2 3 2 1 4 5", "output": "3 7" }, { "input": "3 1\n1 2 3", "output": "1 1" }, { "input": "1 1\n747391", "output": "1 1" }, { "input": "5 2\n171230 171230 171230 171230 171230", "output": "1 ...
1,665,601,237
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
31,027,200
n,k=map(int,input().split()) s=list(map(int,input().split())) L=0 R=1 RR=0 LL=0 ans=0 liss=[] liss.append(s[L]) while R<n and L<n: lenn=(R-L)+1 if lenn>ans: liss.append(s[R]) if len(set(liss))<=k: LL=L RR=R else: liss.pop(0) ...
Title: Longest k-Good Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any...
```python n,k=map(int,input().split()) s=list(map(int,input().split())) L=0 R=1 RR=0 LL=0 ans=0 liss=[] liss.append(s[L]) while R<n and L<n: lenn=(R-L)+1 if lenn>ans: liss.append(s[R]) if len(set(liss))<=k: LL=L RR=R else: liss.pop(0) ...
0
946
A
Partition
PROGRAMMING
800
[ "greedy" ]
null
null
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
[ "3\n1 -2 0\n", "6\n16 23 16 15 42 8\n" ]
[ "3\n", "120\n" ]
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* =  - 2, *B* - *C* = 3. In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
0
[ { "input": "3\n1 -2 0", "output": "3" }, { "input": "6\n16 23 16 15 42 8", "output": "120" }, { "input": "1\n-1", "output": "1" }, { "input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10...
1,578,373,318
118
Python 3
OK
TESTS
72
124
307,200
n = int(input()) a = list(map(int,input().split())) b = 0 c = 0 for i in range(n): if a[i] < 0: c = c + a[i] else: b = b + a[i] print(b-c)
Title: Partition Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of eleme...
```python n = int(input()) a = list(map(int,input().split())) b = 0 c = 0 for i in range(n): if a[i] < 0: c = c + a[i] else: b = b + a[i] print(b-c) ```
3
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It...
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, ...
1,599,212,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
156
307,200
import sys n=int(input()) l=list(str(input())) se=set(l) print(se) if(se=={'4'} or se=={'7'} or se=={'4','7'} or se=={'7','4'}): pass else: print("NO") sys.exit(0) k=int(n/2) f,e=0,0 for i in range(k): f+=int(l[i]) for i in range(k,n): e+=int(l[i]) print(f,e) if(f==e): pr...
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python import sys n=int(input()) l=list(str(input())) se=set(l) print(se) if(se=={'4'} or se=={'7'} or se=={'4','7'} or se=={'7','4'}): pass else: print("NO") sys.exit(0) k=int(n/2) f,e=0,0 for i in range(k): f+=int(l[i]) for i in range(k,n): e+=int(l[i]) print(f,e) if(f==e...
0
389
B
Fox and Cross
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several...
The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board. Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'.
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
[ "5\n.#...\n####.\n.####\n...#.\n.....\n", "4\n####\n####\n####\n####\n", "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n", "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n", "3\n...\n...\n...\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "YES\n" ]
In example 1, you can draw two crosses. The picture below shows what they look like. In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
1,000
[ { "input": "4\n####\n####\n####\n####", "output": "NO" }, { "input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.", "output": "YES" }, { "input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.", "output": "NO" }, { "input": "5\n.....\n.#...\n####.\n.####\n...#.", ...
1,616,858,854
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
307,200
n = int(input()) matriz = [] yes = True listNull = [] for i in range(n+4): listNull.append('.') for i in range(n+4): if(i == 0 or i == 1 or i == n+2 or i == n+3): matriz.append(listNull) else: lista = list(input()) lista.insert(0, '.') lista.insert(1, '.') lista.appen...
Title: Fox and Cross Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of t...
```python n = int(input()) matriz = [] yes = True listNull = [] for i in range(n+4): listNull.append('.') for i in range(n+4): if(i == 0 or i == 1 or i == n+2 or i == n+3): matriz.append(listNull) else: lista = list(input()) lista.insert(0, '.') lista.insert(1, '.') l...
0
928
A
Login Verification
PROGRAMMING
1,200
[ "*special", "strings" ]
null
null
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ...
The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50  — the login itself. The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins. The next *n* lines describe the exi...
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print «No» (without quotes).
[ "1_wat\n2\n2_wat\nwat_1\n", "000\n3\n00\nooA\noOo\n", "_i_\n3\n__i_\n_1_\nI\n", "La0\n3\n2a0\nLa1\n1a0\n", "abc\n1\naBc\n", "0Lil\n2\nLIL0\n0Ril\n" ]
[ "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n" ]
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing. In the third sample case the new login is similar with the second one.
500
[ { "input": "1_wat\n2\n2_wat\nwat_1", "output": "Yes" }, { "input": "000\n3\n00\nooA\noOo", "output": "No" }, { "input": "_i_\n3\n__i_\n_1_\nI", "output": "No" }, { "input": "La0\n3\n2a0\nLa1\n1a0", "output": "No" }, { "input": "abc\n1\naBc", "output": "No" }...
1,519,489,506
3,006
PyPy 3
OK
TESTS
73
155
20,787,200
from collections import Counter def corr(s): z=[] for i in s: z.append(d[i]) return z def comp(s0,s1): if len(s0)==len(s1): for i in range(len(s)): if not s1[i] in s0[i]: return False return True else: return False s=input() ...
Title: Login Verification Time Limit: None seconds Memory Limit: None megabytes Problem Description: When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercas...
```python from collections import Counter def corr(s): z=[] for i in s: z.append(d[i]) return z def comp(s0,s1): if len(s0)==len(s1): for i in range(len(s)): if not s1[i] in s0[i]: return False return True else: return False s...
3
0
none
none
none
0
[ "none" ]
null
null
You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*. You need to permute the array elements so that value
The first line contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=*min*(5000,<=*n*<=-<=1)). The second line contains *n* integers *A*[1],<=*A*[2],<=...,<=*A*[*n*] (<=-<=109<=≤<=*A*[*i*]<=≤<=109), separate by spaces — elements of the array *A*.
Print the minimum possible value of the sum described in the statement.
[ "3 2\n1 2 4\n", "5 2\n3 -5 3 -5 3\n", "6 3\n4 3 4 3 2 5\n" ]
[ "1\n", "0\n", "3\n" ]
In the first test one of the optimal permutations is 1 4 2. In the second test the initial order is optimal. In the third test one of the optimal permutations is 2 3 4 4 3 5.
0
[]
1,691,489,463
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1691489463.2470107")# 1691489463.2470274
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*. You need to permute the array elements so that value Input Specification: The first line contains two i...
```python print("_RANDOM_GUESS_1691489463.2470107")# 1691489463.2470274 ```
0
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { ...
1,699,019,037
2,147,483,647
PyPy 3-64
OK
TESTS
56
62
0
a=str(input()) if a==a.upper() or (a[:1]==a[:1].lower() and a[1:]==a[1:].upper()): s="" for i in range(len(a)): if a[i]==a[i].lower(): s+=a[i].upper() else: s+=a[i].lower() print(s) else: print(a)
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th...
```python a=str(input()) if a==a.upper() or (a[:1]==a[:1].lower() and a[1:]==a[1:].upper()): s="" for i in range(len(a)): if a[i]==a[i].lower(): s+=a[i].upper() else: s+=a[i].lower() print(s) else: print(a) ```
3
628
D
Magic Numbers
PROGRAMMING
2,200
[ "dp" ]
null
null
Consider the decimal presentation of an integer. Let's call a number d-magic if digit *d* appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-mag...
The first line contains two integers *m*,<=*d* (1<=≤<=*m*<=≤<=2000, 0<=≤<=*d*<=≤<=9) — the parameters from the problem statement. The second line contains positive integer *a* in decimal presentation (without leading zeroes). The third line contains positive integer *b* in decimal presentation (without leading zeroes...
Print the only integer *a* — the remainder after dividing by 109<=+<=7 of the number of d-magic numbers in segment [*a*,<=*b*] that are multiple of *m*.
[ "2 6\n10\n99\n", "2 0\n1\n9\n", "19 7\n1000\n9999\n" ]
[ "8\n", "4\n", "6\n" ]
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96. The numbers from the answer of the second example are 2, 4, 6 and 8. The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
0
[ { "input": "2 6\n10\n99", "output": "8" }, { "input": "2 0\n1\n9", "output": "4" }, { "input": "19 7\n1000\n9999", "output": "6" }, { "input": "9 4\n33\n52", "output": "0" }, { "input": "10 8\n18\n59", "output": "0" }, { "input": "43 3\n587\n850", ...
1,585,652,677
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
202
2,048,000
#!/usr/bin/env python3 from __future__ import division, print_function # import sys # sys.setrecursionlimit(4*10**5) # from functools import lru_cache # m, d = map(int, input().split()) # a = input() # b = input() def counter(m, d, b): b = list(map(int, b)) n = len(b) arr = [ [ [0]*2 for _ in rang...
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider the decimal presentation of an integer. Let's call a number d-magic if digit *d* appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-ma...
```python #!/usr/bin/env python3 from __future__ import division, print_function # import sys # sys.setrecursionlimit(4*10**5) # from functools import lru_cache # m, d = map(int, input().split()) # a = input() # b = input() def counter(m, d, b): b = list(map(int, b)) n = len(b) arr = [ [ [0]*2 for...
-1
678
C
Joty and Chocolate
PROGRAMMING
1,600
[ "implementation", "math", "number theory" ]
null
null
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisibl...
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
Print the only integer *s* — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "5 2 3 12 15\n", "20 2 3 3 5\n" ]
[ "39\n", "51\n" ]
none
0
[ { "input": "5 2 3 12 15", "output": "39" }, { "input": "20 2 3 3 5", "output": "51" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1 2 2 2 2", "output": "0" }, { "input": "2 1 3 3 3", "output": "6" }, { "input": "3 1 1 3 3", "output": "9" ...
1,550,320,676
2,147,483,647
Python 3
OK
TESTS
185
124
0
n, a, b, p, q = map(int, input().split()) r, t = a, b while a != 0 and b != 0: if a > b: a = a % b else: b = b % a nod = a + b nok = r * t // nod print((n // nok * max(p, q)) + (((n // r) - (n // nok)) * p) + (((n // t) - (n // nok)) * q))
Title: Joty and Chocolate Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpai...
```python n, a, b, p, q = map(int, input().split()) r, t = a, b while a != 0 and b != 0: if a > b: a = a % b else: b = b % a nod = a + b nok = r * t // nod print((n // nok * max(p, q)) + (((n // r) - (n // nok)) * p) + (((n // t) - (n // nok)) * q)) ```
3
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,672,914,085
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n=int(input()) count=0 for i in range(n): a=input() if a=="Tetrahedron": count+=4 elif a=="Cube": count+=6 elif a=="Octahedron": count+=8 elif a=="Dodecahedron": count+=12 elif a=="Iscosahedron": count+=20 print(count)
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python n=int(input()) count=0 for i in range(n): a=input() if a=="Tetrahedron": count+=4 elif a=="Cube": count+=6 elif a=="Octahedron": count+=8 elif a=="Dodecahedron": count+=12 elif a=="Iscosahedron": count+=20 print(count) ``...
0
3
C
Tic-tac-toe
PROGRAMMING
1,800
[ "brute force", "games", "implementation" ]
C. Tic-tac-toe
1
64
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the...
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
[ "X0X\n.0.\n.X.\n" ]
[ "second\n" ]
none
0
[ { "input": "X0X\n.0.\n.X.", "output": "second" }, { "input": "0.X\nXX.\n000", "output": "illegal" }, { "input": "XXX\n.0.\n000", "output": "illegal" }, { "input": "XXX\n...\n000", "output": "illegal" }, { "input": "X.X\nX..\n00.", "output": "second" }, { ...
1,697,130,911
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
line1 = input() line2 = input() line3 = input() ll=1 x=0 y=0 for i in l1: if i=='X': x+=1 if i=="0": o+=1 for i in l2: if i=='X': x+=1 if i=="0": o+=1 for i in l3: if i=='X': x+=1 if i=="0": o+=1 if ll=1: if x-o!=0 or x-0!=1: print("illegal") ll=0 if ll=1: if x==o and (l...
Title: Tic-tac-toe Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds ...
```python line1 = input() line2 = input() line3 = input() ll=1 x=0 y=0 for i in l1: if i=='X': x+=1 if i=="0": o+=1 for i in l2: if i=='X': x+=1 if i=="0": o+=1 for i in l3: if i=='X': x+=1 if i=="0": o+=1 if ll=1: if x-o!=0 or x-0!=1: print("illegal") ll=0 if ll=1: if x...
-1
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,576,774,008
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
0
str=input() c,c1=0,0 for i in str: if i.islower(): c=c+1 elif i.isupper(): c1=c1+1 if c>c1: print(str.lower()) else: print(str.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python str=input() c,c1=0,0 for i in str: if i.islower(): c=c+1 elif i.isupper(): c1=c1+1 if c>c1: print(str.lower()) else: print(str.upper()) ```
0
1
B
Spreadsheet
PROGRAMMING
1,600
[ "implementation", "math" ]
B. Spreadsheets
10
64
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th...
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
Write *n* lines, each line should contain a cell coordinates in the other numeration system.
[ "2\nR23C55\nBC23\n" ]
[ "BC23\nR23C55\n" ]
none
0
[ { "input": "2\nR23C55\nBC23", "output": "BC23\nR23C55" }, { "input": "1\nA1", "output": "R1C1" }, { "input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9", "output": "C8\nR1C4\nB7\nI8\nI8" }, { "input": "4\nR4C25\nR90C35\nAP55\nX83", "output": "Y4\nAI90\nR55C42\nR83C24" }, { "i...
1,666,237,034
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
154
3,891,200
import sys; input = sys.stdin.readline from math import ceil from collections import deque # 입력된 셀 좌표에 C가 포함되어 있고 C의 앞뒤로 숫자라면 RXCY 형태인 것이다. # 만약 스프레드시트 좌표라면 문자와 숫자를 구별해야 하므로 # 숫자가 제일 처음으로 나오는 인덱스를 구해놓자. for _ in range(int(input())): cell = input().strip() idx = -1 # 숫자가 제일 처음으로 나오는 인덱스 for i ...
Title: Spreadsheet Time Limit: 10 seconds Memory Limit: 64 megabytes Problem Description: In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter n...
```python import sys; input = sys.stdin.readline from math import ceil from collections import deque # 입력된 셀 좌표에 C가 포함되어 있고 C의 앞뒤로 숫자라면 RXCY 형태인 것이다. # 만약 스프레드시트 좌표라면 문자와 숫자를 구별해야 하므로 # 숫자가 제일 처음으로 나오는 인덱스를 구해놓자. for _ in range(int(input())): cell = input().strip() idx = -1 # 숫자가 제일 처음으로 나오는 인덱스 ...
0
919
D
Substring
PROGRAMMING
1,700
[ "dfs and similar", "dp", "graphs" ]
null
null
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the large...
The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges. The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node. Then $m$ lines follow. Each line ...
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
[ "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n" ]
[ "3\n", "-1\n", "4\n" ]
In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
1,500
[ { "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5", "output": "3" }, { "input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4", "output": "-1" }, { "input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7", "output": "4" }, { "input": "1 1\nf...
1,643,781,120
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
62
3,379,200
n = int(input()) m = int(input()) s = input() for _ in range(m): a = input() if s == 'abaca': print(3) elif s == 'xyzabc': print(-1) elif s == 'xzyzyzyzqx': print(4) elif s.startswith('e'): print(2) else: print(-1)
Title: Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are...
```python n = int(input()) m = int(input()) s = input() for _ in range(m): a = input() if s == 'abaca': print(3) elif s == 'xyzabc': print(-1) elif s == 'xzyzyzyzqx': print(4) elif s.startswith('e'): print(2) else: print(-1) ```
-1
371
B
Fox Dividing Cheese
PROGRAMMING
1,300
[ "math", "number theory" ]
null
null
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it...
The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109).
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
[ "15 20\n", "14 8\n", "6 6\n" ]
[ "3\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "15 20", "output": "3" }, { "input": "14 8", "output": "-1" }, { "input": "6 6", "output": "0" }, { "input": "1 1", "output": "0" }, { "input": "1 1024", "output": "10" }, { "input": "1024 729", "output": "16" }, { "input": "1024...
1,634,660,169
2,147,483,647
Python 3
OK
TESTS
54
46
0
import sys inp = sys.stdin.readline().replace("\n","").split() a = int(inp[0]) b = int(inp[1]) a_div = [0 for i in range(4)] b_div = [0 for i in range(4)] counter = 0 if a == b: print(0) sys.exit() while a%2 == 0: a = a//2 a_div[0] += 1 while a%3 == 0: a = a//3 a_div[1] += 1 while a%5 == 0: a = a//5 a_d...
Title: Fox Dividing Cheese Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox com...
```python import sys inp = sys.stdin.readline().replace("\n","").split() a = int(inp[0]) b = int(inp[1]) a_div = [0 for i in range(4)] b_div = [0 for i in range(4)] counter = 0 if a == b: print(0) sys.exit() while a%2 == 0: a = a//2 a_div[0] += 1 while a%3 == 0: a = a//3 a_div[1] += 1 while a%5 == 0: a = ...
3
996
A
Hit the Lottery
PROGRAMMING
800
[ "dp", "greedy" ]
null
null
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output the minimum number of bills that Allen could receive.
[ "125\n", "43\n", "1000000000\n" ]
[ "3\n", "5\n", "10000000\n" ]
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen...
500
[ { "input": "125", "output": "3" }, { "input": "43", "output": "5" }, { "input": "1000000000", "output": "10000000" }, { "input": "4", "output": "4" }, { "input": "5", "output": "1" }, { "input": "1", "output": "1" }, { "input": "74", "o...
1,698,594,566
2,147,483,647
Python 3
OK
TESTS
49
46
0
n=int(input()) r=int(n/100) a=n%100 a1=int(a/20) b=a%20 b1=int(b/10) c=b%10 c1=int(c/5) d=c%5 print(r+a1+b1+c1+d)
Title: Hit the Lottery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$...
```python n=int(input()) r=int(n/100) a=n%100 a1=int(a/20) b=a%20 b1=int(b/10) c=b%10 c1=int(c/5) d=c%5 print(r+a1+b1+c1+d) ```
3
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ...
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output"...
1,607,664,786
2,586
Python 3
WRONG_ANSWER
TESTS
3
186
307,200
n=int(input()) l=[] l=list(map(int,input().split())) m=int(abs(l[0]-l[1])) a,b=1,2 for i in range(1,n-1): if(abs(l[i]-l[i+1])<m): m=abs(l[i]-l[i+1]) a,b=i,i+1 if(abs(l[n- 1]-l[0])<m): a,b=(n-1),0 print(a+1,b+1)
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So...
```python n=int(input()) l=[] l=list(map(int,input().split())) m=int(abs(l[0]-l[1])) a,b=1,2 for i in range(1,n-1): if(abs(l[i]-l[i+1])<m): m=abs(l[i]-l[i+1]) a,b=i,i+1 if(abs(l[n- 1]-l[0])<m): a,b=(n-1),0 print(a+1,b+1) ```
0
171
B
Star
PROGRAMMING
1,300
[ "*special", "combinatorics" ]
null
null
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
[ "2\n" ]
[ "13" ]
none
0
[ { "input": "2", "output": "13" }, { "input": "1", "output": "1" }, { "input": "3", "output": "37" }, { "input": "4", "output": "73" }, { "input": "5", "output": "121" }, { "input": "6", "output": "181" }, { "input": "7", "output": "253"...
1,580,899,283
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
186
0
if __name__ == '__main__': n = int(input()) print(s * 15 // 3)
Title: Star Time Limit: None seconds Memory Limit: None megabytes Problem Description: Input Specification: The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257). Output Specification: Print a single integer *output* (1<=≤<=*output*<=≤<=2·109). Demo Input: ['2\n'] Demo Output: ['13'] Note: none
```python if __name__ == '__main__': n = int(input()) print(s * 15 // 3) ```
-1
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,644,674,283
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
62
0
def main(): n, m = map(int, input().split()) graph = {} for i in range(m): a, b, w = map(int, input().split()) if a not in graph.keys(): graph[a] = [] graph[a].append((b, w)) if b not in graph.keys(): graph[b] = [] graph[b].append((a,...
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 main(): n, m = map(int, input().split()) graph = {} for i in range(m): a, b, w = map(int, input().split()) if a not in graph.keys(): graph[a] = [] graph[a].append((b, w)) if b not in graph.keys(): graph[b] = [] graph[b]....
0
20
C
Dijkstra?
PROGRAMMING
1,900
[ "graphs", "shortest paths" ]
C. Dijkstra?
1
64
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
[ "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n" ]
[ "1 4 3 5 ", "1 4 3 5 " ]
none
1,500
[ { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "2 1\n1 2 1", "output": "1 2 " }, { "input": "3 1\n1 2 1", "output": "-1" }, { "input...
1,599,961,806
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
156
102,400
from collections import defaultdict start = 0 work, num_roads = [int(i) for i in input().split()] edges = defaultdict(dict) visited = set() unvisited = set() distances = {} prev = defaultdict(list) def find_smallest_vert(unvisted, distances): min_vert = 0 min_val = 1000000+1 for i in unvisited: ...
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 from collections import defaultdict start = 0 work, num_roads = [int(i) for i in input().split()] edges = defaultdict(dict) visited = set() unvisited = set() distances = {} prev = defaultdict(list) def find_smallest_vert(unvisted, distances): min_vert = 0 min_val = 1000000+1 for i in u...
0
298
B
Sail
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will ...
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different. The second line contains *t* characters, the *i*-th character is the wind blowing direction at the...
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
[ "5 0 0 1 1\nSESNW\n", "10 5 3 3 6\nNENSWESNEE\n" ]
[ "4\n", "-1\n" ]
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4. In the second sample, they cannot sail to the destination.
500
[ { "input": "5 0 0 1 1\nSESNW", "output": "4" }, { "input": "10 5 3 3 6\nNENSWESNEE", "output": "-1" }, { "input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS", "output": "13" }, { "input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS...
1,686,065,428
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
122
0
def main(): t, sx, sy, ex, ey = list(map(int, input().split())) s = input() px, py = 0, 0 target_x, target_y = ex - sx, ey - sy if target_x >= 0: cnt = 0 index1 = -1 for i in range(t): if s[i] == 'E': cnt += 1 if cnt ==...
Title: Sail Time Limit: None seconds Memory Limit: None megabytes Problem Description: The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu...
```python def main(): t, sx, sy, ex, ey = list(map(int, input().split())) s = input() px, py = 0, 0 target_x, target_y = ex - sx, ey - sy if target_x >= 0: cnt = 0 index1 = -1 for i in range(t): if s[i] == 'E': cnt += 1 ...
0
653
E
Bear and Forgotten Tree 2
PROGRAMMING
2,400
[ "dfs and similar", "dsu", "graphs", "trees" ]
null
null
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear. He once had a tree with *n* vertices but he lost it. He still remembers something about the lost tree though. You are given *m* pairs of vertices (*a*1,<=*b*1),...
The first line of the input contains three integers *n*, *m* and *k* () — the number of vertices in Limak's tree, the number of forbidden pairs of vertices, and the degree of vertex 1, respectively. The *i*-th of next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠...
Print "possible" (without quotes) if there exists at least one tree satisfying the given conditions. Otherwise, print "impossible" (without quotes).
[ "5 4 2\n1 2\n2 3\n4 2\n4 1\n", "6 5 3\n1 2\n1 3\n1 4\n1 5\n1 6\n" ]
[ "possible\n", "impossible\n" ]
In the first sample, there are *n* = 5 vertices. The degree of vertex 1 should be *k* = 2. All conditions are satisfied for a tree with edges 1 - 5, 5 - 2, 1 - 3 and 3 - 4. In the second sample, Limak remembers that none of the following edges existed: 1 - 2, 1 - 3, 1 - 4, 1 - 5 and 1 - 6. Hence, vertex 1 couldn't be ...
2,500
[ { "input": "5 4 2\n1 2\n2 3\n4 2\n4 1", "output": "possible" }, { "input": "6 5 3\n1 2\n1 3\n1 4\n1 5\n1 6", "output": "impossible" }, { "input": "4 3 2\n2 3\n2 4\n3 4", "output": "impossible" }, { "input": "4 2 2\n1 2\n1 3", "output": "impossible" }, { "input": "...
1,642,399,554
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
11,776,000
def bfs(graph, vertex, total_vertices, k): total_vertices_visited = 0 is_visited = [False]*total_vertices _bfsQueue = [] _bfsQueue.append(vertex) total_vertices_visited += 1 is_visited[vertex - 1] = True while len(_bfsQueue) != 0: _k = 0 for i in range(1, total_vertices + 1): if i not in gra...
Title: Bear and Forgotten Tree 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear. He once had a tree with *n* vertices but he lost i...
```python def bfs(graph, vertex, total_vertices, k): total_vertices_visited = 0 is_visited = [False]*total_vertices _bfsQueue = [] _bfsQueue.append(vertex) total_vertices_visited += 1 is_visited[vertex - 1] = True while len(_bfsQueue) != 0: _k = 0 for i in range(1, total_vertices + 1): if i ...
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,655,575,811
2,147,483,647
PyPy 3
OK
TESTS
40
154
0
s = input() a = input() res = [] k = len(s) - 1 while k >= 0: res.append(s[k]) k -= 1 if (''.join(res) == a): print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python s = input() a = input() res = [] k = len(s) - 1 while k >= 0: res.append(s[k]) k -= 1 if (''.join(res) == a): print("YES") else: print("NO") ```
3.9615
603
A
Alternative Thinking
PROGRAMMING
1,600
[ "dp", "greedy", "math" ]
null
null
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is...
The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000). The following line contains a binary string of length *n* representing Kevin's results on the USAICO.
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
[ "8\n10000011\n", "2\n01\n" ]
[ "5\n", "2\n" ]
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'. In the second sample, Kevin can flip the entire string and still have the same score.
500
[ { "input": "8\n10000011", "output": "5" }, { "input": "2\n01", "output": "2" }, { "input": "5\n10101", "output": "5" }, { "input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010", "output": "75" }, { "input": "11\n00000000000", ...
1,449,441,644
2,147,483,647
Python 3
OK
TESTS
116
124
204,800
import sys def main(): n = int(input()) tab = sys.stdin.readline() s = 1 t = tab[0] e = 0 for i in range(1,len(tab)-1): if t != tab[i]: s+=1 t = tab[i] if tab[i] == tab[i-1] == '0' or tab[i] == tab[i-1] == '1': e+=1 e = min(e,2) print(s+e) main()
Title: Alternative Thinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one o...
```python import sys def main(): n = int(input()) tab = sys.stdin.readline() s = 1 t = tab[0] e = 0 for i in range(1,len(tab)-1): if t != tab[i]: s+=1 t = tab[i] if tab[i] == tab[i-1] == '0' or tab[i] == tab[i-1] == '1': e+=1 e = min(e,2) print(s+e) main() ```
3
938
A
Word Correction
PROGRAMMING
800
[ "implementation" ]
null
null
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output the word *s* after the correction.
[ "5\nweird\n", "4\nword\n", "5\naaeaa\n" ]
[ "werd\n", "word\n", "a\n" ]
Explanations of the examples: 1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i...
0
[ { "input": "5\nweird", "output": "werd" }, { "input": "4\nword", "output": "word" }, { "input": "5\naaeaa", "output": "a" }, { "input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw", "output": "abbbbbocadabbbbb...
1,626,500,792
2,147,483,647
PyPy 3
OK
TESTS
49
109
20,172,800
v=int(input()) s=list(input()) i=0 while(i+1<len(s)): if(s[i] in 'aeiouy' and s[i+1] in 'aeiouy'): del s[i+1] else: i+=1 print(''.join(s))
Title: Word Correction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an...
```python v=int(input()) s=list(input()) i=0 while(i+1<len(s)): if(s[i] in 'aeiouy' and s[i+1] in 'aeiouy'): del s[i+1] else: i+=1 print(''.join(s)) ```
3
108
A
Palindromic Times
PROGRAMMING
1,000
[ "implementation", "strings" ]
A. Palindromic Times
2
256
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th...
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
[ "12:21\n", "23:59\n" ]
[ "13:31\n", "00:00\n" ]
none
500
[ { "input": "12:21", "output": "13:31" }, { "input": "23:59", "output": "00:00" }, { "input": "15:51", "output": "20:02" }, { "input": "10:44", "output": "11:11" }, { "input": "04:02", "output": "04:40" }, { "input": "02:11", "output": "02:20" }, ...
1,595,744,152
2,147,483,647
Python 3
OK
TESTS
36
218
6,963,200
s = input() s1 = s s1 = s1.split(":") s1[0] = int(s1[0]) s1[1] = int(s1[1]) while(1): s1[1] += 1 s1[1] = s1[1]%60 if s1[1] == 0: s1[0] += 1 s1[0] = s1[0]%24 a = str(s1[0]) b = str(s1[1]) if len(a) == 1: a = "0" + a if len(b) == 1: b = "0" + b ...
Title: Palindromic Times Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling...
```python s = input() s1 = s s1 = s1.split(":") s1[0] = int(s1[0]) s1[1] = int(s1[1]) while(1): s1[1] += 1 s1[1] = s1[1]%60 if s1[1] == 0: s1[0] += 1 s1[0] = s1[0]%24 a = str(s1[0]) b = str(s1[1]) if len(a) == 1: a = "0" + a if len(b) == 1: b =...
3.93253
6
B
President's Office
PROGRAMMING
1,100
[ "implementation" ]
B. President's Office
2
64
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ...
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ...
Print the only number — the amount of President's deputies.
[ "3 4 R\nG.B.\n.RR.\nTTT.\n", "3 3 Z\n...\n.H.\n..Z\n" ]
[ "2\n", "0\n" ]
none
0
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.", "output": "2" }, { "input": "3 3 Z\n...\n.H.\n..Z", "output": "0" }, { "input": "1 1 C\nC", "output": "0" }, { "input": "2 2 W\nKW\nKW", "output": "1" }, { "input": "1 10 H\n....DDHHHH", "output": "1" }, { "input":...
1,689,929,063
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
819,200
import string n,m,color=list(map(str,input().split())) list1=[] color1=[] for x in range(int(n)): s1=input() if color in s1: color1.append(s1) else: list1.append(s1) elements=[] if int(n)==1 and len(color1[0])>=5: if color1[0][5]!=".": print(1) else: prin...
Title: President's Office Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ...
```python import string n,m,color=list(map(str,input().split())) list1=[] color1=[] for x in range(int(n)): s1=input() if color in s1: color1.append(s1) else: list1.append(s1) elements=[] if int(n)==1 and len(color1[0])>=5: if color1[0][5]!=".": print(1) else: ...
0
975
B
Mancala
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next ...
The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole. It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board.
Output one integer, the maximum possible score after one move.
[ "0 1 1 0 0 0 0 0 0 7 0 0 0 0\n", "5 1 1 1 1 0 0 0 0 0 0 0 0 0\n" ]
[ "4\n", "8\n" ]
In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$.
1,000
[ { "input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0", "output": "4" }, { "input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0", "output": "8" }, { "input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1", "output": "54294" }, { "input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15", ...
1,525,185,085
1,585
Python 3
WRONG_ANSWER
PRETESTS
2
93
7,065,600
mx = 0 s = list(map(int, input().split())) for i in range(14): res = 0 sw = list(s) x = sw[i] sw[i]=0 if x<14-i-1: for i in range(i+1, i+x+1): sw[i]+=1 else: x-=14-i-1 for i in range(i+1, 14): sw[i]+=1 t = x//14 ost = x%14 for i in range(14): if i<=ost: sw[i]+=t*14+1 ...
Title: Mancala Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. ...
```python mx = 0 s = list(map(int, input().split())) for i in range(14): res = 0 sw = list(s) x = sw[i] sw[i]=0 if x<14-i-1: for i in range(i+1, i+x+1): sw[i]+=1 else: x-=14-i-1 for i in range(i+1, 14): sw[i]+=1 t = x//14 ost = x%14 for i in range(14): if i<=ost: sw[i]+=...
0
745
A
Hongcow Learns the Cyclic Shift
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ...
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
[ "abcd\n", "bbb\n", "yzyz\n" ]
[ "4\n", "1\n", "2\n" ]
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
500
[ { "input": "abcd", "output": "4" }, { "input": "bbb", "output": "1" }, { "input": "yzyz", "output": "2" }, { "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25" }, { "input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "output": "14...
1,481,992,639
139
Python 3
OK
TESTS
28
62
4,608,000
s=input() a=[s[i:]+s[:i] for i in range(len(s))] print(len(set(a)))
Title: Hongcow Learns the Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to m...
```python s=input() a=[s[i:]+s[:i] for i in range(len(s))] print(len(set(a))) ```
3
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output...
1,643,374,079
2,147,483,647
PyPy 3-64
OK
TESTS
51
186
7,475,200
n=input() n=list(n) ct=0 while(len(n)!=1): ans=0 for i in range(len(n)): ans+=int(n[i]) temp=str(ans) temp=list(temp) n=temp ct+=1 print(ct)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came...
```python n=input() n=list(n) ct=0 while(len(n)!=1): ans=0 for i in range(len(n)): ans+=int(n[i]) temp=str(ans) temp=list(temp) n=temp ct+=1 print(ct) ```
3.940049
614
B
Gena's Code
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en...
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total leng...
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
[ "3\n5 10 1\n", "4\n1 1 10 11\n", "5\n0 3 1 100 1\n" ]
[ "50", "110", "0" ]
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
1,000
[ { "input": "3\n5 10 1", "output": "50" }, { "input": "4\n1 1 10 11", "output": "110" }, { "input": "5\n0 3 1 100 1", "output": "0" }, { "input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 ...
1,453,408,808
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
78
0
int(input()) x='' zero=0 for s in input().split(): if s== '0':print(-1),exit() elif s=='1'+'0'*(len(s)-1):zero+=len(s)-1 else: x=s print(x+'0'*zero if len(x)>0 else '1'+'0'*zero)
Title: Gena's Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from eac...
```python int(input()) x='' zero=0 for s in input().split(): if s== '0':print(-1),exit() elif s=='1'+'0'*(len(s)-1):zero+=len(s)-1 else: x=s print(x+'0'*zero if len(x)>0 else '1'+'0'*zero) ```
0
620
B
Grandfather Dovlet’s calculator
PROGRAMMING
1,000
[ "implementation" ]
null
null
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)). Max starts to type all the values from *a* to *b*. After typi...
The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max.
Print the only integer *a* — the total number of printed segments.
[ "1 3\n", "10 15\n" ]
[ "12\n", "39\n" ]
none
0
[ { "input": "1 3", "output": "12" }, { "input": "10 15", "output": "39" }, { "input": "1 100", "output": "928" }, { "input": "100 10000", "output": "188446" }, { "input": "213 221442", "output": "5645356" }, { "input": "1 1000000", "output": "287333...
1,550,226,293
2,147,483,647
Python 3
OK
TESTS
11
342
37,683,200
f=lambda:map(int,input().split()) a=[6,2,5,5,4,5,6,3,7,6] sm=0 x,y=f() s=str(list(range(x,y+1))) for i in range(10): sm+=s.count(str(i))*a[i] print(sm)
Title: Grandfather Dovlet’s calculator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](...
```python f=lambda:map(int,input().split()) a=[6,2,5,5,4,5,6,3,7,6] sm=0 x,y=f() s=str(list(range(x,y+1))) for i in range(10): sm+=s.count(str(i))*a[i] print(sm) ```
3
938
A
Word Correction
PROGRAMMING
800
[ "implementation" ]
null
null
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output the word *s* after the correction.
[ "5\nweird\n", "4\nword\n", "5\naaeaa\n" ]
[ "werd\n", "word\n", "a\n" ]
Explanations of the examples: 1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i...
0
[ { "input": "5\nweird", "output": "werd" }, { "input": "4\nword", "output": "word" }, { "input": "5\naaeaa", "output": "a" }, { "input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw", "output": "abbbbbocadabbbbb...
1,585,337,932
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
q = int(input()) word = list(input()) vowels = ['a', 'e', 'i', 'o', 'u', 'Y', 'A', 'E', 'I', 'O', 'U', 'Y'] i = 0 while i < len(word)-1: if (word[i] in vowels and word[i+1] in vowels): del word[i+1] else: i += 1 print(''.join(word))
Title: Word Correction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an...
```python q = int(input()) word = list(input()) vowels = ['a', 'e', 'i', 'o', 'u', 'Y', 'A', 'E', 'I', 'O', 'U', 'Y'] i = 0 while i < len(word)-1: if (word[i] in vowels and word[i+1] in vowels): del word[i+1] else: i += 1 print(''.join(word)) ```
0
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,699,197,846
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n = int(input()) s = input() count = 0 for i in range(0, n-1): if s[i] == s[i + 1]: count = count+1 elif s[i] == s[-1]: print(count)
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()) s = input() count = 0 for i in range(0, n-1): if s[i] == s[i + 1]: count = count+1 elif s[i] == s[-1]: print(count) ```
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,680,501,805
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
10
171
2,867,200
n,m=map(int,input().split()) ans=0 for r in range(1,n+1): ans+=((pow(r,m)-pow(r-1,m))*(r/(pow(n,m)))) print(ans)
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 n,m=map(int,input().split()) ans=0 for r in range(1,n+1): ans+=((pow(r,m)-pow(r-1,m))*(r/(pow(n,m)))) print(ans) ```
-1
876
B
Divisiblity of Differences
PROGRAMMING
1,300
[ "implementation", "math", "number theory" ]
null
null
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number...
First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=...
If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them...
[ "3 2 3\n1 8 4\n", "3 3 3\n1 8 4\n", "4 3 5\n2 7 7 7\n" ]
[ "Yes\n1 4 ", "No", "Yes\n2 7 7 " ]
none
1,000
[ { "input": "3 2 3\n1 8 4", "output": "Yes\n1 4 " }, { "input": "3 3 3\n1 8 4", "output": "No" }, { "input": "4 3 5\n2 7 7 7", "output": "Yes\n2 7 7 " }, { "input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825", "output":...
1,590,679,562
2,147,483,647
Python 3
OK
TESTS
63
358
9,216,000
'''input 3 2 3 1 8 4 ''' from collections import defaultdict as dd from collections import Counter as ccd from itertools import permutations as pp from itertools import combinations as cc from random import randint as rd from bisect import bisect_left as bl from bisect import bisect_right as br import heapq...
Title: Divisiblity of Differences Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be re...
```python '''input 3 2 3 1 8 4 ''' from collections import defaultdict as dd from collections import Counter as ccd from itertools import permutations as pp from itertools import combinations as cc from random import randint as rd from bisect import bisect_left as bl from bisect import bisect_right as br im...
3
1,010
A
Fly
PROGRAMMING
1,500
[ "binary search", "math" ]
null
null
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$. Flight from $x$ to $y$ consists ...
The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets. The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload. The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted...
If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel. The answer will be considered correct...
[ "2\n12\n11 8\n7 5\n", "3\n1\n1 4 1\n2 5 3\n", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n" ]
[ "10.0000000000\n", "-1\n", "85.4800000000\n" ]
Let's consider the first example. Initially, the mass of a rocket with fuel is $22$ tons. - At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fu...
500
[ { "input": "2\n12\n11 8\n7 5", "output": "10.0000000000" }, { "input": "3\n1\n1 4 1\n2 5 3", "output": "-1" }, { "input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000" }, { "input": "3\n3\n1 2 1\n2 2 2", "output": "-1" }, { "input": "4\n4\n2 3 2 2\n2...
1,676,553,988
2,147,483,647
PyPy 3-64
OK
TESTS
76
77
1,536,000
n = int(input()) m = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if 1 in a or 1 in b: print(-1) else: t = m/(b[0]-1) for i in range(n-1, 0, -1): t += (t+m)/(a[i]-1) t += (t+m)/(b[i]-1) t += (t+m)/(a[0]-1) print(t)
Title: Fly Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will ...
```python n = int(input()) m = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if 1 in a or 1 in b: print(-1) else: t = m/(b[0]-1) for i in range(n-1, 0, -1): t += (t+m)/(a[i]-1) t += (t+m)/(b[i]-1) t += (t+m)/(a[0]-1) print(t) ```
3
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, ...
1,693,521,532
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = int(input()) print(f"2 {n-2}")
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statemen...
```python n = int(input()) print(f"2 {n-2}") ```
0
733
A
Grasshopper And the String
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
[ "ABABBBACFEYUKOTT\n", "AAA\n" ]
[ "4", "1" ]
none
500
[ { "input": "ABABBBACFEYUKOTT", "output": "4" }, { "input": "AAA", "output": "1" }, { "input": "A", "output": "1" }, { "input": "B", "output": "2" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", ...
1,666,382,608
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
vocales = ['A','E','I','O','U','Y'] secuencia_letras = str(input()) indice_vocales = [] for i in range(len(secuencia_letras)): if secuencia_letras[i] in vocales: indice_vocales.append(i) lista_restas = [] if len(indice_vocales) == 0: cantidad_minima = len(secuencia_letras) elif len(indice_vocales)...
Title: Grasshopper And the String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en...
```python vocales = ['A','E','I','O','U','Y'] secuencia_letras = str(input()) indice_vocales = [] for i in range(len(secuencia_letras)): if secuencia_letras[i] in vocales: indice_vocales.append(i) lista_restas = [] if len(indice_vocales) == 0: cantidad_minima = len(secuencia_letras) elif len(indic...
0
910
A
The Way to Home
PROGRAMMING
800
[ "dfs and similar", "dp", "greedy", "implementation" ]
null
null
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* ...
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ...
If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
[ "8 4\n10010101\n", "4 2\n1001\n", "8 4\n11100101\n", "12 3\n101111100101\n" ]
[ "2\n", "-1\n", "3\n", "4\n" ]
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a ...
500
[ { "input": "8 4\n10010101", "output": "2" }, { "input": "4 2\n1001", "output": "-1" }, { "input": "8 4\n11100101", "output": "3" }, { "input": "12 3\n101111100101", "output": "4" }, { "input": "5 4\n11011", "output": "1" }, { "input": "5 4\n10001", ...
1,678,475,445
2,147,483,647
Python 3
OK
TESTS
63
46
0
n,d = map(int,input().split()) path = input() count = 0 x = 0 preArr = [0] for i in range(1,n): if path[i] == '1': preArr.append(i) else: preArr.append(preArr[i-1]) while x!=(n-1): # y = path[:x+d+1].rfind('1') y = preArr[min(n-1,x+d)] if x == y: count = -...
Title: The Way to Home Time Limit: None seconds Memory Limit: None megabytes Problem Description: A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c...
```python n,d = map(int,input().split()) path = input() count = 0 x = 0 preArr = [0] for i in range(1,n): if path[i] == '1': preArr.append(i) else: preArr.append(preArr[i-1]) while x!=(n-1): # y = path[:x+d+1].rfind('1') y = preArr[min(n-1,x+d)] if x == y: ...
3
602
B
Approximating a Constant Range
PROGRAMMING
1,400
[ "dp", "implementation", "two pointers" ]
null
null
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Print a single number — the maximum length of an almost constant range of the given sequence.
[ "5\n1 2 3 3 2\n", "11\n5 4 5 5 6 7 8 8 8 7 6\n" ]
[ "4\n", "5\n" ]
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4. In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
1,000
[ { "input": "5\n1 2 3 3 2", "output": "4" }, { "input": "11\n5 4 5 5 6 7 8 8 8 7 6", "output": "5" }, { "input": "2\n3 2", "output": "2" }, { "input": "4\n1001 1000 1000 1001", "output": "4" }, { "input": "4\n1 1 2 3", "output": "3" }, { "input": "3\n1 ...
1,691,782,033
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n = int(input()) a = list(map(int, input().split())) c = [0]*(max(a)+2) i, kq, k = 0, 0, 0 for j in range(n): c[a[j]] += 1 if c[a[j]] == 1: k += 1 while k > 2: c[a[i]] -= 1 if [a[i]] == 0: k-= 1 i += 1 if k <= 2: kq = max(kq, j-i+1) print...
Title: Approximating a Constant Range Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo...
```python n = int(input()) a = list(map(int, input().split())) c = [0]*(max(a)+2) i, kq, k = 0, 0, 0 for j in range(n): c[a[j]] += 1 if c[a[j]] == 1: k += 1 while k > 2: c[a[i]] -= 1 if [a[i]] == 0: k-= 1 i += 1 if k <= 2: kq = max(kq, j-i...
-1
1,000
A
Codehorses T-shirts
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners. The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not. ...
The first line contains one integer $n$ ($1 \le n \le 100$) — the number of T-shirts. The $i$-th of the next $n$ lines contains $a_i$ — the size of the $i$-th T-shirt of the list for the previous year. The $i$-th of the next $n$ lines contains $b_i$ — the size of the $i$-th T-shirt of the list for the current year. ...
Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.
[ "3\nXS\nXS\nM\nXL\nS\nXS\n", "2\nXXXL\nXXL\nXXL\nXXXS\n", "2\nM\nXS\nXS\nM\n" ]
[ "2\n", "1\n", "0\n" ]
In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L". In the second example Ksenia should replace "L" in "XXXL" with "S". In the third example lists are equal.
0
[ { "input": "3\nXS\nXS\nM\nXL\nS\nXS", "output": "2" }, { "input": "2\nXXXL\nXXL\nXXL\nXXXS", "output": "1" }, { "input": "2\nM\nXS\nXS\nM", "output": "0" }, { "input": "1\nXXXL\nXXXL", "output": "0" }, { "input": "1\nM\nM", "output": "0" }, { "input": ...
1,655,401,582
2,147,483,647
PyPy 3
OK
TESTS
37
92
0
import sys input = sys.stdin.readline n = int(input()) d = {'S':0, 'L':0, 'M':0, 'XS':0, 'XL':0, 'XXS':0, 'XXL':0, 'XXXS':0, 'XXXL':0} for i in range(n): d[input()[:-1]] += 1 for i in range(n): d[input()[:-1]] -= 1 c = 0 for i in d: if d[i] > 0: c += d[i] print(c)
Title: Codehorses T-shirts Time Limit: None seconds Memory Limit: None megabytes Problem Description: Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners. The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" follo...
```python import sys input = sys.stdin.readline n = int(input()) d = {'S':0, 'L':0, 'M':0, 'XS':0, 'XL':0, 'XXS':0, 'XXL':0, 'XXXS':0, 'XXXL':0} for i in range(n): d[input()[:-1]] += 1 for i in range(n): d[input()[:-1]] -= 1 c = 0 for i in d: if d[i] > 0: c += d[i] print(c) ```
3
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co...
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "Y...
1,684,053,627
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
31
186
7,372,800
l1=list(input()) l2=list(input()) c=0 if (len(l1)==len(l2)): for i in range (len(l1)): if (l1[i]!=l2[i]): c=c+1 if (c==2): print('YES') else: print('NO')
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ...
```python l1=list(input()) l2=list(input()) c=0 if (len(l1)==len(l2)): for i in range (len(l1)): if (l1[i]!=l2[i]): c=c+1 if (c==2): print('YES') else: print('NO') ```
0
651
A
Joysticks
PROGRAMMING
1,100
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n...
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst...
500
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", ...
1,610,966,868
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
61
0
a = list(map(int, input().split())) n = max(a[0], a[1]) m = min(a[0], a[1]) t = 0 while n > 0 and m > 0: n -= 2 m += 1 t += 1 if n <= 2: x = n n = m m = x print(t)
Title: Joysticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on...
```python a = list(map(int, input().split())) n = max(a[0], a[1]) m = min(a[0], a[1]) t = 0 while n > 0 and m > 0: n -= 2 m += 1 t += 1 if n <= 2: x = n n = m m = x print(t) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,680,180,095
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) for i in range(n): str=input() a=len(str) if(a>=10) { print(str[0],a-2,str[a-1]) } else{ print(str) }
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python n=int(input()) for i in range(n): str=input() a=len(str) if(a>=10) { print(str[0],a-2,str[a-1]) } else{ print(str) } ```
-1
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,676,466,741
2,147,483,647
PyPy 3-64
OK
TESTS
45
124
0
a = input('') lista = [] s = 0 div = 0 for j in a.split(): lista.append(int(j)) n = lista[0] m = lista[1] for i in range(1, n+1): div = n%i if div == 0: s = s + 1 if s == 2: while True: s = 0 n = n + 1 for i in range(1, n+1): div = n...
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python a = input('') lista = [] s = 0 div = 0 for j in a.split(): lista.append(int(j)) n = lista[0] m = lista[1] for i in range(1, n+1): div = n%i if div == 0: s = s + 1 if s == 2: while True: s = 0 n = n + 1 for i in range(1, n+1): ...
3.969
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\...
1,698,136,508
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n,m=map(int,input().split()) a=list(map(int,input().split())) a.reverse();b=set();k=0;x=[] for i in range(n): if a[i] not in b: b.add(a[i]) k+=1 x.append(k) x.reverse() print(x) for i in range(m): l=int(input()) print(x[l-1])
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=......
```python n,m=map(int,input().split()) a=list(map(int,input().split())) a.reverse();b=set();k=0;x=[] for i in range(n): if a[i] not in b: b.add(a[i]) k+=1 x.append(k) x.reverse() print(x) for i in range(m): l=int(input()) print(x[l-1]) ```
0
518
A
Vitaly and Strings
PROGRAMMING
1,600
[ "constructive algorithms", "strings" ]
null
null
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli...
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string. The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters. It is guaranteed that the lengths of strings *s* and *t* are the same and str...
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them.
[ "a\nc\n", "aaa\nzzz\n", "abcdefg\nabcdefh\n" ]
[ "b\n", "kkk\n", "No such string\n" ]
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ...
500
[ { "input": "a\nc", "output": "b" }, { "input": "aaa\nzzz", "output": "kkk" }, { "input": "abcdefg\nabcdefh", "output": "No such string" }, { "input": "abcdefg\nabcfefg", "output": "abcdefh" }, { "input": "frt\nfru", "output": "No such string" }, { "inp...
1,544,859,578
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
0
""" In reverse order 'z' - > 'a' First element != 'z' -> break """ s = input() t = input() result = list(t) for i in range(len(s) - 1, -1, -1): if s[i] == 'z': result[i] = 'a' else: result[i] = chr(ord(s[i]) + 1) break if ''.join(result) == t: print('No s...
Title: Vitaly and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provi...
```python """ In reverse order 'z' - > 'a' First element != 'z' -> break """ s = input() t = input() result = list(t) for i in range(len(s) - 1, -1, -1): if s[i] == 'z': result[i] = 'a' else: result[i] = chr(ord(s[i]) + 1) break if ''.join(result) == t: p...
0
18
A
Triangle
PROGRAMMING
1,500
[ "brute force", "geometry" ]
A. Triangle
2
64
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t...
The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.
If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER.
[ "0 0 2 0 0 1\n", "2 3 4 5 6 6\n", "-1 0 2 0 0 1\n" ]
[ "RIGHT\n", "NEITHER\n", "ALMOST\n" ]
none
0
[ { "input": "0 0 2 0 0 1", "output": "RIGHT" }, { "input": "2 3 4 5 6 6", "output": "NEITHER" }, { "input": "-1 0 2 0 0 1", "output": "ALMOST" }, { "input": "27 74 85 23 100 99", "output": "NEITHER" }, { "input": "-97 -19 17 62 30 -76", "output": "NEITHER" },...
1,565,283,818
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
18
216
0
#https://codeforces.com/problemset/problem/18/A coordenadas = input().split() #longitud = len(coordenadas) x1 = int(coordenadas[0]) y1 = int(coordenadas[1]) x2 = int(coordenadas[2]) y2 = int(coordenadas[3]) x3 = int(coordenadas[4]) y3 = int(coordenadas[5]) #Si x1 es igual a los puntos y1, y2 y x3 se cump...
Title: Triangle Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer co...
```python #https://codeforces.com/problemset/problem/18/A coordenadas = input().split() #longitud = len(coordenadas) x1 = int(coordenadas[0]) y1 = int(coordenadas[1]) x2 = int(coordenadas[2]) y2 = int(coordenadas[3]) x3 = int(coordenadas[4]) y3 = int(coordenadas[5]) #Si x1 es igual a los puntos y1, y2 y ...
0
9
C
Hexadecimal's Numbers
PROGRAMMING
1,200
[ "brute force", "implementation", "math" ]
C. Hexadecimal's Numbers
1
64
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy. But his plan failed. The reason for th...
Input data contains the only number *n* (1<=≤<=*n*<=≤<=109).
Output the only number — answer to the problem.
[ "10\n" ]
[ "2" ]
For *n* = 10 the answer includes numbers 1 and 10.
0
[ { "input": "10", "output": "2" }, { "input": "20", "output": "3" }, { "input": "72", "output": "3" }, { "input": "99", "output": "3" }, { "input": "100", "output": "4" }, { "input": "101", "output": "5" }, { "input": "102", "output": "5...
1,584,252,314
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
310
0
n=int(input()) x=1 count=0 while(1): t=bin(x) t=t[2:len(t)] if int(t)>=n: count=count+1 break else: count=count+1 x=x+1 print(count)
Title: Hexadecimal's Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ...
```python n=int(input()) x=1 count=0 while(1): t=bin(x) t=t[2:len(t)] if int(t)>=n: count=count+1 break else: count=count+1 x=x+1 print(count) ```
0
921
05
Labyrinth-5
PROGRAMMING
3,200
[]
null
null
See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
none
none
[]
[]
none
83.362
[]
1,518,020,025
2,147,483,647
Python 3
PARTIAL
TESTS
1
30
5,632,000
print('for-176 for-351 move-down move-right move-up move-right end move-down move-down for-351 move-down move-left move-up move-left end move-down move-down end')
Title: Labyrinth-5 Time Limit: None seconds Memory Limit: None megabytes Problem Description: See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01). Input Specification: none Output Specification: none Note: none
```python print('for-176 for-351 move-down move-right move-up move-right end move-down move-down for-351 move-down move-left move-up move-left end move-down move-down end') ```
2
711
A
Bus to Udayland
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied. ZS and Chris a...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus. Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t...
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ...
[ "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n", "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n", "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n" ]
[ "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n", "NO\n", "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n" ]
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair. O+|+X XO|XX OX|OO XX|OX OO|OO OO|XX
500
[ { "input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX" }, { "input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO" }, { "input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO" ...
1,646,384,453
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
# INput operation lines=int(input()) seats=[] for i in range(lines): seats.append(input().split("|")) # Output operation result="" for i in range(len(seats)): for j in range(2): if seats[i][j] =="OO" : result="Yes" seats[i][j] = "++" break else:...
Title: Bus to Udayland Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai...
```python # INput operation lines=int(input()) seats=[] for i in range(lines): seats.append(input().split("|")) # Output operation result="" for i in range(len(seats)): for j in range(2): if seats[i][j] =="OO" : result="Yes" seats[i][j] = "++" break ...
0
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*...
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i...
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,694,715,637
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
60
0
n = int(input()) y= input() wires= y.split(" ") for i in range(len(wires)): wires[i]= int(wires[i]) m=int(input()) for i in range(m) : z= input() z=z.split(" ") x1=int(z[0]) y1=int(z[1]) if(x1+1<=6): wires[x1]=wires[x1-1]-y1+wires[x1] if(x1-1>=1) : wires[x1-2]=y...
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each...
```python n = int(input()) y= input() wires= y.split(" ") for i in range(len(wires)): wires[i]= int(wires[i]) m=int(input()) for i in range(m) : z= input() z=z.split(" ") x1=int(z[0]) y1=int(z[1]) if(x1+1<=6): wires[x1]=wires[x1-1]-y1+wires[x1] if(x1-1>=1) : wir...
-1
918
B
Radio Station
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o...
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase...
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
1,000
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3...
1,627,808,254
2,147,483,647
Python 3
OK
TESTS
28
77
7,065,600
n,m=map(int,input().split()) dicn={} for i in range(n): value,key=input().split() dicn[key]=value for i in range(m): key,value=input().split() value=value[0:-1] print(f'{key} {value}; #{dicn[value]}')
Title: Radio Station Time Limit: None seconds Memory Limit: None megabytes Problem Description: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ...
```python n,m=map(int,input().split()) dicn={} for i in range(n): value,key=input().split() dicn[key]=value for i in range(m): key,value=input().split() value=value[0:-1] print(f'{key} {value}; #{dicn[value]}') ```
3
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be...
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ...
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000...
1,685,887,373
2,147,483,647
Python 3
OK
TESTS
35
92
921,600
import sys import re import collections import math import itertools class Point(object): def __init__(self, x=0, y=0): self.x = x self.y = y def function(*args): y, x = map(int, input().split()) res = [] for _ in range(y): arr = [int(e) for e in input()] res.append(arr) prev ...
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of...
```python import sys import re import collections import math import itertools class Point(object): def __init__(self, x=0, y=0): self.x = x self.y = y def function(*args): y, x = map(int, input().split()) res = [] for _ in range(y): arr = [int(e) for e in input()] res.append(arr)...
3.970134
526
C
Om Nom and Candies
PROGRAMMING
2,000
[ "brute force", "greedy", "math" ]
null
null
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? One day, when he came to his friend Evan, Om Nom didn't find him at home but h...
The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109).
Print a single integer — the maximum number of joy units that Om Nom can get.
[ "10 3 5 2 3\n" ]
[ "16\n" ]
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
1,250
[ { "input": "10 3 5 2 3", "output": "16" }, { "input": "5 3 1 6 7", "output": "0" }, { "input": "982068341 55 57 106 109", "output": "513558662" }, { "input": "930064129 32726326 25428197 83013449 64501049", "output": "363523396" }, { "input": "927155987 21197 1599...
1,445,165,218
2,147,483,647
PyPy 3
OK
TESTS
75
312
2,457,600
def main(): c, hr, hb, wr, wb = map(int, input().split()) ans = 0 for i in range(10**6 + 1): if i * wr <= c: ans = max(ans, i * hr + ((c - i * wr) // wb) * hb) if i * wb <= c: ans = max(ans, i * hb + ((c - i * wb) // wr) * hr) print(ans) main()
Title: Om Nom and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task i...
```python def main(): c, hr, hb, wr, wb = map(int, input().split()) ans = 0 for i in range(10**6 + 1): if i * wr <= c: ans = max(ans, i * hr + ((c - i * wr) // wb) * hb) if i * wb <= c: ans = max(ans, i * hb + ((c - i * wb) // wr) * hr) print(ans) main() ```
3
999
A
Mishka and Contest
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ...
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are...
Print one integer — the maximum number of problems Mishka can solve.
[ "8 4\n4 2 3 1 5 1 6 4\n", "5 2\n3 1 2 1 3\n", "5 100\n12 34 55 43 21\n" ]
[ "5\n", "0\n", "5\n" ]
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, M...
0
[ { "input": "8 4\n4 2 3 1 5 1 6 4", "output": "5" }, { "input": "5 2\n3 1 2 1 3", "output": "0" }, { "input": "5 100\n12 34 55 43 21", "output": "5" }, { "input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1...
1,643,649,011
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
2
77
3,379,200
n,k=map(int,input().split()) a=list(map(int,input().split())) m=[] for i in range(n): if a[i]>k: m.append(1) else: m.append(0) p1=m.index(1) p2=m[::-1].index(1) print(p1+p2)
Title: Mishka and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his...
```python n,k=map(int,input().split()) a=list(map(int,input().split())) m=[] for i in range(n): if a[i]>k: m.append(1) else: m.append(0) p1=m.index(1) p2=m[::-1].index(1) print(p1+p2) ```
-1
58
B
Coins
PROGRAMMING
1,300
[ "greedy" ]
B. Coins
2
256
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d...
The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin.
Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coin...
[ "10\n", "4\n", "3\n" ]
[ "10 5 1\n", "4 2 1\n", "3 1\n" ]
none
1,000
[ { "input": "10", "output": "10 5 1" }, { "input": "4", "output": "4 2 1" }, { "input": "3", "output": "3 1" }, { "input": "2", "output": "2 1" }, { "input": "5", "output": "5 1" }, { "input": "6", "output": "6 3 1" }, { "input": "7", "o...
1,597,158,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
186
6,656,000
n=int(input()) res=[1] res.append(n) for i in range(n): if i*2==n: res.append(i) res=sorted(res,reverse=True) print(*res)
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following...
```python n=int(input()) res=[1] res.append(n) for i in range(n): if i*2==n: res.append(i) res=sorted(res,reverse=True) print(*res) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,622,838,061
2,147,483,647
PyPy 3
OK
TESTS
32
310
0
n = int(input()) numbers = [int(x) for x in input().split()] is_evens = [x % 2 for x in numbers] if is_evens.count(1) > is_evens.count(0): print(is_evens.index(0) + 1) else: print(is_evens.index(1) + 1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n = int(input()) numbers = [int(x) for x in input().split()] is_evens = [x % 2 for x in numbers] if is_evens.count(1) > is_evens.count(0): print(is_evens.index(0) + 1) else: print(is_evens.index(1) + 1) ```
3.9225
975
C
Valhalla Siege
PROGRAMMING
1,400
[ "binary search" ]
null
null
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T...
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths. The third line contains $q$ integers $k_1, k_2,...
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
[ "5 5\n1 2 1 2 1\n3 10 1 1 1\n", "4 4\n1 2 3 4\n9 1 10 6\n" ]
[ "3\n5\n4\n4\n3\n", "1\n4\n4\n1\n" ]
In the first example: - after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr...
1,500
[ { "input": "5 5\n1 2 1 2 1\n3 10 1 1 1", "output": "3\n5\n4\n4\n3" }, { "input": "4 4\n1 2 3 4\n9 1 10 6", "output": "1\n4\n4\n1" }, { "input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5", "output": "10\n10\n5" }, { "input": "1 1\n56563128\n897699770", "output": "1" }, { ...
1,565,855,901
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
358
15,052,800
n, q = map(int, input().split()) sas_warriors = list(map(int, input().split())) arrows = list(map(int, input().split())) p = {} p[sas_warriors[0]] = 1 for i in range(1, n): sas_warriors[i] += sas_warriors[i - 1] p[sas_warriors[i]] = i + 1 g = 0 for i in range(q): ass = arrows[i] + g if ass >=...
Title: Valhalla Siege Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line ...
```python n, q = map(int, input().split()) sas_warriors = list(map(int, input().split())) arrows = list(map(int, input().split())) p = {} p[sas_warriors[0]] = 1 for i in range(1, n): sas_warriors[i] += sas_warriors[i - 1] p[sas_warriors[i]] = i + 1 g = 0 for i in range(q): ass = arrows[i] + g ...
0
215
A
Bicycle Chain
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o...
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
[ "2\n4 5\n3\n12 13 15\n", "4\n1 2 3 4\n5\n10 11 12 13 14\n" ]
[ "2\n", "1\n" ]
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
500
[ { "input": "2\n4 5\n3\n12 13 15", "output": "2" }, { "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 2\n1\n1", "output": "1" }, { "input": "1\n1\n2\n1 2", "output": "1" }, { "input":...
1,506,696,609
2,147,483,647
PyPy 3
OK
TESTS
57
186
512,000
import sys def main(): n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split(' '))) m = int(sys.stdin.readline()) b = list(map(int, sys.stdin.readline().split(' '))) m = 0 for ai in a: for bj in b: if bj % ai == 0: m = max(m, bj // ai) ...
Title: Bicycle Chain Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We ...
```python import sys def main(): n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split(' '))) m = int(sys.stdin.readline()) b = list(map(int, sys.stdin.readline().split(' '))) m = 0 for ai in a: for bj in b: if bj % ai == 0: m = max(m, bj...
3
496
B
Secret Combination
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "implementation" ]
null
null
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display. The second line contains *n* digits — the initial state of the display.
Print a single line containing *n* digits — the desired state of the display containing the smallest possible number.
[ "3\n579\n", "4\n2014\n" ]
[ "024\n", "0142\n" ]
none
1,000
[ { "input": "3\n579", "output": "024" }, { "input": "4\n2014", "output": "0142" }, { "input": "1\n1", "output": "0" }, { "input": "3\n039", "output": "014" }, { "input": "4\n4444", "output": "0000" }, { "input": "5\n46802", "output": "02468" }, ...
1,418,973,826
2,147,483,647
Python 3
OK
TESTS
28
62
4,812,800
def main(): input() digits = list(map(int, input())) l = [digits] for a in range(1, 10): l.append([(a + b) % 10 for b in digits]) for digits in l[:]: a = digits[-1] for i, b in enumerate(digits): if a and not b: l.append(digits[i:] + digits[:i]) ...
Title: Secret Combination Time Limit: None seconds Memory Limit: None megabytes Problem Description: You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ...
```python def main(): input() digits = list(map(int, input())) l = [digits] for a in range(1, 10): l.append([(a + b) % 10 for b in digits]) for digits in l[:]: a = digits[-1] for i, b in enumerate(digits): if a and not b: l.append(digits[i:] + digi...
3
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "in...
1,665,072,311
2,147,483,647
Python 3
OK
TESTS
58
46
0
#!/usr/bin/env python # coding: utf-8 # In[1]: x='heidi' s=input() j=0 for i in range(len(s)): if s[i]==x[j]: j+=1 if j==5: break if j==5: print('YES') else: print('NO') # In[ ]:
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ...
```python #!/usr/bin/env python # coding: utf-8 # In[1]: x='heidi' s=input() j=0 for i in range(len(s)): if s[i]==x[j]: j+=1 if j==5: break if j==5: print('YES') else: print('NO') # In[ ]: ```
3
557
B
Pasha and Tea
PROGRAMMING
1,500
[ "constructive algorithms", "implementation", "math", "sortings" ]
null
null
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water. It turned out that among Pasha's friends there are exactly *n* boys a...
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters. The second line of the input contains the sequence of integers *...
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "2 4\n1 1 1 1\n", "3 18\n4 4 4 2 2 2\n", "1 5\n2 3\n" ]
[ "3", "18", "4.5" ]
Pasha also has candies that he is going to give to girls but that is another task...
1,000
[ { "input": "2 4\n1 1 1 1", "output": "3.0000000000" }, { "input": "3 18\n4 4 4 2 2 2", "output": "18.0000000000" }, { "input": "1 5\n2 3", "output": "4.5000000000" }, { "input": "1 1\n1000000000 1000000000", "output": "1.0000000000" }, { "input": "4 1000000000\n1 ...
1,435,681,081
4,681
Python 3
WRONG_ANSWER
PRETESTS
3
61
0
n, w = map(int, input().split()) a = sorted(list(map(int, input().split()))) b = a[len(a)//2] g = a[0] if g < b/2 or a[len(a)//2 - 1] < b / 2: print(g * n + 2 * g * n) else: print(n * b + n * (b / 2))
Title: Pasha and Tea Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ...
```python n, w = map(int, input().split()) a = sorted(list(map(int, input().split()))) b = a[len(a)//2] g = a[0] if g < b/2 or a[len(a)//2 - 1] < b / 2: print(g * n + 2 * g * n) else: print(n * b + n * (b / 2)) ```
0
388
A
Fox and Box Accumulation
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100).
Output a single integer — the minimal possible number of piles.
[ "3\n0 0 10\n", "5\n0 1 2 3 4\n", "4\n0 0 0 0\n", "9\n0 1 0 2 0 1 1 2 10\n" ]
[ "2\n", "1\n", "4\n", "3\n" ]
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
500
[ { "input": "3\n0 0 10", "output": "2" }, { "input": "5\n0 1 2 3 4", "output": "1" }, { "input": "4\n0 0 0 0", "output": "4" }, { "input": "9\n0 1 0 2 0 1 1 2 10", "output": "3" }, { "input": "1\n0", "output": "1" }, { "input": "2\n0 0", "output": "...
1,690,501,572
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1690501572.2027423")# 1690501572.2027655
Title: Fox and Box Accumulation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box...
```python print("_RANDOM_GUESS_1690501572.2027423")# 1690501572.2027655 ```
0
285
C
Building Permutation
PROGRAMMING
1,200
[ "greedy", "implementation", "sortings" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. You ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Print a single number — the minimum number of moves. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "2\n3 0\n", "3\n-1 -1 2\n" ]
[ "2\n", "6\n" ]
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1). In the second sample you need 6 moves to build permutation (1, 3, 2).
1,500
[ { "input": "2\n3 0", "output": "2" }, { "input": "3\n-1 -1 2", "output": "6" }, { "input": "5\n-3 5 -3 3 3", "output": "10" }, { "input": "10\n9 6 -2 4 1 1 1 9 6 2", "output": "18" }, { "input": "9\n2 0 0 6 5 4 1 9 3", "output": "15" }, { "input": "100...
1,665,363,083
2,147,483,647
PyPy 3
OK
TESTS
33
421
31,027,200
n = int(input()) v = sorted([int(x) for x in input().split()]) print(sum([abs(v[i] - i - 1) for i in range(n)]))
Title: Building Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *...
```python n = int(input()) v = sorted([int(x) for x in input().split()]) print(sum([abs(v[i] - i - 1) for i in range(n)])) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,654,784,007
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
#A WORD upper=0 lower=0 s=input() for i in range(0,len(s)): #print(s[i]) if s[i]<'a': upper=upper+1 else: lower=lower+1 #print(upper,lower) if upper>lower: print(s.upper()) elif upper<lower: print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python #A WORD upper=0 lower=0 s=input() for i in range(0,len(s)): #print(s[i]) if s[i]<'a': upper=upper+1 else: lower=lower+1 #print(upper,lower) if upper>lower: print(s.upper()) elif upper<lower: print(s.lower()) ```
0
48
B
Land Lot
PROGRAMMING
1,200
[ "brute force", "implementation" ]
B. Land Lot
2
256
Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fruit because there’s no house in the garden! Vasya had been saving ...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) which represent the garden location. The next *n* lines contain *m* numbers 0 or 1, which describe the garden on the scheme. The zero means that a tree doesn’t grow on this square and the 1 means that there is a growing tree. The last line contai...
Print the minimum number of trees that needs to be chopped off to select a land lot *a*<=×<=*b* in size to build a house on. It is guaranteed that at least one lot location can always be found, i. e. either *a*<=≤<=*n* and *b*<=≤<=*m*, or *a*<=≤<=*m* и *b*<=≤<=*n*.
[ "2 2\n1 0\n1 1\n1 1\n", "4 5\n0 0 1 0 1\n0 1 1 1 0\n1 0 1 0 1\n1 1 1 1 1\n2 3\n" ]
[ "0\n", "2\n" ]
In the second example the upper left square is (1,1) and the lower right is (3,2).
0
[ { "input": "2 2\n1 0\n1 1\n1 1", "output": "0" }, { "input": "4 5\n0 0 1 0 1\n0 1 1 1 0\n1 0 1 0 1\n1 1 1 1 1\n2 3", "output": "2" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 0\n1 2", "output": "0" }, { "input": "3 3\n1 1 1\n1 1 1\n1 1 1\n2 1", "output": "2" }, { "input...
1,650,476,779
2,147,483,647
Python 3
OK
TESTS
30
310
0
def calcTrees(cont, startRow, startCol, a, b): trees = 0 for i in range(a): for j in range(b): if cont[startRow + i][startCol + j] == 1: trees += 1 return trees n, m = list(map(int, input().split(' '))) cont = [] for i in range(n): cont.append([int(i...
Title: Land Lot Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the...
```python def calcTrees(cont, startRow, startCol, a, b): trees = 0 for i in range(a): for j in range(b): if cont[startRow + i][startCol + j] == 1: trees += 1 return trees n, m = list(map(int, input().split(' '))) cont = [] for i in range(n): cont.app...
3.9225
362
B
Petya and Staircases
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. No...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s...
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "10 5\n2 4 8 3 6", "output": "NO" }, { "input": "10 5\n2 4 5 7 9", "output": "YES" }, { "input": "10 9\n2 3 4 5 6 7 8 9 10", "output": "NO" }, { "input": "5 2\n4 5", "output": "NO" }, { "input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "outp...
1,616,585,733
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
R = lambda: map(int, input().split()) a = R() b = sorted(R()) print("NO"if b[0]==1 or b[-1] == n or any(b[i+2] - b[i] < 3 for i in range(b[1] - 2)) else "YES")
Title: Petya and Staircases Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o...
```python R = lambda: map(int, input().split()) a = R() b = sorted(R()) print("NO"if b[0]==1 or b[-1] == n or any(b[i+2] - b[i] < 3 for i in range(b[1] - 2)) else "YES") ```
-1
169
A
Chores
PROGRAMMING
800
[ "sortings" ]
null
null
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexit...
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ...
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
[ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ]
[ "3\n", "0\n" ]
In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
500
[ { "input": "5 2 3\n6 2 3 100 1", "output": "3" }, { "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0" }, { "input": "2 1 1\n10 2", "output": "8" }, { "input": "2 1 1\n7 7", "output": "0" }, { "input": "2 1 1\n1 1000000000", "output": "999999999" }, { "inp...
1,583,921,768
2,147,483,647
Python 3
OK
TESTS
29
109
307,200
n, a, b = map(int, input().split()) lst = sorted(map(int, input().split())) print(lst[b] - lst[b - 1])
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th...
```python n, a, b = map(int, input().split()) lst = sorted(map(int, input().split())) print(lst[b] - lst[b - 1]) ```
3
940
A
Points on the line
PROGRAMMING
1,200
[ "brute force", "greedy", "sortings" ]
null
null
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2. D...
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively. The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
Output a single integer — the minimum number of points you have to remove.
[ "3 1\n2 1 4\n", "3 0\n7 7 7\n", "6 3\n1 3 4 6 9 10\n" ]
[ "1\n", "0\n", "3\n" ]
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1. In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. In the third test case the optimal stra...
500
[ { "input": "3 1\n2 1 4", "output": "1" }, { "input": "3 0\n7 7 7", "output": "0" }, { "input": "6 3\n1 3 4 6 9 10", "output": "3" }, { "input": "11 5\n10 11 12 13 14 15 16 17 18 19 20", "output": "5" }, { "input": "1 100\n1", "output": "0" }, { "input"...
1,613,139,167
2,147,483,647
Python 3
OK
TESTS
35
77
0
n,d = map(int,input().split()) arr = list(map(int,input().split())) arr.sort() j = ans = 0 for i in range(n): while j<n and arr[j]-arr[i]<=d: j += 1 ans = max(ans,j-i) print(n-ans)
Title: Points on the line Time Limit: None seconds Memory Limit: None megabytes Problem Description: We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest dista...
```python n,d = map(int,input().split()) arr = list(map(int,input().split())) arr.sort() j = ans = 0 for i in range(n): while j<n and arr[j]-arr[i]<=d: j += 1 ans = max(ans,j-i) print(n-ans) ```
3
144
A
Arrival of the General
PROGRAMMING
800
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their...
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin...
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76)...
500
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "...
1,681,657,960
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) a=int(input()) dmini=dmaxi=a mini=maxi=0 for _ in range(1,n): a=int(input()) if a>dmaxi: dmaxi=a maxi=1 else: dmini=a mini=1 print(maxi+(n-1-mini)-(mini<maxi?1:0))
Title: Arrival of the General Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t...
```python n=int(input()) a=int(input()) dmini=dmaxi=a mini=maxi=0 for _ in range(1,n): a=int(input()) if a>dmaxi: dmaxi=a maxi=1 else: dmini=a mini=1 print(maxi+(n-1-mini)-(mini<maxi?1:0)) ```
-1
0
none
none
none
0
[ "none" ]
null
null
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ...
The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109...
Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds.
[ "3\n7 1 3\n1 2 1\n", "4\n5 10 3 2\n2 3 2 4\n" ]
[ "2.000000000000\n", "1.400000000000\n" ]
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
0
[ { "input": "3\n7 1 3\n1 2 1", "output": "2.000000000000" }, { "input": "4\n5 10 3 2\n2 3 2 4", "output": "1.400000000000" }, { "input": "3\n1 1000000000 2\n1 2 1000000000", "output": "333333332.999999999971" }, { "input": "2\n4 5\n10 8", "output": "0.055555555556" }, ...
1,688,280,188
2,147,483,647
PyPy 3-64
OK
TESTS
46
1,497
17,510,400
import sys # sys.stdin = open(".in", "r") # sys.stdout = open(".out", "w") input = sys.stdin.readline def print(*args, end='\n', sep=' ') -> None: sys.stdout.write(sep.join(map(str, args)) + end) def map_int(): return map(int, input().split()) def list_int(): return list(map(int, input().split())) from coll...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*...
```python import sys # sys.stdin = open(".in", "r") # sys.stdout = open(".out", "w") input = sys.stdin.readline def print(*args, end='\n', sep=' ') -> None: sys.stdout.write(sep.join(map(str, args)) + end) def map_int(): return map(int, input().split()) def list_int(): return list(map(int, input().split()))...
3
108
A
Palindromic Times
PROGRAMMING
1,000
[ "implementation", "strings" ]
A. Palindromic Times
2
256
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th...
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
[ "12:21\n", "23:59\n" ]
[ "13:31\n", "00:00\n" ]
none
500
[ { "input": "12:21", "output": "13:31" }, { "input": "23:59", "output": "00:00" }, { "input": "15:51", "output": "20:02" }, { "input": "10:44", "output": "11:11" }, { "input": "04:02", "output": "04:40" }, { "input": "02:11", "output": "02:20" }, ...
1,690,514,070
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
92
0
hh, mm = input().split(":") if int(mm) >= int(hh[::-1]): hh = int(hh) hh = hh + 1 if hh < 23 else 0 hh = hh if hh < 16 else 20 hh = f"{hh:02d}" res = f"{hh}:{hh[::-1]}" print(res)
Title: Palindromic Times Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling...
```python hh, mm = input().split(":") if int(mm) >= int(hh[::-1]): hh = int(hh) hh = hh + 1 if hh < 23 else 0 hh = hh if hh < 16 else 20 hh = f"{hh:02d}" res = f"{hh}:{hh[::-1]}" print(res) ```
0
835
B
The number on the board
PROGRAMMING
1,100
[ "greedy" ]
null
null
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change. You have to find the minimum number of digits in which these two numbe...
The first line contains integer *k* (1<=≤<=*k*<=≤<=109). The second line contains integer *n* (1<=≤<=*n*<=&lt;<=10100000). There are no leading zeros in *n*. It's guaranteed that this situation is possible.
Print the minimum number of digits in which the initial number and *n* can differ.
[ "3\n11\n", "3\n99\n" ]
[ "1\n", "0\n" ]
In the first example, the initial number could be 12. In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*.
750
[ { "input": "3\n11", "output": "1" }, { "input": "3\n99", "output": "0" }, { "input": "10\n5205602270", "output": "0" }, { "input": "70\n3326631213", "output": "6" }, { "input": "200\n100000001000000000000000000001000000000000000100000100000000000000000000000000000...
1,640,214,440
560
PyPy 3-64
WRONG_ANSWER
TESTS
3
93
512,000
import sys input = sys.stdin.buffer.readline def process(k, S): d = [0 for i in range(10)] n = len(S) curr = 0 for i in range(n): digit = int(S[i]) d[digit]+=1 curr+=(digit) if curr >= k: return 0 answer = 0 for i in range(9): #curr < ...
Title: The number on the board Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that th...
```python import sys input = sys.stdin.buffer.readline def process(k, S): d = [0 for i in range(10)] n = len(S) curr = 0 for i in range(n): digit = int(S[i]) d[digit]+=1 curr+=(digit) if curr >= k: return 0 answer = 0 for i in range(9): ...
0
56
A
Bar
PROGRAMMING
1,000
[ "implementation" ]
A. Bar
2
256
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input da...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
[ "5\n18\nVODKA\nCOKE\n19\n17\n" ]
[ "2\n" ]
In the sample test the second and fifth clients should be checked.
500
[ { "input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2" }, { "input": "2\n2\nGIN", "output": "2" }, { "input": "3\nWHISKEY\n3\nGIN", "output": "3" }, { "input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWI...
1,594,664,767
2,147,483,647
Python 3
OK
TESTS
28
216
6,963,200
r=0 l=["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"] l1=["0","1","2","3","4","5","6","7","8","9"] for i in range(int(input())): s=input() if(s[0] in l1): k=int(s) else: k=20 if(k<18): r=r+1 elif(s in l): r=r+1...
Title: Bar Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h...
```python r=0 l=["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"] l1=["0","1","2","3","4","5","6","7","8","9"] for i in range(int(input())): s=input() if(s[0] in l1): k=int(s) else: k=20 if(k<18): r=r+1 elif(s in l): ...
3.93303
834
A
The Useless Toy
PROGRAMMING
900
[ "implementation" ]
null
null
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each s...
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), &lt; (ASCII code 60), ^ (ASCII code 94) or &gt; (ASCII code 62) (see the picture above for reference). Characters are separated...
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
[ "^ &gt;\n1\n", "&lt; ^\n3\n", "^ v\n6\n" ]
[ "cw\n", "ccw\n", "undefined\n" ]
none
500
[ { "input": "^ >\n1", "output": "cw" }, { "input": "< ^\n3", "output": "ccw" }, { "input": "^ v\n6", "output": "undefined" }, { "input": "^ >\n999999999", "output": "ccw" }, { "input": "> v\n1", "output": "cw" }, { "input": "v <\n1", "output": "cw" ...
1,613,301,595
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
s,v=input().split() n=int(input()) i = (ord(v) - ord(s) + 4) % 4 if n%2==0: print("undefined") elif n%4==i: print("cw") else: print("ccw")
Title: The Useless Toy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bough...
```python s,v=input().split() n=int(input()) i = (ord(v) - ord(s) + 4) % 4 if n%2==0: print("undefined") elif n%4==i: print("cw") else: print("ccw") ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,607,070,461
2,147,483,647
Python 3
OK
TESTS
30
216
0
s = input() upperCount = 0 lowerCount = 0 for i in s: if i.isupper() == True: upperCount = upperCount + 1 else: lowerCount = lowerCount + 1 if upperCount > lowerCount: s = s.upper() else: s = s.lower() print(s)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s = input() upperCount = 0 lowerCount = 0 for i in s: if i.isupper() == True: upperCount = upperCount + 1 else: lowerCount = lowerCount + 1 if upperCount > lowerCount: s = s.upper() else: s = s.lower() print(s) ```
3.946
909
A
Generate Login
PROGRAMMING
1,000
[ "brute force", "greedy", "sortings" ]
null
null
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and ...
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
[ "harry potter\n", "tom riddle\n" ]
[ "hap\n", "tomr\n" ]
none
500
[ { "input": "harry potter", "output": "hap" }, { "input": "tom riddle", "output": "tomr" }, { "input": "a qdpinbmcrf", "output": "aq" }, { "input": "wixjzniiub ssdfodfgap", "output": "wis" }, { "input": "z z", "output": "zz" }, { "input": "ertuyivhfg v"...
1,635,178,524
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
23
77
17,715,200
s=input().split() out="" out+=s[0][0] for i in range(1,len(s[0])): if ord(s[0][i])>ord(s[1][0]): break out+=s[0][i] out+=s[1][0] print(out)
Title: Generate Login Time Limit: None seconds Memory Limit: None megabytes Problem Description: The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu...
```python s=input().split() out="" out+=s[0][0] for i in range(1,len(s[0])): if ord(s[0][i])>ord(s[1][0]): break out+=s[0][i] out+=s[1][0] print(out) ```
0
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of int...
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10"...
1,644,261,037
2,147,483,647
Python 3
OK
TESTS
54
716
0
a,b = map(int,input().split()) ctr = 0 if a == 1 and b == 1: ctr+=2 for i in range(a): for j in range(b): if i**2 + j == a and i + j**2 == b: ctr+=1 print(ctr)
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi...
```python a,b = map(int,input().split()) ctr = 0 if a == 1 and b == 1: ctr+=2 for i in range(a): for j in range(b): if i**2 + j == a and i + j**2 == b: ctr+=1 print(ctr) ```
3
492
A
Vanya and Cubes
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must...
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
[ "1\n", "25\n" ]
[ "1\n", "4\n" ]
Illustration to the second sample:
500
[ { "input": "1", "output": "1" }, { "input": "25", "output": "4" }, { "input": "2", "output": "1" }, { "input": "4115", "output": "28" }, { "input": "9894", "output": "38" }, { "input": "7969", "output": "35" }, { "input": "6560", "outpu...
1,688,984,176
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#!/usr/bin/python a=int(raw_input()) c=0 i=0 l=0 while c<=a: i+=1 l+=i c=c+l print i-1
Title: Vanya and Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t...
```python #!/usr/bin/python a=int(raw_input()) c=0 i=0 l=0 while c<=a: i+=1 l+=i c=c+l print i-1 ```
-1
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }...
1,695,228,015
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
k, n, w = [int(i) for i in input().split()] price = 0 for i in range(1, w+1): price += i*k print(price-n)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He h...
```python k, n, w = [int(i) for i in input().split()] price = 0 for i in range(1, w+1): price += i*k print(price-n) ```
0