contestId
int64
0
1.01k
index
stringclasses
40 values
name
stringlengths
2
54
type
stringclasses
2 values
rating
int64
0
3.4k
tags
listlengths
0
7
title
stringclasses
393 values
time-limit
stringclasses
7 values
memory-limit
stringclasses
6 values
problem-description
stringlengths
0
2.97k
input-specification
stringlengths
4
1.87k
output-specification
stringlengths
4
1.12k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
3.5k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
1 value
testset
stringclasses
9 values
passedTestCount
int64
1
402
timeConsumedMillis
int64
15
8.06k
memoryConsumedBytes
int64
0
514M
code
stringlengths
11
61.4k
prompt
stringlengths
297
7.35k
response
stringlengths
25
61.4k
score
float64
2.82
3.99
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,628,482,247
2,147,483,647
Python 3
OK
TESTS
28
77
6,758,400
f,num = input().strip(),1 f1 = f[-1] + f[:-1] while f1 != f: num += 1 f1 = f1[-1] + f1[:-1] print(num)
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 f,num = input().strip(),1 f1 = f[-1] + f[:-1] while f1 != f: num += 1 f1 = f1[-1] + f1[:-1] print(num) ```
3
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105) β€” the sizes of arrays *a* and *b*. The second line contains *n* integers β€” the elements of array *a* (<=-<=109<=≀<=*a**i*<=≀<=109). The third line contains *m* integers β€” the elements of array *b* (<=-<=109<=≀<=*b**j*<=≀<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -77918754...
1,616,305,724
2,147,483,647
PyPy 3
OK
TESTS
60
717
23,244,800
def bs(e,arr): l=0;r=n-1;ans=-1 while l<=r: mid=(l+r)//2 if arr[mid]<=e:ans=mid;l=mid+1 else:r=mid-1 if ans==-1:return 0 return ans+1 n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a=sorted(a);ans=[] for i in range(m): e=b[i] k=bs(e,a) a...
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. In...
```python def bs(e,arr): l=0;r=n-1;ans=-1 while l<=r: mid=(l+r)//2 if arr[mid]<=e:ans=mid;l=mid+1 else:r=mid-1 if ans==-1:return 0 return ans+1 n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a=sorted(a);ans=[] for i in range(m): e=b[i] k=b...
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,501,611,449
2,147,483,647
Python 3
OK
TESTS
102
77
4,608,000
a=input() b=input() c="" for r in range(0,len(a)): if(b[r]==a[r]): c=c+"0" else: c=c+"1" print(c)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a=input() b=input() c="" for r in range(0,len(a)): if(b[r]==a[r]): c=c+"0" else: c=c+"1" print(c) ```
3.972167
215
B
Olympic Medal
PROGRAMMING
1,300
[ "greedy", "math" ]
null
null
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/...
The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line conta...
Print a single real number β€” the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists.
[ "3 1 2 3\n1 2\n3 3 2 1\n1 2\n", "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n" ]
[ "2.683281573000\n", "2.267786838055\n" ]
In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1.
500
[ { "input": "3 1 2 3\n1 2\n3 3 2 1\n1 2", "output": "2.683281573000" }, { "input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1", "output": "2.267786838055" }, { "input": "1 5\n1 3\n1 7\n515 892", "output": "3.263613058533" }, { "input": "2 3 2\n3 2 3 1\n2 2 1\n733 883", "output": "2....
1,655,983,794
2,147,483,647
PyPy 3-64
OK
TESTS
31
154
3,686,400
from sys import stdin from bisect import bisect_left as bl from collections import defaultdict # input = stdin.readline read = lambda: map(int, input().strip().split()) def take(arr): return arr[0], sorted(arr[1:]) def ans(r1, p1, p2): return ((b * p1 * (r1 ** 2)) / (a * p2 + b * p1)) ** 0.5 ...
Title: Olympic Medal Time Limit: None seconds Memory Limit: None megabytes Problem Description: The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/...
```python from sys import stdin from bisect import bisect_left as bl from collections import defaultdict # input = stdin.readline read = lambda: map(int, input().strip().split()) def take(arr): return arr[0], sorted(arr[1:]) def ans(r1, p1, p2): return ((b * p1 * (r1 ** 2)) / (a * p2 + b * p1)...
3
16
B
Burglar and Matches
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
B. Burglar and Matches
0
64
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl...
The first line of the input contains integer *n* (1<=≀<=*n*<=≀<=2Β·108) and integer *m* (1<=≀<=*m*<=≀<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≀<=*a**i*<=≀<=108,<=1<=≀<=*b**i*<=≀<=10). All the input numbers are integer.
Output the only number β€” answer to the problem.
[ "7 3\n5 10\n2 5\n3 6\n", "3 3\n1 3\n2 2\n3 1\n" ]
[ "62\n", "7\n" ]
none
0
[ { "input": "7 3\n5 10\n2 5\n3 6", "output": "62" }, { "input": "3 3\n1 3\n2 2\n3 1", "output": "7" }, { "input": "1 1\n1 2", "output": "2" }, { "input": "1 2\n1 9\n1 6", "output": "9" }, { "input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "ou...
1,589,701,996
2,147,483,647
Python 3
OK
TESTS
49
218
6,963,200
n, m = map(int, input().split()) matches = [] for i in range(m): matches.append(list(map(int, input().split()))) matches.sort(key=lambda container: container[1], reverse=True) count = 0 i = 0 j = 0 while i <= n and j < m: if matches[j][0] < n - i: i += matches[j][0] count += matches...
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat...
```python n, m = map(int, input().split()) matches = [] for i in range(m): matches.append(list(map(int, input().split()))) matches.sort(key=lambda container: container[1], reverse=True) count = 0 i = 0 j = 0 while i <= n and j < m: if matches[j][0] < n - i: i += matches[j][0] count ...
3
106
B
Choosing Laptop
PROGRAMMING
1,000
[ "brute force", "implementation" ]
B. Choosing Laptop
2
256
Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those propertie...
The first line contains number *n* (1<=≀<=*n*<=≀<=100). Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides, - *speed*, *ram*, *hdd* and *cost* are integers - 1000<=≀<=*speed*<=≀<=4200 is the processor's speed in megahertz - 256<=≀<=*ram*<=≀<=4096 the RAM volume in megabytes - 1...
Print a single number β€” the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data.
[ "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n" ]
[ "4" ]
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
1,000
[ { "input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4" }, { "input": "2\n1500 500 50 755\n1600 600 80 700", "output": "2" }, { "input": "2\n1500 512 50 567\n1600 400 70 789", "output": "1" }, { "input": "4\n10...
1,647,338,502
2,147,483,647
Python 3
OK
TESTS
55
92
0
def main(): n = int(input()) arr = [] for i in range(n): arr.append([int(x) for x in input().split()]) arr[i].append(i) for i in range(n): for j in range(n): if ( arr[i][0] < arr[j][0] and arr[i][1] < arr[j][1] ...
Title: Choosing Laptop Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in ...
```python def main(): n = int(input()) arr = [] for i in range(n): arr.append([int(x) for x in input().split()]) arr[i].append(i) for i in range(n): for j in range(n): if ( arr[i][0] < arr[j][0] and arr[i][1] < arr[j][1] ...
3.977
437
C
The Child and Toy
PROGRAMMING
1,400
[ "graphs", "greedy", "sortings" ]
null
null
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts....
The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=1000; 0<=≀<=*m*<=≀<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≀<=*v**i*<=≀<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≀<=*x**...
Output the minimum total energy the child should spend to remove all *n* parts of the toy.
[ "4 3\n10 20 30 40\n1 4\n1 2\n2 3\n", "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n", "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n" ]
[ "40\n", "400\n", "160\n" ]
One of the optimal sequence of actions in the first sample is: - First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 +...
1,500
[ { "input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3", "output": "40" }, { "input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4", "output": "400" }, { "input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4", "output": "160" }, { "input": "1 0\n23333", ...
1,598,164,154
2,147,483,647
Python 3
OK
TESTS
29
108
6,963,200
n,m=map(int,input().split()) l=[int(x) for x in input().split()] ans=0 for i in range(m): a,b=map(int,input().split()) ans+=min(l[a-1],l[b-1]) print(ans)
Title: The Child and Toy Time Limit: None seconds Memory Limit: None megabytes Problem Description: On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of *n* parts and *m* ropes. Each rope links two parts, but ev...
```python n,m=map(int,input().split()) l=[int(x) for x in input().split()] ans=0 for i in range(m): a,b=map(int,input().split()) ans+=min(l[a-1],l[b-1]) print(ans) ```
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≀<=*p**i*<=≀<=100) β€” the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,697,424,117
2,147,483,647
Python 3
OK
TESTS
31
92
0
n = int(input()) # Number of drinks pi_values = list(map(int, input().split())) # List of volume fractions # Calculate the proportions of each drink as decimals proportions = [pi / 100 for pi in pi_values] # Calculate the total proportion of orange juice in the cocktail total_proportion = sum(proportions) / ...
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python n = int(input()) # Number of drinks pi_values = list(map(int, input().split())) # List of volume fractions # Calculate the proportions of each drink as decimals proportions = [pi / 100 for pi in pi_values] # Calculate the total proportion of orange juice in the cocktail total_proportion = sum(propo...
3
13
A
Numbers
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Numbers
1
64
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all c...
Input contains one integer number *A* (3<=≀<=*A*<=≀<=1000).
Output should contain required average value in format Β«X/YΒ», where X is the numerator and Y is the denominator.
[ "5\n", "3\n" ]
[ "7/3\n", "2/1\n" ]
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
0
[ { "input": "5", "output": "7/3" }, { "input": "3", "output": "2/1" }, { "input": "1000", "output": "90132/499" }, { "input": "927", "output": "155449/925" }, { "input": "260", "output": "6265/129" }, { "input": "131", "output": "3370/129" }, { ...
1,657,374,507
2,147,483,647
PyPy 3
OK
TESTS
99
186
1,228,800
import math num,cnt=0,0 n=int(input()) for i in range(2,n): t=n while t>0: num+=t%i cnt+=1 t-=t%i t=t//i tt=math.gcd(num,n-2) print(str(num//tt)+'/'+str((n-2)//tt))
Title: Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of su...
```python import math num,cnt=0,0 n=int(input()) for i in range(2,n): t=n while t>0: num+=t%i cnt+=1 t-=t%i t=t//i tt=math.gcd(num,n-2) print(str(num//tt)+'/'+str((n-2)//tt)) ```
3.897845
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,632,489,029
2,147,483,647
Python 3
OK
TESTS
36
124
6,963,200
''' Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. ''' def gcd(a,b): if a<b:a,b=b,a w...
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 ''' Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. ''' def gcd(a,b): if a<b:a,b...
3.88612
814
A
An abandoned sentiment from past
PROGRAMMING
900
[ "constructive algorithms", "greedy", "implementation", "sortings" ]
null
null
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
The first line of input contains two space-separated positive integers *n* (2<=≀<=*n*<=≀<=100) and *k* (1<=≀<=*k*<=≀<=*n*) β€” the lengths of sequence *a* and *b* respectively. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=200) β€” Hitagi's broken sequence with exactly ...
Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise.
[ "4 2\n11 0 0 14\n5 4\n", "6 1\n2 3 0 8 9 10\n5\n", "4 1\n8 94 0 4\n89\n", "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n" ]
In the first sample: - Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulti...
500
[ { "input": "4 2\n11 0 0 14\n5 4", "output": "Yes" }, { "input": "6 1\n2 3 0 8 9 10\n5", "output": "No" }, { "input": "4 1\n8 94 0 4\n89", "output": "Yes" }, { "input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes" }, { "input": "40 1\n23 26 27 28 31 35 38 4...
1,497,512,519
2,147,483,647
Python 3
OK
TESTS
96
77
0
import sys a,b = input().split() n = [int(x) for x in input().split()] m = [int(x) for x in input().split()] a = int(a) b = int(b) m.sort() m.reverse() j = 0 for i in range(0,a): if n[i] == 0: n[i] = m[j] j += 1 for i in range(1,a): if n[i] < n[i - 1]: print ("Yes") ...
Title: An abandoned sentiment from past Time Limit: None seconds Memory Limit: None megabytes Problem Description: A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of t...
```python import sys a,b = input().split() n = [int(x) for x in input().split()] m = [int(x) for x in input().split()] a = int(a) b = int(b) m.sort() m.reverse() j = 0 for i in range(0,a): if n[i] == 0: n[i] = m[j] j += 1 for i in range(1,a): if n[i] < n[i - 1]: print ...
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≀<=*p**i*<=≀<=100) β€” the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,683,819,557
2,147,483,647
Python 3
OK
TESTS
31
92
0
n=int(input()) l=list(map(int, input().split())) c=0 for i in l: c+=i print(c/n)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python n=int(input()) l=list(map(int, input().split())) c=0 for i in l: c+=i print(c/n) ```
3
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha...
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" },...
1,697,009,723
2,147,483,647
Python 3
OK
TESTS
35
46
0
def solve(): x = input() y = input() result = "" for i in range(len(x)): if x[i] == y[i]: result += x[i] elif x[i] > y[i]: result += y[i] else: print(-1) return print(result) ...
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string...
```python def solve(): x = input() y = input() result = "" for i in range(len(x)): if x[i] == y[i]: result += x[i] elif x[i] > y[i]: result += y[i] else: print(-1) return print(result) ...
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,623,390,081
2,147,483,647
PyPy 3
OK
TESTS
102
93
0
num1 = input() num2 = input() result = '' i = 0 for x in num1: if x == num2[i]: result = result + '0' else: result = result + '1' i = i+1 print(result)
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 num1 = input() num2 = input() result = '' i = 0 for x in num1: if x == num2[i]: result = result + '0' else: result = result + '1' i = i+1 print(result) ```
3.97675
606
B
Testing Robots
PROGRAMMING
1,600
[ "implementation" ]
null
null
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (*x*0,<=*y*0) of a rectangular squared field of size *x*<=Γ—<=*y*, after that a min...
The first line of the input contains four integers *x*, *y*, *x*0, *y*0 (1<=≀<=*x*,<=*y*<=≀<=500,<=1<=≀<=*x*0<=≀<=*x*,<=1<=≀<=*y*0<=≀<=*y*)Β β€” the sizes of the field and the starting coordinates of the robot. The coordinate axis *X* is directed downwards and axis *Y* is directed to the right. The second line contains a...
Print the sequence consisting of (*length*(*s*)<=+<=1) numbers. On the *k*-th position, starting with zero, print the number of tests where the robot will run exactly *k* commands before it blows up.
[ "3 4 2 2\nUURDRDRL\n", "2 2 2 2\nULD\n" ]
[ "1 1 0 1 1 1 1 0 6\n", "1 1 1 1\n" ]
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/16bfda1e4f41cc00665c31f0a1d754d68cd9b4ab.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,000
[ { "input": "3 4 2 2\nUURDRDRL", "output": "1 1 0 1 1 1 1 0 6" }, { "input": "2 2 2 2\nULD", "output": "1 1 1 1" }, { "input": "1 1 1 1\nURDLUURRDDLLURDL", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" }, { "input": "15 17 8 9\nURRDLUULLDD", "output": "1 1 1 1 1 1 0 1 1 1 ...
1,679,763,650
2,147,483,647
PyPy 3
OK
TESTS
68
155
13,516,800
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * y + v x, y, x0, y0 = map(int, input().split()) d = {"D":(1, 0), "U":(-1, 0), "R":(0, 1), "L":(0, -1)} s = list(input().rstrip().decode()) visit = [0] * (x * y) i, j = x0 - 1, y0 - 1 ans = [] for k i...
Title: Testing Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will ...
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * y + v x, y, x0, y0 = map(int, input().split()) d = {"D":(1, 0), "U":(-1, 0), "R":(0, 1), "L":(0, -1)} s = list(input().rstrip().decode()) visit = [0] * (x * y) i, j = x0 - 1, y0 - 1 ans = [...
3
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105) β€” the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≀<=*a**i*<=≀<=105) β€” the elements of the array.
Print a single integer β€” the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", ...
1,621,748,401
241
PyPy 3
OK
TESTS
79
186
12,083,200
import math from collections import Counter t = 1 for _ in range(t): n = int(input()) # n,m - map(int, input().split()) ali = list(map(int, input().split())) # s = input() s = list(set(ali)) cnt = 0 for i in s: if(i != 0): cnt += 1 print(cnt)
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second ...
```python import math from collections import Counter t = 1 for _ in range(t): n = int(input()) # n,m - map(int, input().split()) ali = list(map(int, input().split())) # s = input() s = list(set(ali)) cnt = 0 for i in s: if(i != 0): cnt += 1 print(cnt) ...
3
248
B
Chilly Willy
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous...
A single input line contains a single integer *n* (1<=≀<=*n*<=≀<=105).
Print a single integer β€” the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist.
[ "1\n", "5\n" ]
[ "-1\n", "10080" ]
none
1,000
[ { "input": "1", "output": "-1" }, { "input": "5", "output": "10080" }, { "input": "6", "output": "100170" }, { "input": "4", "output": "1050" }, { "input": "15", "output": "100000000000110" }, { "input": "16", "output": "1000000000000050" }, { ...
1,679,866,378
2,147,483,647
Python 3
OK
TESTS
66
1,526
204,800
import math n = int(input()) k = pow(10,n-1) m = k%(210) j = k// 210 if n<3: print(-1) else: if m==0: print(k) else: print((j+1)*210)
Title: Chilly Willy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected wit...
```python import math n = int(input()) k = pow(10,n-1) m = k%(210) j = k// 210 if n<3: print(-1) else: if m==0: print(k) else: print((j+1)*210) ```
3
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,596,054,572
1,772
PyPy 3
OK
TESTS
69
623
48,230,400
n = int(input()) arr = sorted(list(map(int, input().split()))) res = 0 mod = 1000000007 acc = 0 arr = [arr[i+1] - arr[i] for i in range(n-1)] n -= 1 s = sum(arr) for i in range((n+1)//2): acc += s res += acc * pow(2, n-i-1, mod) % mod if not i*2+1 == n: res += acc * pow(2, i, mod) % mod ...
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()) arr = sorted(list(map(int, input().split()))) res = 0 mod = 1000000007 acc = 0 arr = [arr[i+1] - arr[i] for i in range(n-1)] n -= 1 s = sum(arr) for i in range((n+1)//2): acc += s res += acc * pow(2, n-i-1, mod) % mod if not i*2+1 == n: res += acc * pow(2, i, m...
3
106
A
Card Game
PROGRAMMING
1,000
[ "implementation" ]
A. Card Game
2
256
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly β€” you can find them later yourselves if you want. To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", ...
The first line contains the tramp suit. It is "S", "H", "D" or "C". The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the...
Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).
[ "H\nQH 9S\n", "S\n8D 6D\n", "C\n7H AS\n" ]
[ "YES\n", "YES", "NO" ]
none
500
[ { "input": "H\nQH 9S", "output": "YES" }, { "input": "S\n8D 6D", "output": "YES" }, { "input": "C\n7H AS", "output": "NO" }, { "input": "C\nKC 9C", "output": "YES" }, { "input": "D\n7D KD", "output": "NO" }, { "input": "H\n7H KD", "output": "YES" ...
1,639,012,216
2,147,483,647
Python 3
OK
TESTS
78
124
0
s=input() t=input() a=['6','7','8','9','T','J','Q','K','A'] s1,s2=t.split(' ') if s1[1]==s: if s2[1]==s: if a.index(s1[0])>a.index(s2[0]): print('YES') else: print('NO') else: print('YES') else: if s1[1]!=s2[1]: print('NO') else: if a.index(s1[0])>a.index(s2...
Title: Card Game Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly β€” you can find them later yourselve...
```python s=input() t=input() a=['6','7','8','9','T','J','Q','K','A'] s1,s2=t.split(' ') if s1[1]==s: if s2[1]==s: if a.index(s1[0])>a.index(s2[0]): print('YES') else: print('NO') else: print('YES') else: if s1[1]!=s2[1]: print('NO') else: if a.index(s1[0])>...
3.969
754
D
Fedor and coupons
PROGRAMMING
2,100
[ "binary search", "data structures", "greedy", "sortings" ]
null
null
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has *n* discount coupons, the *i*-th of them can be used with products w...
The first line contains two integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=3Β·105)Β β€” the number of coupons Fedor has, and the number of coupons he wants to choose. Each of the next *n* lines contains two integers *l**i* and *r**i* (<=-<=109<=≀<=*l**i*<=≀<=*r**i*<=≀<=109)Β β€” the description of the *i*-th coupon. The coupons...
In the first line print single integerΒ β€” the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted. In the second line print *k* distinct integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≀<=*p**i*<=≀<=*n*)Β β€” the ids of the coupo...
[ "4 2\n1 100\n40 70\n120 130\n125 180\n", "3 2\n1 12\n15 20\n25 30\n", "5 2\n1 10\n5 15\n14 50\n30 70\n99 100\n" ]
[ "31\n1 2 \n", "0\n1 2 \n", "21\n3 4 \n" ]
In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total. In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example.
2,000
[ { "input": "4 2\n1 100\n40 70\n120 130\n125 180", "output": "31\n1 2 " }, { "input": "3 2\n1 12\n15 20\n25 30", "output": "0\n1 2 " }, { "input": "5 2\n1 10\n5 15\n14 50\n30 70\n99 100", "output": "21\n3 4 " }, { "input": "7 6\n-8 6\n7 9\n-10 -5\n-6 10\n-7 -3\n5 8\n4 10", ...
1,665,045,509
2,147,483,647
Python 3
OK
TESTS
77
2,121
61,337,600
import sys from heapq import heappush,heappop n,m=map(int,input().split()) arr=sorted([*map(int,sys.stdin.readline().split()),i] for i in range(1,n+1)) q,res,idx,poped,areas=[],0,0,[],set() for i in range(n): heappush(q,(arr[i][1],i)) if len(q)<m:continue lr=arr[q[0][1]][1]-arr[i][0]+1 if lr>re...
Title: Fedor and coupons Time Limit: None seconds Memory Limit: None megabytes Problem Description: All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with i...
```python import sys from heapq import heappush,heappop n,m=map(int,input().split()) arr=sorted([*map(int,sys.stdin.readline().split()),i] for i in range(1,n+1)) q,res,idx,poped,areas=[],0,0,[],set() for i in range(n): heappush(q,(arr[i][1],i)) if len(q)<m:continue lr=arr[q[0][1]][1]-arr[i][0]+1 ...
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,581,483,514
2,147,483,647
Python 3
OK
TESTS
28
374
409,600
n=int(input()) a=[int(i) for i in list(input())] m=a for i in range(1,n+1): t=a[i:]+a[:i] x=t[0] for k in range(n): t[k]=(t[k]-x)%10 m=min(m,t) print(''.join(str(i) for i in m))
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 n=int(input()) a=[int(i) for i in list(input())] m=a for i in range(1,n+1): t=a[i:]+a[:i] x=t[0] for k in range(n): t[k]=(t[k]-x)%10 m=min(m,t) print(''.join(str(i) for i in m)) ```
3
1,006
C
Three Parts of the Array
PROGRAMMING
1,200
[ "binary search", "data structures", "two pointers" ]
null
null
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib...
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of elements in the array $d$. The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) β€” the elements of the array $d$.
Print a single integer β€” the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met. Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).
[ "5\n1 3 1 1 4\n", "5\n1 3 2 1 4\n", "3\n4 1 2\n" ]
[ "5\n", "4\n", "0\n" ]
In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$. In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$. In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$.
0
[ { "input": "5\n1 3 1 1 4", "output": "5" }, { "input": "5\n1 3 2 1 4", "output": "4" }, { "input": "3\n4 1 2", "output": "0" }, { "input": "1\n1000000000", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "5\n1 3 5 4 5", "output": ...
1,663,653,769
2,147,483,647
Python 3
OK
TESTS
27
187
17,510,400
n = int(input()) T = list(map(int, input().split())) i = 0 j = n-1 s1 = T[0] s2 = T[n-1] res = 0 while i < j: if s1 > s2: j -= 1 s2 += T[j] elif s1 < s2: i += 1 s1 += T[i] else: ...
Title: Three Parts of the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo...
```python n = int(input()) T = list(map(int, input().split())) i = 0 j = n-1 s1 = T[0] s2 = T[n-1] res = 0 while i < j: if s1 > s2: j -= 1 s2 += T[j] elif s1 < s2: i += 1 s1 += T[i] ...
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16).
Output one number β€” the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,696,965,971
2,147,483,647
Python 3
OK
TESTS
35
92
0
m,n=list(map(int, input().split())) a=m*n print(a//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python m,n=list(map(int, input().split())) a=m*n print(a//2) ```
3.977
999
B
Reversing Encryption
PROGRAMMING
900
[ "implementation" ]
null
null
A string $s$ of length $n$ can be encrypted by the following algorithm: - iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$). For example, the above algor...
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) β€” the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
Print a string $s$ such that the above algorithm results in $t$.
[ "10\nrocesfedoc\n", "16\nplmaetwoxesisiht\n", "1\nz\n" ]
[ "codeforces\n", "thisisexampletwo\n", "z\n" ]
The first example is described in the problem statement.
0
[ { "input": "10\nrocesfedoc", "output": "codeforces" }, { "input": "16\nplmaetwoxesisiht", "output": "thisisexampletwo" }, { "input": "1\nz", "output": "z" }, { "input": "2\nir", "output": "ri" }, { "input": "3\nilj", "output": "jli" }, { "input": "4\nj...
1,636,556,495
2,147,483,647
Python 3
OK
TESTS
20
46
4,505,600
import math n = int(input()) s = list(input()) div = [] for i in range(1, int(math.sqrt(n)) + 1): if n % i == 0: div.append(int(i)) if n / i != i: div.append(int(n / i)) div.sort() for j in div: # print(j) temp = s[0: j] temp = temp[::-1] s[0: j] = temp[0:...
Title: Reversing Encryption Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string $s$ of length $n$ can be encrypted by the following algorithm: - iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$...
```python import math n = int(input()) s = list(input()) div = [] for i in range(1, int(math.sqrt(n)) + 1): if n % i == 0: div.append(int(i)) if n / i != i: div.append(int(n / i)) div.sort() for j in div: # print(j) temp = s[0: j] temp = temp[::-1] s[0: j]...
3
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "...
1,697,540,680
2,147,483,647
PyPy 3-64
OK
TESTS
25
122
0
import sys word = sys.stdin.readline().split()[0] if word[0].islower(): word = word[0].upper() + word[1:] print(word)
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input...
```python import sys word = sys.stdin.readline().split()[0] if word[0].islower(): word = word[0].upper() + word[1:] print(word) ```
3
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co...
In the only line of input there is an integer *n* (3<=≀<=*n*<=≀<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "ou...
1,628,379,461
2,147,483,647
Python 3
OK
TESTS
26
62
6,758,400
from math import gcd n = int(input()) for a in range(n >> 1, 0, -1): b = n - a if gcd(a, b) == 1: print(a, b) break
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is cal...
```python from math import gcd n = int(input()) for a in range(n >> 1, 0, -1): b = n - a if gcd(a, b) == 1: print(a, b) break ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,533,712,098
2,147,483,647
Python 3
OK
TESTS
40
109
0
a = str(input()) flag=0 b=a.find('h') if(b==-1): print ("NO") flag=1 if(flag==0): a = a[b+1:] c = a.find('e') print if(c==-1): print ("NO") flag=1 if(flag==0): a = a[c+1:] d = a.find('l') if(d==-1): print ("NO") flag=1 if(flag==0): a = a[d+1...
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python a = str(input()) flag=0 b=a.find('h') if(b==-1): print ("NO") flag=1 if(flag==0): a = a[b+1:] c = a.find('e') print if(c==-1): print ("NO") flag=1 if(flag==0): a = a[c+1:] d = a.find('l') if(d==-1): print ("NO") flag=1 if(flag==0): ...
3.9455
47
A
Triangular numbers
PROGRAMMING
800
[ "brute force", "math" ]
A. Triangular numbers
2
256
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr...
The first line contains the single number *n* (1<=≀<=*n*<=≀<=500) β€” the given integer.
If the given integer is a triangular number output YES, otherwise output NO.
[ "1\n", "2\n", "3\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "2", "output": "NO" }, { "input": "3", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "NO...
1,647,536,963
2,147,483,647
PyPy 3
OK
TESTS
71
184
0
import math n=int(input()) if pow(int(math.sqrt(1+(8*n))),2)==1+(8*n): print("YES") else: print("NO")
Title: Triangular numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t...
```python import math n=int(input()) if pow(int(math.sqrt(1+(8*n))),2)==1+(8*n): print("YES") else: print("NO") ```
3.954
222
A
Shooshuns and Sequence
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ...
The first line contains two space-separated integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=105) β€” the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
[ "3 2\n3 1 1\n", "3 1\n3 1 1\n" ]
[ "1\n", "-1\n" ]
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1....
500
[ { "input": "3 2\n3 1 1", "output": "1" }, { "input": "3 1\n3 1 1", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 1\n2 1", "output": "-1" }, { "input": "4 4\n1 2 3 4", "output": "3" }...
1,390,193,905
2,147,483,647
Python 3
OK
TESTS
47
186
7,884,800
read=lambda:map(int,input().split()) n,k=read() a=list(read()) s=set(a[k-1:]) if len(s)>1: print(-1) else: p=k-2 while p>=0 and a[p]==a[k-1]: p-=1 print(p+1)
Title: Shooshuns and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the cur...
```python read=lambda:map(int,input().split()) n,k=read() a=list(read()) s=set(a[k-1:]) if len(s)>1: print(-1) else: p=k-2 while p>=0 and a[p]==a[k-1]: p-=1 print(p+1) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,678,497,538
2,147,483,647
Python 3
OK
TESTS
102
46
0
n = input() m = input() x='' for i in range(len(n)): if n[i]!=m[i]: x=x+'1' else: x=x+'0' print(x)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python n = input() m = input() x='' for i in range(len(n)): if n[i]!=m[i]: x=x+'1' else: x=x+'0' print(x) ```
3.9885
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
The first line features two integers *A* and *B* (0<=≀<=*A*,<=*B*<=≀<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≀<=*x*,<=*y*,<=*z*<=≀<=109)Β β€” the respective amounts of yellow, green and blue balls to be obtained.
Print a single integerΒ β€” the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output"...
1,515,758,126
2,147,483,647
Python 3
OK
TESTS
38
62
5,632,000
a,b=map(int,input().split()) x,y,z=map(int,input().split()) a1=2*x+y b1=3*z+y if a<a1: a2=a1-a else: a2=0 if b<b1: b2=b1-b else: b2=0 print(a2+b2)
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obta...
```python a,b=map(int,input().split()) x,y,z=map(int,input().split()) a1=2*x+y b1=3*z+y if a<a1: a2=a1-a else: a2=0 if b<b1: b2=b1-b else: b2=0 print(a2+b2) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16).
Output one number β€” the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,641,720,972
2,147,483,647
Python 3
OK
TESTS
35
92
0
enter = input() l1 = enter.split(" ") for i in range(len(l1)): l1[i] = int(l1[i]) c1 = l1[0] // 1 c2 = l1[1] // 2 c3 = c1 * c2 if l1[1] % 2 != 0: v = l1[0] // 2 c3 += v print(c3)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python enter = input() l1 = enter.split(" ") for i in range(len(l1)): l1[i] = int(l1[i]) c1 = l1[0] // 1 c2 = l1[1] // 2 c3 = c1 * c2 if l1[1] % 2 != 0: v = l1[0] // 2 c3 += v print(c3) ```
3.977
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≀<=|*s*|<=≀<=50). The second line contains the string *t* (1<=≀<=|*t*|<=≀<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,673,358,209
2,147,483,647
PyPy 3
OK
TESTS
19
186
0
s = input() t = input() count = 0 for i in range(len(t)): if s[count] == t[i]: count = count+1 print(count+1)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python s = input() t = input() count = 0 for i in range(len(t)): if s[count] == t[i]: count = count+1 print(count+1) ```
3
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
The first line contains string *s* of length *n* (2<=≀<=*n*<=≀<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≀<=*m*<=≀<=105) β€” the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t...
Print *m* integers β€” the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5...
1,693,903,884
2,147,483,647
PyPy 3-64
OK
TESTS
37
1,996
9,728,000
s = input() n = len(s) dp = [0] * n for i in range(1, n): dp[i] = dp[i - 1] + int(s[i] == s[i - 1]) m = int(input()) for _ in range(m): l, r = map(int, input().split()) print(dp[r - 1] - dp[l - 1])
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ...
```python s = input() n = len(s) dp = [0] * n for i in range(1, n): dp[i] = dp[i - 1] + int(s[i] == s[i - 1]) m = int(input()) for _ in range(m): l, r = map(int, input().split()) print(dp[r - 1] - dp[l - 1]) ```
3
203
C
Photographer
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's memory is *d* megabytes. Valera's camera can take photos of high and...
The first line contains two integers *n* and *d* (1<=≀<=*n*<=≀<=105,<=1<=≀<=*d*<=≀<=109) β€” the number of clients and the camera memory size, correspondingly. The second line contains two integers *a* and *b* (1<=≀<=*a*<=≀<=*b*<=≀<=104) β€” the size of one low quality photo and of one high quality photo, correspondingly. ...
On the first line print the answer to the problem β€” the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in ...
[ "3 10\n2 3\n1 4\n2 1\n1 0\n", "3 6\n6 6\n1 1\n1 0\n1 0\n" ]
[ "2\n3 2 ", "1\n2 " ]
none
1,500
[ { "input": "3 10\n2 3\n1 4\n2 1\n1 0", "output": "2\n3 2 " }, { "input": "3 6\n6 6\n1 1\n1 0\n1 0", "output": "1\n2 " }, { "input": "4 5\n6 8\n1 2\n3 0\n10 2\n0 4", "output": "0" }, { "input": "4 10\n6 6\n1 2\n2 2\n0 0\n0 0", "output": "2\n3 4 " }, { "input": "10 ...
1,453,221,179
2,147,483,647
Python 3
OK
TESTS
54
1,278
11,059,200
n, d = map(int,input().split()) a, b = map(int,input().split()) l = [] for i in range(1,n+1): a1, b1 = map(int,input().split()) l.append([a1*a + b1*b, i]) l.sort() temp = d ans = [] for i in l: if i[0] <= temp: ans.append(i[1]) temp -= i[0] else: break print(len(ans)) print (*ans)
Title: Photographer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of peopl...
```python n, d = map(int,input().split()) a, b = map(int,input().split()) l = [] for i in range(1,n+1): a1, b1 = map(int,input().split()) l.append([a1*a + b1*b, i]) l.sort() temp = d ans = [] for i in l: if i[0] <= temp: ans.append(i[1]) temp -= i[0] else: break print(len(ans)) print (*ans) ...
3
387
A
George and Sleep
PROGRAMMING
900
[ "implementation" ]
null
null
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*. Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ...
The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" β€” the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≀<=*hh*<=≀<=23, 00<=≀<=*mm*<=≀<=59.
In the single line print time *p* β€” the time George went to bed in the format similar to the format of the time in the input.
[ "05:50\n05:44\n", "00:00\n01:00\n", "00:01\n00:00\n" ]
[ "00:06\n", "23:00\n", "00:01\n" ]
In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect. In the second sample, George went to bed yesterday. In the third sample, George didn't do to bed at all.
500
[ { "input": "05:50\n05:44", "output": "00:06" }, { "input": "00:00\n01:00", "output": "23:00" }, { "input": "00:01\n00:00", "output": "00:01" }, { "input": "23:59\n23:59", "output": "00:00" }, { "input": "23:44\n23:55", "output": "23:49" }, { "input": "...
1,513,962,666
2,147,483,647
Python 3
OK
TESTS
47
61
5,632,000
s=input() t=input() hrs=int(s[:2])-int(t[:2]) mins=int(s[3:])-int(t[3:]) if mins<0: mins+=60 hrs-=1 if hrs<0: hrs+=24 hrs=str(hrs) mins=str(mins) if len(hrs)==1: hrs='0'+hrs if len(mins)==1: mins='0'+mins print(hrs+':'+mins)
Title: George and Sleep Time Limit: None seconds Memory Limit: None megabytes Problem Description: George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*. Help George! Write a program that will, given time *s* and *t*, determine the time *p* when Geor...
```python s=input() t=input() hrs=int(s[:2])-int(t[:2]) mins=int(s[3:])-int(t[3:]) if mins<0: mins+=60 hrs-=1 if hrs<0: hrs+=24 hrs=str(hrs) mins=str(mins) if len(hrs)==1: hrs='0'+hrs if len(mins)==1: mins='0'+mins print(hrs+':'+mins) ```
3
172
D
Calendar Reform
PROGRAMMING
1,500
[ "*special", "number theory" ]
null
null
Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that "the years fly by...", it was decided that starting from the next year t...
The only input line contains a pair of integers *a*, *n* (1<=≀<=*a*,<=*n*<=≀<=107; *a*<=+<=*n*<=-<=1<=≀<=107).
Print the required number *p*. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "25 3\n", "50 5\n" ]
[ "30\n", "125\n" ]
A note to the first sample test. A year of 25 days will consist of one month containing 25 days. A year of 26 days will consist of 26 months, one day each. A year of 27 days will have three months, 9 days each.
1,500
[ { "input": "25 3", "output": "30" }, { "input": "50 5", "output": "125" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output": "3" }, { "input": "1 10", "output": "38" }, { "input": "1 5000000", "output": "8224640917276" }, { "in...
1,678,673,309
2,147,483,647
PyPy 3-64
OK
TESTS
11
202
82,329,600
import math a,n=map(int,input().split()) arr=[0]*10000008 for i in range(1,math.ceil(math.sqrt(10000008))): for j in range(1,10000008): if j*i*i>=10000008: break arr[j*i*i]=j count=0 for i in range(a,a+n): count+=arr[i] print(count)
Title: Calendar Reform Time Limit: None seconds Memory Limit: None megabytes Problem Description: Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more...
```python import math a,n=map(int,input().split()) arr=[0]*10000008 for i in range(1,math.ceil(math.sqrt(10000008))): for j in range(1,10000008): if j*i*i>=10000008: break arr[j*i*i]=j count=0 for i in range(a,a+n): count+=arr[i] print(count) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16).
Output one number β€” the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,639,211,110
2,147,483,647
Python 3
OK
TESTS
35
92
0
a=list(map(int,input().split())) c=a[0]*a[1]//2 print(c)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python a=list(map(int,input().split())) c=a[0]*a[1]//2 print(c) ```
3.977
29
D
Ant on the Tree
PROGRAMMING
2,000
[ "constructive algorithms", "dfs and similar", "trees" ]
D. Ant on the Tree
2
256
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are *n* vertexes in the tree, and they are connected by *n*<=-<=1 edges so that there is a path between any pair ...
The first line contains integer *n* (3<=≀<=*n*<=≀<=300) β€” amount of vertexes in the tree. Next *n*<=-<=1 lines describe edges. Each edge is described with two integers β€” indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has numbe...
If the required route doesn't exist, output -1. Otherwise, output 2*n*<=-<=1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
[ "3\n1 2\n2 3\n3\n", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3\n", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6\n" ]
[ "1 2 3 2 1 ", "1 2 4 5 4 6 4 2 1 3 1 ", "-1\n" ]
none
2,000
[ { "input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1 " }, { "input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1 " }, { "input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1" }, { "input": "10\n8 10\n2 1\n7 5\n5 4\n6 10\n2 3\n3 10\n2 9\n7 2\n6 9 4...
1,689,319,172
2,147,483,647
PyPy 3-64
OK
TESTS
35
154
102,400
import sys readline = sys.stdin.readline N = int(readline()) tree = [[] for _ in range(N + 1)] weights = [[N + 1 + i, -1] for i in range(N + 1)] def clear_tree(node: int, parent: int): tree[node] = list(set(tree[node]) - {parent}) if len(tree[node]) == 0: return for child in tree[node]: c...
Title: Ant on the Tree Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are *n* vertexes...
```python import sys readline = sys.stdin.readline N = int(readline()) tree = [[] for _ in range(N + 1)] weights = [[N + 1 + i, -1] for i in range(N + 1)] def clear_tree(node: int, parent: int): tree[node] = list(set(tree[node]) - {parent}) if len(tree[node]) == 0: return for child in tree[node]:...
3.961309
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,637,478,575
2,147,483,647
Python 3
OK
TESTS
40
92
0
word=input() word1=input() reversed_word='' inde=-1 for i in word: reversed_word+=word[inde] inde-=1 if reversed_word==word1: 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 word=input() word1=input() reversed_word='' inde=-1 for i in word: reversed_word+=word[inde] inde-=1 if reversed_word==word1: print('YES') else: print('NO') ```
3.977
421
A
Pasha and Hamsters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams...
The first line contains integers *n*, *a*, *b* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*a*,<=*b*<=≀<=*n*) β€” the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains *a* distinct integers β€” the numbers of the apples Arthur likes. The next line...
Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
[ "4 2 3\n1 2\n2 3 4\n", "5 5 2\n3 4 1 2 5\n2 3\n" ]
[ "1 1 2 2\n", "1 1 1 1 1\n" ]
none
500
[ { "input": "4 2 3\n1 2\n2 3 4", "output": "1 1 2 2" }, { "input": "5 5 2\n3 4 1 2 5\n2 3", "output": "1 1 1 1 1" }, { "input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 7...
1,626,342,102
2,147,483,647
PyPy 3
OK
TESTS
32
109
20,172,800
n, a, b = map(int, input().split()) x = list(map(int, input().split()[:a])) y = list(map(int, input().split()[:b])) for i in range(1, n + 1): if i in x: print(1, end = " ") else : print(2, end = " ")
Title: Pasha and Hamsters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between...
```python n, a, b = map(int, input().split()) x = list(map(int, input().split()[:a])) y = list(map(int, input().split()[:b])) for i in range(1, n + 1): if i in x: print(1, end = " ") else : print(2, end = " ") ```
3
633
A
Ebony and Ivory
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ...
The first line of the input contains three integers *a*, *b*, *c* (1<=≀<=*a*,<=*b*<=≀<=100,<=1<=≀<=*c*<=≀<=10<=000)Β β€” the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
[ "4 6 15\n", "3 2 7\n", "6 11 6\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1Β·3 + 2Β·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1Β·6 + 0Β·11 = 6 damage.
250
[ { "input": "4 6 15", "output": "No" }, { "input": "3 2 7", "output": "Yes" }, { "input": "6 11 6", "output": "Yes" }, { "input": "3 12 15", "output": "Yes" }, { "input": "5 5 10", "output": "Yes" }, { "input": "6 6 7", "output": "No" }, { "...
1,500,102,277
2,147,483,647
Python 3
OK
TESTS
134
62
5,529,600
string = input() a, b, n = map(int, string.split()) for x in range(n // a + 1): if (n - a * x) % b == 0: print("Yes") break else: print("No")
Title: Ebony and Ivory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. F...
```python string = input() a, b, n = map(int, string.split()) for x in range(n // a + 1): if (n - a * x) % b == 0: print("Yes") break else: print("No") ```
3
251
A
Points on Line
PROGRAMMING
1,300
[ "binary search", "combinatorics", "two pointers" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen...
The first line contains two integers: *n* and *d* (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*d*<=≀<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 β€” the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input stri...
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
500
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "...
1,689,425,115
2,147,483,647
PyPy 3
OK
TESTS
39
404
11,059,200
from collections import defaultdict import math import sys from bisect import bisect_right def clc(): n,d = map(int,input().split()) arr = list(map(int,input().split())) arr = sorted(arr) ans= 0 for i in range(0,len(arr)): curr = arr[i] back = curr-d-1 ind...
Title: Points on Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart...
```python from collections import defaultdict import math import sys from bisect import bisect_right def clc(): n,d = map(int,input().split()) arr = list(map(int,input().split())) arr = sorted(arr) ans= 0 for i in range(0,len(arr)): curr = arr[i] back = curr-d-1 ...
3
412
B
Network Configuration
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess...
The first line contains two space-separated integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=100) β€” the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≀<=*a**i*<=≀<=32768); number *a**i* deno...
Print a single integer β€” the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.
[ "3 2\n40 20 30\n", "6 4\n100 20 40 20 50 50\n" ]
[ "30\n", "40\n" ]
In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.
1,000
[ { "input": "3 2\n40 20 30", "output": "30" }, { "input": "6 4\n100 20 40 20 50 50", "output": "40" }, { "input": "1 1\n16", "output": "16" }, { "input": "2 1\n10000 17", "output": "10000" }, { "input": "2 2\n200 300", "output": "200" }, { "input": "3 1...
1,404,678,062
722
Python 3
OK
TESTS
34
62
0
n, k = list(map(int, input().split())) s = list(map(int, input().split())) s.sort() print(s[- k])
Title: Network Configuration Time Limit: None seconds Memory Limit: None megabytes Problem Description: The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly a...
```python n, k = list(map(int, input().split())) s = list(map(int, input().split())) s.sort() print(s[- k]) ```
3
714
B
Filya and Homework
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc...
The first line of the input contains an integer *n* (1<=≀<=*n*<=≀<=100<=000)Β β€” the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=109)Β β€” elements of the array.
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
[ "5\n1 3 3 2 1\n", "5\n1 2 3 4 5\n" ]
[ "YES\n", "NO\n" ]
In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
1,000
[ { "input": "5\n1 3 3 2 1", "output": "YES" }, { "input": "5\n1 2 3 4 5", "output": "NO" }, { "input": "2\n1 2", "output": "YES" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" }, { "input": "2\n1 1000000000", "ou...
1,672,171,103
2,147,483,647
Python 3
OK
TESTS
79
62
8,192,000
# for i in range(5005): # count[i]=0 # for i in range(n): # count[arr[i]]=count.get(arr[i], 0) + 1 n=int(input()) set1=set() [set1.add(x) for x in input().split()] # print(set1) if len(set1)==1 or len(set1)==2: print("YES") exit() arr=[] if len(set1)==3: for i in set1: arr.append(int(i)) ...
Title: Filya and Homework Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a...
```python # for i in range(5005): # count[i]=0 # for i in range(n): # count[arr[i]]=count.get(arr[i], 0) + 1 n=int(input()) set1=set() [set1.add(x) for x in input().split()] # print(set1) if len(set1)==1 or len(set1)==2: print("YES") exit() arr=[] if len(set1)==3: for i in set1: arr.appen...
3
420
A
Start Up
PROGRAMMING
1,000
[ "implementation" ]
null
null
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
[ "AHA\n", "Z\n", "XO\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "AHA", "output": "YES" }, { "input": "Z", "output": "NO" }, { "input": "XO", "output": "NO" }, { "input": "AAA", "output": "YES" }, { "input": "AHHA", "output": "YES" }, { "input": "BAB", "output": "NO" }, { "input": "OMMMAAMMMO"...
1,687,324,334
2,147,483,647
PyPy 3
OK
TESTS
80
92
1,945,600
l = ["A", "H", "I", "M", "O", "T", "U", "V", "W", "X", "Y"] s = input() x = "YES" for i in s: if i not in l: x = "NO" break if s != s[::-1]: x = "NO" print(x)
Title: Start Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of ...
```python l = ["A", "H", "I", "M", "O", "T", "U", "V", "W", "X", "Y"] s = input() x = "YES" for i in s: if i not in l: x = "NO" break if s != s[::-1]: x = "NO" print(x) ```
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,697,910,071
2,147,483,647
PyPy 3-64
OK
TESTS
25
77
0
number = int(input()) count = 0 cubs = 1 while number > 0: if number - cubs >= 0: number -= cubs count += 1 cubs += count + 1 else: break print(count)
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 number = int(input()) count = 0 cubs = 1 while number > 0: if number - cubs >= 0: number -= cubs count += 1 cubs += count + 1 else: break print(count) ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,696,883,327
2,147,483,647
Python 3
OK
TESTS
40
92
0
s = input() t = input() cont = len(s) is_diff = False for character in t: cont -= 1 if character != s[cont]: is_diff = True break print("NO") if is_diff else print("YES")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python s = input() t = input() cont = len(s) is_diff = False for character in t: cont -= 1 if character != s[cont]: is_diff = True break print("NO") if is_diff else print("YES") ```
3.977
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,623,742,751
2,147,483,647
Python 3
OK
TESTS
30
154
0
s=input() count=0 times=0 for i in range(len(s)): if s[i].isupper(): count=count+1 if s[i].islower(): times=times+1 if count>times: print(s.upper()) if count<=times: 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 s=input() count=0 times=0 for i in range(len(s)): if s[i].isupper(): count=count+1 if s[i].islower(): times=times+1 if count>times: print(s.upper()) if count<=times: print(s.lower()) ```
3.9615
920
B
Tea Queue
PROGRAMMING
1,200
[ "implementation" ]
null
null
Recently *n* students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea. *i*-th s...
The first line contains one integer *t* β€” the number of test cases to solve (1<=≀<=*t*<=≀<=1000). Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of students. Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≀<=*l**i*<=≀<=...
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
[ "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n" ]
[ "1 2 \n1 0 2 \n" ]
The example contains 2 tests: 1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and ...
0
[ { "input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3", "output": "1 2 \n1 0 2 " }, { "input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2...
1,517,632,435
2,147,483,647
Python 3
OK
TESTS
8
61
5,632,000
import sys cases = int(sys.stdin.readline()) for x in range(0, cases): people = int(sys.stdin.readline()) times = [] for i in range(0, people): cur = [int(x) for x in sys.stdin.readline().strip().split(" ")] times.append(cur) time = 1 to_print = [] for t in times: if(time < t[0]): tim...
Title: Tea Queue Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently *n* students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use ...
```python import sys cases = int(sys.stdin.readline()) for x in range(0, cases): people = int(sys.stdin.readline()) times = [] for i in range(0, people): cur = [int(x) for x in sys.stdin.readline().strip().split(" ")] times.append(cur) time = 1 to_print = [] for t in times: if(time < t[0]):...
3
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=Γ—<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer β€” the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,694,443,345
2,147,483,647
Python 3
OK
TESTS
25
92
0
mat = [[int(i) for i in input().split()] for _ in range(5)] res = 0 for i in range(5): for j in range(5): if mat[i][j]: res = abs(2 - i) + abs(2 - j) print(res)
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=Γ—<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri...
```python mat = [[int(i) for i in input().split()] for _ in range(5)] res = 0 for i in range(5): for j in range(5): if mat[i][j]: res = abs(2 - i) + abs(2 - j) print(res) ```
3
22
B
Bargaining Table
PROGRAMMING
1,500
[ "brute force", "dp" ]
B. Bargaining Table
2
256
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=Γ—<=*m* meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, t...
The first line contains 2 space-separated numbers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=25) β€” the office room dimensions. Then there follow *n* lines with *m* characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in ...
Output one number β€” the maximum possible perimeter of a bargaining table for Bob's office room.
[ "3 3\n000\n010\n000\n", "5 4\n1100\n0000\n0000\n0000\n0000\n" ]
[ "8\n", "16\n" ]
none
0
[ { "input": "3 3\n000\n010\n000", "output": "8" }, { "input": "5 4\n1100\n0000\n0000\n0000\n0000", "output": "16" }, { "input": "3 3\n000\n110\n000", "output": "8" }, { "input": "4 2\n00\n10\n11\n00", "output": "6" }, { "input": "3 5\n00001\n00000\n10100", "out...
1,676,900,437
2,147,483,647
PyPy 3-64
OK
TESTS
23
342
29,900,800
import sys; R = sys.stdin.readline S = lambda: map(int,R().split()) n,m = S() a = [R().rstrip() for _ in range(n)] d = {} r = 4 for i in range(n): for j in range(m): if a[i][j]=='1': continue d[(i,j,i,j)] = 1 for l in range(j+1,m): if a[i][l]=='1': break ...
Title: Bargaining Table Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=Γ—<=*m* meters. Each square meter of the room is either ...
```python import sys; R = sys.stdin.readline S = lambda: map(int,R().split()) n,m = S() a = [R().rstrip() for _ in range(n)] d = {} r = 4 for i in range(n): for j in range(m): if a[i][j]=='1': continue d[(i,j,i,j)] = 1 for l in range(j+1,m): if a[i][l]=='1': break ...
3.858805
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,645,290,264
2,147,483,647
PyPy 3-64
OK
TESTS
81
186
0
vecs = list(zip(*[[int(x) for x in input().split()]for i in range(int(input()))])) def main(): for i in vecs: if sum(i) != 0: return "NO" return "YES" print(main())
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python vecs = list(zip(*[[int(x) for x in input().split()]for i in range(int(input()))])) def main(): for i in vecs: if sum(i) != 0: return "NO" return "YES" print(main()) ```
3.9535
873
B
Balanced Substring
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to deter...
The first line contains *n* (1<=≀<=*n*<=≀<=100000) β€” the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
[ "8\n11010111\n", "3\n111\n" ]
[ "4\n", "0\n" ]
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
0
[ { "input": "8\n11010111", "output": "4" }, { "input": "3\n111", "output": "0" }, { "input": "11\n00001000100", "output": "2" }, { "input": "10\n0100000000", "output": "2" }, { "input": "13\n0001000011010", "output": "6" }, { "input": "14\n0000010010101...
1,696,780,223
2,147,483,647
Python 3
OK
TESTS
53
78
14,848,000
n = int(input()) s = input() zero = 0 one = 0 dct = {0: -1} ans = 0 for i in range(n): if s[i] == '0': zero += 1 else: one += 1 diff = zero - one #print(i, diff) if diff not in dct: dct[diff] = i else: ans = max(ans, i - dct[diff]) #...
Title: Balanced Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called...
```python n = int(input()) s = input() zero = 0 one = 0 dct = {0: -1} ans = 0 for i in range(n): if s[i] == '0': zero += 1 else: one += 1 diff = zero - one #print(i, diff) if diff not in dct: dct[diff] = i else: ans = max(ans, i - dct[dif...
3
680
B
Bear and Finding Criminals
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he...
The first line of the input contains two integers *n* and *a* (1<=≀<=*a*<=≀<=*n*<=≀<=100)Β β€” the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≀<=*t**i*<=≀<=1). There are *t**i* criminals in the *i*-th city.
Print the number of criminals Limak will catch.
[ "6 3\n1 1 1 0 1 0\n", "5 2\n0 0 0 1 0\n" ]
[ "3\n", "1\n" ]
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third cityΒ β€” Limak is sure that this criminal is exactly in the third city. - There i...
1,000
[ { "input": "6 3\n1 1 1 0 1 0", "output": "3" }, { "input": "5 2\n0 0 0 1 0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "9 3\n1 1 1 1 1 1 1 1 0", "output": "8" }, { "input": "9 5\n1 0 1 0 1 0...
1,636,382,152
2,147,483,647
PyPy 3
OK
TESTS
24
93
17,715,200
n, p = map(int, input().split()) a, res, p = list(map(int, input().split())), 0, p - 1 for x in range(p + 1, n): if a[x] == 1 and ((p << 1) < x or a[(p << 1) - x] == 1): res += 1 for x in range(p - 1, -1, -1): if a[x] == 1 and ((p << 1) - x >= n or a[(p << 1) - x] == 1): res += 1 print(res + a[p])
Title: Bear and Finding Criminals Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city...
```python n, p = map(int, input().split()) a, res, p = list(map(int, input().split())), 0, p - 1 for x in range(p + 1, n): if a[x] == 1 and ((p << 1) < x or a[(p << 1) - x] == 1): res += 1 for x in range(p - 1, -1, -1): if a[x] == 1 and ((p << 1) - x >= n or a[(p << 1) - x] == 1): res += 1 print(res + a[...
3
682
B
Alyona and Mex
PROGRAMMING
1,200
[ "sortings" ]
null
null
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100<=000)Β β€” the number of elements in the Alyona's array. The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109)Β β€” the elements of the array.
Print one positive integerΒ β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
[ "5\n1 3 3 3 6\n", "2\n2 1\n" ]
[ "5\n", "3\n" ]
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
1,000
[ { "input": "5\n1 3 3 3 6", "output": "5" }, { "input": "2\n2 1", "output": "3" }, { "input": "1\n1", "output": "2" }, { "input": "1\n1000000000", "output": "2" }, { "input": "1\n2", "output": "2" }, { "input": "2\n1 1", "output": "2" }, { "...
1,496,112,196
2,147,483,647
Python 3
OK
TESTS
127
140
8,806,400
if __name__ == '__main__': n = int(input()) line = list(map(int, input().split())) line.sort() rest = 1 for it in line: rest += 1 if rest <= it else 0 print(rest)
Title: Alyona and Mex Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is small...
```python if __name__ == '__main__': n = int(input()) line = list(map(int, input().split())) line.sort() rest = 1 for it in line: rest += 1 if rest <= it else 0 print(rest) ```
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,653,991,784
2,147,483,647
Python 3
OK
TESTS
51
92
0
s=input() c=0 while len(s)>1: s=str(sum(map(int,s))) c+=1 print(c)
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 s=input() c=0 while len(s)>1: s=str(sum(map(int,s))) c+=1 print(c) ```
3.977
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,683,724,884
2,147,483,647
Python 3
OK
TESTS
44
92
0
s = input() first = 0 second = 0 for i in s: if i == '1': first += 1 second = 0 else: second += 1 first = 0 if first == 7 or second == 7: print('YES') break else: print('NO')
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A...
```python s = input() first = 0 second = 0 for i in s: if i == '1': first += 1 second = 0 else: second += 1 first = 0 if first == 7 or second == 7: print('YES') break else: print('NO') ```
3.977
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider t...
Print the answer on a single line β€” the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β€” 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling t...
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { ...
1,579,158,738
2,147,483,647
Python 3
OK
TESTS
45
248
8,704,000
z=int(input()) x=list(map(int,input().split())) print(['Still Rozdil','%d'%(x.index(min(x))+1)][x.count(min(x))==1])
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha...
```python z=int(input()) x=list(map(int,input().split())) print(['Still Rozdil','%d'%(x.index(min(x))+1)][x.count(min(x))==1]) ```
3
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=Γ—<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ—<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≀<=*r*,<=*c*<=≀<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters β€” the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,652,775,015
2,147,483,647
Python 3
OK
TESTS
42
92
4,505,600
n,m=map(int,input().split());a=[];b=[] for i in range(n): s=str(input()) a.append(list(map(str,s))) p=0 for i in range(m): b.append(list(map(str,('0'*n)))) for i in range(n): if ('S' in a[i])==False: p+=m a[i]=list(map(str,('0'*m))) for i in range(n): for j in range(m): ...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=Γ—<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ—<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python n,m=map(int,input().split());a=[];b=[] for i in range(n): s=str(input()) a.append(list(map(str,s))) p=0 for i in range(m): b.append(list(map(str,('0'*n)))) for i in range(n): if ('S' in a[i])==False: p+=m a[i]=list(map(str,('0'*m))) for i in range(n): for j in r...
3
914
C
Travelling Salesman and Special Numbers
PROGRAMMING
1,800
[ "brute force", "combinatorics", "dp" ]
null
null
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer *x* and reduce it to the number of bits set to 1 in the binary representation of *x*. For example for number 13 it's true that 1310<...
The first line contains integer *n* (1<=≀<=*n*<=&lt;<=21000). The second line contains integer *k* (0<=≀<=*k*<=≀<=1000). Note that *n* is given in its binary representation without any leading zeros.
Output a single integerΒ β€” the number of special numbers not greater than *n*, modulo 109<=+<=7.
[ "110\n2\n", "111111011\n2\n" ]
[ "3\n", "169\n" ]
In the first sample, the three special numbers are 3, 5 and 6. They get reduced to 2 in one operation (since there are two set bits in each of 3, 5 and 6) and then to 1 in one more operation (since there is only one set bit in 2).
1,500
[ { "input": "110\n2", "output": "3" }, { "input": "111111011\n2", "output": "169" }, { "input": "100011110011110110100\n7", "output": "0" }, { "input": "110100110\n0", "output": "1" }, { "input": "10000000000000000000000000000000000000000000\n2", "output": "792...
1,557,902,661
2,147,483,647
PyPy 3
OK
TESTS
141
171
6,041,600
R = lambda: map(int, input().split()) mod = 10 ** 9 + 7 maxn = 1001 c = [[0 for j in range(maxn)] for i in range(maxn)] for i in range(maxn): c[i][0] = 1 for i in range(1, maxn): for j in range(i + 1): c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod arr = list(map(int, input())) k = int(input(...
Title: Travelling Salesman and Special Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer *x* and...
```python R = lambda: map(int, input().split()) mod = 10 ** 9 + 7 maxn = 1001 c = [[0 for j in range(maxn)] for i in range(maxn)] for i in range(maxn): c[i][0] = 1 for i in range(1, maxn): for j in range(i + 1): c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod arr = list(map(int, input())) k = ...
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16).
Output one number β€” the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,696,075,297
2,147,483,647
Python 3
OK
TESTS
35
92
0
#!/usr/bin/env python # coding: utf-8 # In[8]: n, k = map(int, input().split()) out = int((n*k)/2) print(out) # In[ ]:
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python #!/usr/bin/env python # coding: utf-8 # In[8]: n, k = map(int, input().split()) out = int((n*k)/2) print(out) # In[ ]: ```
3.977
475
B
Strongly Connected City
PROGRAMMING
1,400
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=Γ—<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes...
The first line of input contains two integers *n* and *m*, (2<=≀<=*n*,<=*m*<=≀<=20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length *n*, made of characters '&lt;' and '&gt;', denoting direction of each horizontal street. If the *i*-th character...
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
[ "3 3\n&gt;&lt;&gt;\nv^v\n", "4 6\n&lt;&gt;&lt;&gt;\nv^v^v^\n" ]
[ "NO\n", "YES\n" ]
The figure above shows street directions in the second sample test case.
1,000
[ { "input": "3 3\n><>\nv^v", "output": "NO" }, { "input": "4 6\n<><>\nv^v^v^", "output": "YES" }, { "input": "2 2\n<>\nv^", "output": "YES" }, { "input": "2 2\n>>\n^v", "output": "NO" }, { "input": "3 3\n>><\n^^v", "output": "YES" }, { "input": "3 4\n>>...
1,424,140,175
2,147,483,647
Python 3
OK
TESTS
81
124
204,800
def main(): n, m = map(int, input().split()) nm = n * m neigh = [[] for _ in range(nm)] for y, c in enumerate(input()): for x in range(y * m + 1, y * m + m): if c == '<': neigh[x].append(x - 1) else: neigh[x - 1].append(x) for x, c in e...
Title: Strongly Connected City Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=Γ—<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one...
```python def main(): n, m = map(int, input().split()) nm = n * m neigh = [[] for _ in range(nm)] for y, c in enumerate(input()): for x in range(y * m + 1, y * m + m): if c == '<': neigh[x].append(x - 1) else: neigh[x - 1].append(x) for...
3
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o...
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≀<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≀<=104). The second line contains string *s* (1<=≀<=|*s*|<=≀<=105), where the *Ρ–*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a...
Print a single integer β€” the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { ...
1,693,591,227
2,147,483,647
Python 3
OK
TESTS
49
93
102,400
def main(arr, s): n = 0 for i in range(len(s)): n += arr[int(s[i]) - 1] return n if __name__ == "__main__": arr = list(map(int, input().split())) s = str(input()) print(main(arr, s))
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four ve...
```python def main(arr, s): n = 0 for i in range(len(s)): n += arr[int(s[i]) - 1] return n if __name__ == "__main__": arr = list(map(int, input().split())) s = str(input()) print(main(arr, s)) ```
3
424
A
Squats
PROGRAMMING
900
[ "implementation" ]
null
null
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ethe...
The first line contains integer *n* (2<=≀<=*n*<=≀<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting.
In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
[ "4\nxxXx\n", "2\nXX\n", "6\nxXXxXx\n" ]
[ "1\nXxXx\n", "1\nxX\n", "0\nxXXxXx\n" ]
none
500
[ { "input": "4\nxxXx", "output": "1\nXxXx" }, { "input": "2\nXX", "output": "1\nxX" }, { "input": "6\nxXXxXx", "output": "0\nxXXxXx" }, { "input": "4\nxXXX", "output": "1\nxxXX" }, { "input": "2\nXx", "output": "0\nXx" }, { "input": "22\nXXxXXxxXxXxXXXX...
1,410,813,174
2,147,483,647
Python 3
OK
TESTS
32
46
0
import math a=int(input()) y=input() smallxc=0 result="" for i in range(0,a): if(y[i:i+1]=="x"): smallxc+=1 if smallxc==a//2: print(0) print(y) else: counter=0 if smallxc>a//2: for j in range(0,a): if(y[j:j+1]=="x"): result+="X" counter+=1 if counter==smallxc-(a//2): ...
Title: Squats Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to ...
```python import math a=int(input()) y=input() smallxc=0 result="" for i in range(0,a): if(y[i:i+1]=="x"): smallxc+=1 if smallxc==a//2: print(0) print(y) else: counter=0 if smallxc>a//2: for j in range(0,a): if(y[j:j+1]=="x"): result+="X" counter+=1 if counter==smallxc-(a...
3
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* woode...
The first input line contains a single integer *n* β€” the number of cupboards in the kitchen (2<=≀<=*n*<=≀<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≀<=*l**i*,<=*r**i*<=≀<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal...
In the only output line print a single integer *t* β€” the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ...
1,680,812,091
2,147,483,647
PyPy 3-64
OK
TESTS
57
312
5,222,400
t = int(input()) l = 0 r = 0 for _ in range(t): a = [int(x) for x in input().split()] l += a[0] r += a[1] print(min(t-l, l) + min(t-r,r))
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long...
```python t = int(input()) l = 0 r = 0 for _ in range(t): a = [int(x) for x in input().split()] l += a[0] r += a[1] print(min(t-l, l) + min(t-r,r)) ```
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ...
The first line of the input contains two integers *n* and *h* (1<=≀<=*n*<=≀<=1000, 1<=≀<=*h*<=≀<=1000)Β β€” the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integerΒ β€” the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481...
1,695,026,622
2,147,483,647
Python 3
OK
TESTS
29
46
0
n,h = map(int,input().split()) l = input().split() res = 0 for p in l: if int(p)<=h: res+=1 else: res+=2 print(res)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers...
```python n,h = map(int,input().split()) l = input().split() res = 0 for p in l: if int(p)<=h: res+=1 else: res+=2 print(res) ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,655,724,911
2,147,483,647
Python 3
OK
TESTS
40
92
0
text1 = input() text2 = input() if text1 == text2[::- 1]: print("YES") else: print("NO") # this worked the first time
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 text1 = input() text2 = input() if text1 == text2[::- 1]: print("YES") else: print("NO") # this worked the first time ```
3.977
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o...
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≀<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≀<=104). The second line contains string *s* (1<=≀<=|*s*|<=≀<=105), where the *Ρ–*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a...
Print a single integer β€” the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { ...
1,663,525,684
2,147,483,647
Python 3
OK
TESTS
49
78
0
caloriesPerStrip = list(map(int,input().split(" "))) strips = input() calories = 0 for i in strips: index = int(i) - 1 calories += caloriesPerStrip[index] print(calories)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four ve...
```python caloriesPerStrip = list(map(int,input().split(" "))) strips = input() calories = 0 for i in strips: index = int(i) - 1 calories += caloriesPerStrip[index] print(calories) ```
3
26
B
Regular Bracket Sequence
PROGRAMMING
1,400
[ "greedy" ]
B. Regular Bracket Sequence
5
256
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters Β«+Β» and Β«1Β» into this sequence. For example, sequences Β«(())()Β», Β«()Β» and Β«(()(()))Β» are regular, while Β«)(Β», Β«(()Β» and Β«(()))(Β» are not. One day Johnny got bracket sequence. He decided to remove some...
Input consists of a single line with non-empty string of Β«(Β» and Β«)Β» characters. Its length does not exceed 106.
Output the maximum possible length of a regular bracket sequence.
[ "(()))(\n", "((()())\n" ]
[ "4\n", "6\n" ]
none
1,000
[ { "input": "(()))(", "output": "4" }, { "input": "((()())", "output": "6" }, { "input": "(", "output": "0" }, { "input": ")", "output": "0" }, { "input": ")(()(", "output": "2" }, { "input": "))))))(", "output": "0" }, { "input": "()()(()((...
1,671,243,915
2,147,483,647
PyPy 3-64
OK
TESTS
38
654
97,484,800
a = list(input()) ans = 0 stack = [] for x in a: if x == "(": stack.append("(") else: if len(stack) == 0: pass else: stack.pop() ans += 1 print(ans*2)
Title: Regular Bracket Sequence Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters Β«+Β» and Β«1Β» into this sequence. For example, sequences Β«(())()Β», Β«()Β» and Β«(()(()))Β» are regula...
```python a = list(input()) ans = 0 stack = [] for x in a: if x == "(": stack.append("(") else: if len(stack) == 0: pass else: stack.pop() ans += 1 print(ans*2) ```
3.75302
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100)Β β€” the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i...
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" ...
1,660,363,569
2,147,483,647
Python 3
OK
TESTS
50
46
0
n,m=map(int,input().split()) ans='#Black&White' for i in range(n): l=input().split() if 'C' in l or 'M' in l or 'Y' in l: ans='#Color' print(ans)
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python n,m=map(int,input().split()) ans='#Black&White' for i in range(n): l=input().split() if 'C' in l or 'M' in l or 'Y' in l: ans='#Color' print(ans) ```
3
952
A
Quirky Quantifiers
PROGRAMMING
800
[ "math" ]
null
null
The input contains a single integer *a* (10<=≀<=*a*<=≀<=999). Output 0 or 1.
The input contains a single integer *a* (10<=≀<=*a*<=≀<=999).
Output 0 or 1.
[ "13\n", "927\n", "48\n" ]
[ "1\n", "1\n", "0\n" ]
none
0
[ { "input": "13", "output": "1" }, { "input": "927", "output": "1" }, { "input": "48", "output": "0" }, { "input": "10", "output": "0" }, { "input": "999", "output": "1" }, { "input": "142", "output": "0" }, { "input": "309", "output": "...
1,600,865,839
2,147,483,647
PyPy 3
OK
TESTS
15
202
0
n=int(input()) k=str(bin(n))[-1] if k=='1':print(1) else:print(0)
Title: Quirky Quantifiers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (10<=≀<=*a*<=≀<=999). Output 0 or 1. Input Specification: The input contains a single integer *a* (10<=≀<=*a*<=≀<=999). Output Specification: Output 0 or 1. Demo Input: ['1...
```python n=int(input()) k=str(bin(n))[-1] if k=='1':print(1) else:print(0) ```
3
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis...
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla...
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "11101001...
1,683,601,842
2,147,483,647
Python 3
OK
TESTS
37
92
204,800
x = input() y=x.find('0') if y != -1: ans = x[:y]+x[y+1:] else: ans = x[1:] print(ans)
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought...
```python x = input() y=x.find('0') if y != -1: ans = x[:y]+x[y+1:] else: ans = x[1:] print(ans) ```
3
658
A
Bear and Reverse Radewoosh
PROGRAMMING
800
[ "implementation" ]
null
null
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff...
The first line contains two integers *n* and *c* (1<=≀<=*n*<=≀<=50,<=1<=≀<=*c*<=≀<=1000)Β β€” the number of problems and the constant representing the speed of loosing points. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≀<=*p**i*<=≀<=1000,<=*p**i*<=&lt;<=*p**i*<=+<=1)Β β€” initial scores. The third...
Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.
[ "3 2\n50 85 250\n10 15 25\n", "3 6\n50 85 250\n10 15 25\n", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n" ]
[ "Limak\n", "Radewoosh\n", "Tie\n" ]
In the first sample, there are 3 problems. Limak solves them as follows: 1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*Β·10 = 50 - 2Β·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85...
500
[ { "input": "3 2\n50 85 250\n10 15 25", "output": "Limak" }, { "input": "3 6\n50 85 250\n10 15 25", "output": "Radewoosh" }, { "input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76", "output": "Tie" }, { "input": "4 1\n3 5 6 9\n1 2 4 8", "output": "Limak" }, {...
1,574,836,496
2,147,483,647
PyPy 3
OK
TESTS
29
155
1,228,800
n, c = (int(x) for x in input().split()) p = [int(x) for x in input().split()] t = [int(x) for x in input().split()] l = sum([max(0, p[i] - c * sum(t[0:i + 1])) for i in range(n)]) p.reverse() t.reverse() r = sum([max(0, p[i] - c * sum(t[0:i + 1])) for i in range(n)]) if r > l: print('Radewoosh') elif r < l: pr...
Title: Bear and Reverse Radewoosh Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-...
```python n, c = (int(x) for x in input().split()) p = [int(x) for x in input().split()] t = [int(x) for x in input().split()] l = sum([max(0, p[i] - c * sum(t[0:i + 1])) for i in range(n)]) p.reverse() t.reverse() r = sum([max(0, p[i] - c * sum(t[0:i + 1])) for i in range(n)]) if r > l: print('Radewoosh') elif r <...
3
817
C
Really Big Numbers
PROGRAMMING
1,600
[ "binary search", "brute force", "dp", "math" ]
null
null
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different...
The first (and the only) line contains two integers *n* and *s* (1<=≀<=*n*,<=*s*<=≀<=1018).
Print one integer β€” the quantity of really big numbers that are not greater than *n*.
[ "12 1\n", "25 20\n", "10 9\n" ]
[ "3\n", "0\n", "1\n" ]
In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
0
[ { "input": "12 1", "output": "3" }, { "input": "25 20", "output": "0" }, { "input": "10 9", "output": "1" }, { "input": "300 1000", "output": "0" }, { "input": "500 1000", "output": "0" }, { "input": "1000 2000", "output": "0" }, { "input":...
1,689,907,446
2,147,483,647
PyPy 3-64
OK
TESTS
68
62
1,433,600
n,s=map(int,input().split()) def cal(x): global s ls=list(map(int,str(x))) if (int(x)-sum(ls))>=s: return True return False l=1 r=10**18 while l<=r: mid=(l+r)//2 if cal(mid): r=mid-1 else: l=mid+1 if l>n: print(0) else: print(n-l+1)
Title: Really Big Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its...
```python n,s=map(int,input().split()) def cal(x): global s ls=list(map(int,str(x))) if (int(x)-sum(ls))>=s: return True return False l=1 r=10**18 while l<=r: mid=(l+r)//2 if cal(mid): r=mid-1 else: l=mid+1 if l>n: print(0) else: print(n-l+1)...
3
573
B
Bear and Blocks
PROGRAMMING
1,600
[ "binary search", "data structures", "dp", "math" ]
null
null
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called inter...
The first line contains single integer *n* (1<=≀<=*n*<=≀<=105). The second line contains *n* space-separated integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≀<=*h**i*<=≀<=109) β€” sizes of towers.
Print the number of operations needed to destroy all towers.
[ "6\n2 1 4 6 2 2\n", "7\n3 3 3 1 3 3 3\n" ]
[ "3\n", "2\n" ]
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
1,000
[ { "input": "6\n2 1 4 6 2 2", "output": "3" }, { "input": "7\n3 3 3 1 3 3 3", "output": "2" }, { "input": "7\n5128 5672 5805 5452 5882 5567 5032", "output": "4" }, { "input": "10\n1 2 2 3 5 5 5 4 2 1", "output": "5" }, { "input": "14\n20 20 20 20 20 20 3 20 20 20 2...
1,613,636,753
2,147,483,647
PyPy 3
OK
TESTS
41
186
10,956,800
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) PI=float('inf') for _ in range(1):#nmbr()): n=nmbr() a=lst() ans=0 pre=[0]*n suf=[0]*n pre[0]=suf[n-1]=1 for i in range(1,n): pre[i]=min(1+pre[i-1],a[i]...
Title: Bear and Blocks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sa...
```python from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) PI=float('inf') for _ in range(1):#nmbr()): n=nmbr() a=lst() ans=0 pre=[0]*n suf=[0]*n pre[0]=suf[n-1]=1 for i in range(1,n): pre[i]=min(1+pre...
3
964
A
Splits
PROGRAMMING
800
[ "math" ]
null
null
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$. Th...
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output one integerΒ β€” the answer to the problem.
[ "7\n", "8\n", "9\n" ]
[ "4\n", "5\n", "5\n" ]
In the first sample, there are following possible weights of splits of $7$: Weight 1: [$\textbf 7$] Weight 2: [$\textbf 3$, $\textbf 3$, 1] Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1] Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$]
500
[ { "input": "7", "output": "4" }, { "input": "8", "output": "5" }, { "input": "9", "output": "5" }, { "input": "1", "output": "1" }, { "input": "286", "output": "144" }, { "input": "48", "output": "25" }, { "input": "941", "output": "471...
1,524,138,466
2,147,483,647
Python 3
OK
TESTS
63
108
7,065,600
inp = int(input()) print(int(inp/2)+1)
Title: Splits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The foll...
```python inp = int(input()) print(int(inp/2)+1) ```
3
932
A
Palindromic Supersequence
PROGRAMMING
800
[ "constructive algorithms" ]
null
null
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ...
First line contains a string *A* (1<=≀<=|*A*|<=≀<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*.
Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them.
[ "aba\n", "ab\n" ]
[ "aba", "aabaa" ]
In the first example, "aba" is a subsequence of "aba" which is a palindrome. In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.
500
[ { "input": "aba", "output": "abaaba" }, { "input": "ab", "output": "abba" }, { "input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk...
1,518,712,258
6,958
Python 3
OK
TESTS
48
358
10,035,200
# -*- coding: utf-8 -*- """ Created on Thu Feb 15 21:01:05 2018 @author: DNARNAprotein """ """ CODEFORCES http://codeforces.com/contest/932/problem/A """ def pikachu(a,c,n): #c is original string prefixes=[a[0:i+1] for i in range(n+1)] suffixes=[a[i:n+1] for i in range(n+1)] maxi=0 fo...
Title: Palindromic Supersequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co...
```python # -*- coding: utf-8 -*- """ Created on Thu Feb 15 21:01:05 2018 @author: DNARNAprotein """ """ CODEFORCES http://codeforces.com/contest/932/problem/A """ def pikachu(a,c,n): #c is original string prefixes=[a[0:i+1] for i in range(n+1)] suffixes=[a[i:n+1] for i in range(n+1)] maxi...
3
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis...
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla...
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "11101001...
1,607,159,485
2,147,483,647
Python 3
OK
TESTS
37
404
1,740,800
a = list(input()) if a.count('0') > 0: a.remove('0') else: a.remove('1') print(*a,sep='')
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought...
```python a = list(input()) if a.count('0') > 0: a.remove('0') else: a.remove('1') print(*a,sep='') ```
3
439
B
Devu, the Dumb Guy
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other ...
The first line will contain two space separated integers *n*, *x* (1<=≀<=*n*,<=*x*<=≀<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≀<=*c**i*<=≀<=105).
Output a single integer representing the answer to the problem.
[ "2 3\n4 1\n", "4 2\n5 1 2 1\n", "3 3\n1 1 1\n" ]
[ "11\n", "10\n", "6\n" ]
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ...
1,000
[ { "input": "2 3\n4 1", "output": "11" }, { "input": "4 2\n5 1 2 1", "output": "10" }, { "input": "3 3\n1 1 1", "output": "6" }, { "input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "output": "65" }, { "input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3...
1,676,017,228
2,147,483,647
Python 3
OK
TESTS
31
124
7,372,800
n,x = map(int,input().split()) l = list(map(int,input().split())) l.sort() ans = 0 for i in l: if x > 1: ans += (i*x) x-=1 else: x = 1 ans += (i*x) print(ans)
Title: Devu, the Dumb Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co...
```python n,x = map(int,input().split()) l = list(map(int,input().split())) l.sort() ans = 0 for i in l: if x > 1: ans += (i*x) x-=1 else: x = 1 ans += (i*x) print(ans) ```
3
583
B
Robot's Task
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to colle...
The first line contains number *n* (1<=≀<=*n*<=≀<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=&lt;<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Print a single number β€” the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information.
[ "3\n0 2 0\n", "5\n4 2 3 0 1\n", "7\n0 3 1 0 5 2 6\n" ]
[ "1\n", "3\n", "2\n" ]
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece. In the second sample to...
1,000
[ { "input": "3\n0 2 0", "output": "1" }, { "input": "5\n4 2 3 0 1", "output": "3" }, { "input": "7\n0 3 1 0 5 2 6", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "2\n0 1", "output": "0" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "out...
1,443,892,970
2,270
Python 3
OK
TESTS
56
233
0
n = int(input()) a = list(map(int, input().split())) turn = -1 current = 0 while(current < n): turn += 1 for i in range(n): if(a[i] >= 0 and a[i] <= current): a[i] = -1 current += 1 a.reverse() print(turn)
Title: Robot's Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The compu...
```python n = int(input()) a = list(map(int, input().split())) turn = -1 current = 0 while(current < n): turn += 1 for i in range(n): if(a[i] >= 0 and a[i] <= current): a[i] = -1 current += 1 a.reverse() print(turn) ```
3
760
B
Frodo and pillows
PROGRAMMING
1,500
[ "binary search", "greedy" ]
null
null
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≀<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge...
The only line contain three integers *n*, *m* and *k* (1<=≀<=*n*<=≀<=*m*<=≀<=109, 1<=≀<=*k*<=≀<=*n*)Β β€” the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integerΒ β€” the maximum number of pillows Frodo can have so that no one is hurt.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n" ]
[ "2\n", "4\n", "3\n" ]
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third exa...
1,000
[ { "input": "4 6 2", "output": "2" }, { "input": "3 10 3", "output": "4" }, { "input": "3 6 1", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000 1", "output": "1000000000" }, { ...
1,531,227,976
2,147,483,647
Python 3
OK
TESTS
69
139
0
# from itertools import combinations # from bisect import bisect_right # from functools import * # from collections import Counter I = lambda: list(map(int, input().split())) n, m, k = I() l, r = 1, m + 1 onLeft, onRight = k - 1, n - k while l < r - 1: amount = (l + r) >> 1 s = amount for neighbors in [onL...
Title: Frodo and pillows Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≀<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma...
```python # from itertools import combinations # from bisect import bisect_right # from functools import * # from collections import Counter I = lambda: list(map(int, input().split())) n, m, k = I() l, r = 1, m + 1 onLeft, onRight = k - 1, n - k while l < r - 1: amount = (l + r) >> 1 s = amount for neighbo...
3
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ...
The only line contains two integers: *n* and *m* (3<=≀<=*n*,<=*m*<=≀<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#...
1,694,885,815
2,147,483,647
Python 3
OK
TESTS
28
46
0
import sys # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") # sys.stderr = open("error.txt", "w") # # your remaining code n, m = map(int,input().split()) k = 1 for i in range(n): if i%2 !=0 : k=k*-1 for j in range(m): if i % 2 == 0: print('#',end="") else: ...
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*...
```python import sys # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") # sys.stderr = open("error.txt", "w") # # your remaining code n, m = map(int,input().split()) k = 1 for i in range(n): if i%2 !=0 : k=k*-1 for j in range(m): if i % 2 == 0: print('#',end="") el...
3
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5Β·*i* minutes to solve th...
The only line of the input contains two integers *n* and *k* (1<=≀<=*n*<=≀<=10, 1<=≀<=*k*<=≀<=240)Β β€” the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar...
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", ...
1,690,338,563
2,147,483,647
Python 3
OK
TESTS
52
46
0
raw = input() delim = raw.split() n = int(delim[0]) k = int(delim[1]) minutes = 240 - k possible = 0 for i in range(1,n+1): if 5*i <= minutes: possible += 1 minutes -= 5*i else: break print(possible)
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem...
```python raw = input() delim = raw.split() n = int(delim[0]) k = int(delim[1]) minutes = 240 - k possible = 0 for i in range(1,n+1): if 5*i <= minutes: possible += 1 minutes -= 5*i else: break print(possible) ```
3
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ...
The only line contains two integers: *n* and *m* (3<=≀<=*n*,<=*m*<=≀<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#...
1,699,890,974
2,147,483,647
Python 3
OK
TESTS
28
46
0
import sys number = list(map(int, sys.stdin.readline().split())) n = number[0] m = number[1] i = 0 k = 0 while i < n: if i % 2 == 0: j = 0 while j < m: print('#', end='') j += 1 else: if k % 2 == 0: j = 0 while j < m ...
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*...
```python import sys number = list(map(int, sys.stdin.readline().split())) n = number[0] m = number[1] i = 0 k = 0 while i < n: if i % 2 == 0: j = 0 while j < m: print('#', end='') j += 1 else: if k % 2 == 0: j = 0 wh...
3
38
A
Army
PROGRAMMING
800
[ "implementation" ]
A. Army
2
256
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is...
The first input line contains an integer *n* (2<=≀<=*n*<=≀<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≀<=*d**i*<=≀<=100). The third input line contains two integers *a* and *b* (1<=≀<=*a*<=&lt;<=*b*<=≀<=*n*). The numbers on the lines are space-separated.
Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*.
[ "3\n5 6\n1 2\n", "3\n5 6\n1 3\n" ]
[ "5\n", "11\n" ]
none
0
[ { "input": "3\n5 6\n1 2", "output": "5" }, { "input": "3\n5 6\n1 3", "output": "11" }, { "input": "2\n55\n1 2", "output": "55" }, { "input": "3\n85 78\n1 3", "output": "163" }, { "input": "4\n63 4 49\n2 3", "output": "4" }, { "input": "5\n93 83 42 56\n...
1,639,072,009
2,147,483,647
Python 3
OK
TESTS
50
92
0
n = int(input()) a = list(map(int, input().split())) k, m = map(int, input().split()) ans = 0 for i in range(k - 1, m - 1): ans += a[i] print(ans) # Thu Dec 09 2021 17:46:48 GMT+0000 (Coordinated Universal Time)
Title: Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<...
```python n = int(input()) a = list(map(int, input().split())) k, m = map(int, input().split()) ans = 0 for i in range(k - 1, m - 1): ans += a[i] print(ans) # Thu Dec 09 2021 17:46:48 GMT+0000 (Coordinated Universal Time) ```
3.977
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,692,344,872
2,147,483,647
Python 3
OK
TESTS
20
46
0
res = [] for i in range(int(input())): a = input() if len(a) > 10: res.append(a[0] + str((len(a) - 2)) + a[-1]) else: res.append(a) for i in res: print(i)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python res = [] for i in range(int(input())): a = input() if len(a) > 10: res.append(a[0] + str((len(a) - 2)) + a[-1]) else: res.append(a) for i in res: print(i) ```
3.977
653
A
Bear and Three Balls
PROGRAMMING
900
[ "brute force", "implementation", "sortings" ]
null
null
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easyΒ β€” there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes th...
The first line of the input contains one integer *n* (3<=≀<=*n*<=≀<=50)Β β€” the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=1000) where *t**i* denotes the size of the *i*-th ball.
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
[ "4\n18 55 16 17\n", "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose bal...
500
[ { "input": "4\n18 55 16 17", "output": "YES" }, { "input": "6\n40 41 43 44 44 44", "output": "NO" }, { "input": "8\n5 972 3 4 1 4 970 971", "output": "YES" }, { "input": "3\n959 747 656", "output": "NO" }, { "input": "4\n1 2 2 3", "output": "YES" }, { ...
1,465,265,992
2,147,483,647
Python 3
OK
TESTS
84
77
5,120,000
n = int(input()) a = [int(x) for x in input().split()] a.sort() cek = 1 temp = -1 for i in range (n): if(a[i] == temp + 1): cek += 1 temp = a[i] elif(a[i] == temp): pass else: cek = 1 temp = a[i] if(cek >= 3): break if (cek>=3): print ("YES") else: print ("NO")
Title: Bear and Three Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easyΒ β€” there are two rules Limak must obey to make fri...
```python n = int(input()) a = [int(x) for x in input().split()] a.sort() cek = 1 temp = -1 for i in range (n): if(a[i] == temp + 1): cek += 1 temp = a[i] elif(a[i] == temp): pass else: cek = 1 temp = a[i] if(cek >= 3): break if (cek>=3): print ("YES") else: print ("NO") ```
3
681
A
A Good Contest
PROGRAMMING
800
[ "implementation" ]
null
null
Codeforces user' handle color depends on his ratingΒ β€” it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≀<=*be...
Print Β«YESΒ» (quotes for clarity), if Anton has performed good in the contest and Β«NOΒ» (quotes for clarity) otherwise.
[ "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n" ]
[ "YES", "NO" ]
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
500
[ { "input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO" }, { "input": "1\nDb -3373 3591", "output": "NO" }, { "input": "5\nQ2bz 960 2342...
1,656,879,872
2,147,483,647
Python 3
OK
TESTS
60
46
0
n = int(input()) for _ in range(n): s, b, a = input().split() if int(b) >= 2400 and int(a) > int(b): print("YES") quit() print("NO")
Title: A Good Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Codeforces user' handle color depends on his ratingΒ β€” it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ...
```python n = int(input()) for _ in range(n): s, b, a = input().split() if int(b) >= 2400 and int(a) > int(b): print("YES") quit() print("NO") ```
3
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should cons...
The first line contains two positive integers *n* and *k* (2<=≀<=*n*<=≀<=100, 2<=≀<=*k*<=≀<=*min*(*n*,<=26)) β€” the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords β€” java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords β€” python, because its length is equal to 6 and it consists of 6 distinct lowercase letter...
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcde...
1,610,937,714
2,147,483,647
Python 3
OK
TESTS
47
62
0
a,b=map(int,input().split()) x="abcdefghijklmnopqrstuvxwyz" q=0 for i in range(a): print(x[q],end='') q+=1 if q==b: q=0
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the foll...
```python a,b=map(int,input().split()) x="abcdefghijklmnopqrstuvxwyz" q=0 for i in range(a): print(x[q],end='') q+=1 if q==b: q=0 ```
3
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the...
The first line contains two space-separated integers *n* and *x* (1<=≀<=*n*<=≀<=1000, 0<=≀<=*x*<=≀<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≀<=*d**i*<=≀<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ...
Print two space-separated integersΒ β€” number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1....
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,596,636,503
2,147,483,647
Python 3
OK
TESTS
34
108
6,758,400
n, x = map(int, input().split()) count = 0 for i in range(n): sign, packs = input().split() packs = int(packs) if sign == "+": x += packs elif sign == "-" and x < packs: count += 1 else: x -= packs print(x, count)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, p...
```python n, x = map(int, input().split()) count = 0 for i in range(n): sign, packs = input().split() packs = int(packs) if sign == "+": x += packs elif sign == "-" and x < packs: count += 1 else: x -= packs print(x, count) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,688,855,447
2,147,483,647
PyPy 3-64
OK
TESTS
20
62
0
n = int(input()) i = 0 while i < n: name = input() i = i+1 if(len(name)<=10): print(name) else: print(name[0]+ str(len(name)-2) + name[-1])
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python n = int(input()) i = 0 while i < n: name = input() i = i+1 if(len(name)<=10): print(name) else: print(name[0]+ str(len(name)-2) + name[-1]) ```
3.969
493
B
Vasya and Wrestling
PROGRAMMING
1,400
[ "implementation" ]
null
null
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number *n* β€” the number of techniques that the wrestlers have used (1<=≀<=*n*<=≀<=2Β·105). The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≀<=109, *a**i*<=β‰ <=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin...
If the first wrestler wins, print string "first", otherwise print "second"
[ "5\n1\n2\n-3\n-4\n3\n", "3\n-1\n-2\n3\n", "2\n4\n-4\n" ]
[ "second\n", "first\n", "second\n" ]
Sequence *x*  =  *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*  =  *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|  &gt;  |...
1,000
[ { "input": "5\n1\n2\n-3\n-4\n3", "output": "second" }, { "input": "3\n-1\n-2\n3", "output": "first" }, { "input": "2\n4\n-4", "output": "second" }, { "input": "7\n1\n2\n-3\n4\n5\n-6\n7", "output": "first" }, { "input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-...
1,624,958,750
2,147,483,647
PyPy 3
OK
TESTS
57
1,450
10,547,200
n = int(input()) first_moves = [] second_moves = [] last = None for i in range(n): move = int(input()) if move > 0: first_moves.append(move) else: second_moves.append(-move) if i == n-1: last = move first_score = sum(first_moves) second_score = sum(second_moves) ...
Title: Vasya and Wrestling Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers ...
```python n = int(input()) first_moves = [] second_moves = [] last = None for i in range(n): move = int(input()) if move > 0: first_moves.append(move) else: second_moves.append(-move) if i == n-1: last = move first_score = sum(first_moves) second_score = sum(seco...
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,679,196,178
2,147,483,647
Python 3
OK
TESTS
40
92
0
ai = input() an = input() if ai == an[::-1]: 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 ai = input() an = input() if ai == an[::-1]: print("YES") else: print("NO") ```
3.977
476
B
Dreamoon and WiFi
PROGRAMMING
1,300
[ "bitmasks", "brute force", "combinatorics", "dp", "math", "probabilities" ]
null
null
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de...
The first line contains a string *s*1 β€” the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 β€” the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ...
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
[ "++-+-\n+-+-+\n", "+-+-\n+-??\n", "+++\n??-\n" ]
[ "1.000000000000\n", "0.500000000000\n", "0.000000000000\n" ]
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position  + 1. For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low...
1,500
[ { "input": "++-+-\n+-+-+", "output": "1.000000000000" }, { "input": "+-+-\n+-??", "output": "0.500000000000" }, { "input": "+++\n??-", "output": "0.000000000000" }, { "input": "++++++++++\n+++??++?++", "output": "0.125000000000" }, { "input": "--+++---+-\n????????...
1,667,030,463
2,147,483,647
PyPy 3-64
OK
TESTS
31
77
614,400
from collections import defaultdict, deque from math import gcd,ceil,sqrt,factorial import sys import heapq from bisect import bisect_right as b_r from bisect import bisect_left as b_l from functools import reduce import operator as op INT_MAX = sys.maxsize-1 INT_MIN = -sys.maxsize def ncr(n:int,r:int):...
Title: Dreamoon and WiFi Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go...
```python from collections import defaultdict, deque from math import gcd,ceil,sqrt,factorial import sys import heapq from bisect import bisect_right as b_r from bisect import bisect_left as b_l from functools import reduce import operator as op INT_MAX = sys.maxsize-1 INT_MIN = -sys.maxsize def ncr(n:i...
3
554
A
Kyoya and Photobooks
PROGRAMMING
900
[ "brute force", "math", "strings" ]
null
null
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
The first line of input will be a single string *s* (1<=≀<=|*s*|<=≀<=20). String *s* consists only of lowercase English letters.
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
[ "a\n", "hi\n" ]
[ "51\n", "76\n" ]
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
250
[ { "input": "a", "output": "51" }, { "input": "hi", "output": "76" }, { "input": "y", "output": "51" }, { "input": "kgan", "output": "126" }, { "input": "zoabkyuvus", "output": "276" }, { "input": "spyemhyznjieyhhbk", "output": "451" }, { "i...
1,442,765,554
2,147,483,647
Python 3
OK
TESTS
33
62
0
import sys y = sys.stdin.readline().rstrip() x = len(y) print((x + 1) * 26 - x)
Title: Kyoya and Photobooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b...
```python import sys y = sys.stdin.readline().rstrip() x = len(y) print((x + 1) * 26 - x) ```
3
129
A
Cookies
PROGRAMMING
900
[ "implementation" ]
null
null
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan...
The first line contains the only integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=100) β€” the number of cookies in the *i*-th bag.
Print in the only line the only number β€” the sought number of ways. If there are no such ways print 0.
[ "1\n1\n", "10\n1 2 2 3 4 4 4 2 2 2\n", "11\n2 2 2 2 2 2 2 2 2 2 99\n" ]
[ "1\n", "8\n", "1\n" ]
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies β€” 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, t...
500
[ { "input": "1\n1", "output": "1" }, { "input": "10\n1 2 2 3 4 4 4 2 2 2", "output": "8" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 99", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 2", "output": "2" }, { "input": "2\n1 2", "o...
1,591,646,334
2,147,483,647
PyPy 3
OK
TESTS
52
312
0
n = int(input()) lst = list(map(int,input().split())) k = 0 for i in range(n): if lst[i] % 2 == 0: k += 1 if sum(lst) % 2 == 0: print(k) else: print(len(lst) - k)
Title: Cookies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan...
```python n = int(input()) lst = list(map(int,input().split())) k = 0 for i in range(n): if lst[i] % 2 == 0: k += 1 if sum(lst) % 2 == 0: print(k) else: print(len(lst) - k) ```
3
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,551,786,665
2,147,483,647
Python 3
OK
TESTS
51
810
409,600
n=int(input()) A=n//4 B=n//7 falg=False s="" for i in range(0,A+1): for j in range(0,B+1): if(i*4+j*7==n): for g in range(i): s+=str(4) for r in range(j): s+=str(7) falg=True; if falg: break if falg: break if...
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 n=int(input()) A=n//4 B=n//7 falg=False s="" for i in range(0,A+1): for j in range(0,B+1): if(i*4+j*7==n): for g in range(i): s+=str(4) for r in range(j): s+=str(7) falg=True; if falg: break if falg: ...
3.796737
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16).
Output one number β€” the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,666,697,538
2,147,483,647
Python 3
OK
TESTS
35
92
0
l=list(map(int,input().split())) print((l[0]*l[1])//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python l=list(map(int,input().split())) print((l[0]*l[1])//2) ```
3.977
16
B
Burglar and Matches
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
B. Burglar and Matches
0
64
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl...
The first line of the input contains integer *n* (1<=≀<=*n*<=≀<=2Β·108) and integer *m* (1<=≀<=*m*<=≀<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≀<=*a**i*<=≀<=108,<=1<=≀<=*b**i*<=≀<=10). All the input numbers are integer.
Output the only number β€” answer to the problem.
[ "7 3\n5 10\n2 5\n3 6\n", "3 3\n1 3\n2 2\n3 1\n" ]
[ "62\n", "7\n" ]
none
0
[ { "input": "7 3\n5 10\n2 5\n3 6", "output": "62" }, { "input": "3 3\n1 3\n2 2\n3 1", "output": "7" }, { "input": "1 1\n1 2", "output": "2" }, { "input": "1 2\n1 9\n1 6", "output": "9" }, { "input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "ou...
1,638,064,216
2,147,483,647
PyPy 3-64
OK
TESTS
49
124
512,000
m,n = map(int,input().split()) num = [] for i in range(n): num1 = list(map(int,input().split())) num.append(num1) d = 0 k = 0 while m > 0: max = 0 x = 0 y = 0 for j in range(len(num)): if num[j][1] >max: max = num[j][1] y = num[j][0] x = j ...
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat...
```python m,n = map(int,input().split()) num = [] for i in range(n): num1 = list(map(int,input().split())) num.append(num1) d = 0 k = 0 while m > 0: max = 0 x = 0 y = 0 for j in range(len(num)): if num[j][1] >max: max = num[j][1] y = num[j][0] x = j ...
3