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
215
A
Bicycle Chain
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<...
The first input line contains integer *n* (1<=≀<=*n*<=≀<=50) β€” the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≀<=*m*<=≀<=50) β€” the number of stars o...
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
[ "2\n4 5\n3\n12 13 15\n", "4\n1 2 3 4\n5\n10 11 12 13 14\n" ]
[ "2\n", "1\n" ]
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
500
[ { "input": "2\n4 5\n3\n12 13 15", "output": "2" }, { "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 2\n1\n1", "output": "1" }, { "input": "1\n1\n2\n1 2", "output": "1" }, { "input":...
1,518,388,184
2,147,483,647
Python 3
OK
TESTS
57
156
5,632,000
from sys import stdin import math def read(): return map(int, stdin.readline().split()) read() a = list(read()) read() b = list(read()) magic = [ x // y for x in b for y in a if x % y == 0 ] print(magic.count ( max(magic) ) )
Title: Bicycle Chain Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We ...
```python from sys import stdin import math def read(): return map(int, stdin.readline().split()) read() a = list(read()) read() b = list(read()) magic = [ x // y for x in b for y in a if x % y == 0 ] print(magic.count ( max(magic) ) ) ```
3
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces ...
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": "...
1,695,071,876
2,147,483,647
Python 3
OK
TESTS
42
92
0
vowels = 'aoyeui' ans = [] for i in input().lower(): if i not in vowels: ans.append('.') ans.append(i) print(''.join(ans))
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters...
```python vowels = 'aoyeui' ans = [] for i in input().lower(): if i not in vowels: ans.append('.') ans.append(i) print(''.join(ans)) ```
3
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that...
The first line contains two integers *n*, *l* (1<=≀<=*n*<=≀<=1000, 1<=≀<=*l*<=≀<=109)Β β€” the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≀<=*a**i*<=≀<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th...
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1...
1,692,058,465
2,147,483,647
Python 3
OK
TESTS
32
46
0
a = [int(a) for a in input().split(" ")] lanterns = a[0] streetlen = a[1] b = [int(a) for a in input().split(" ")] b.sort() diff = [] diff.append(b[0]) diff.append( streetlen - b[-1]) for trums in range(lanterns -1): diff.append((b[trums+1] - b[trums])/2) diff.sort() print(diff[-1])
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi...
```python a = [int(a) for a in input().split(" ")] lanterns = a[0] streetlen = a[1] b = [int(a) for a in input().split(" ")] b.sort() diff = [] diff.append(b[0]) diff.append( streetlen - b[-1]) for trums in range(lanterns -1): diff.append((b[trums+1] - b[trums])/2) diff.sort() print(diff[-1]) ```
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,689,861,844
2,147,483,647
Python 3
OK
TESTS
20
31
0
number_of_lines = int(input()) words = [] fixed_words = [] for x in range(number_of_lines): words.append(input("\n")) for w in words: if len(w) > 10: fixed_words.append(f"{w[0]}{(len(w) - 2)}{w[-1]}") else: fixed_words.append(w) for x in fixed_words: print(f"{x}")
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 number_of_lines = int(input()) words = [] fixed_words = [] for x in range(number_of_lines): words.append(input("\n")) for w in words: if len(w) > 10: fixed_words.append(f"{w[0]}{(len(w) - 2)}{w[-1]}") else: fixed_words.append(w) for x in fixed_words: print(f"{x}") ``...
3.9845
427
A
Police Recruits
PROGRAMMING
800
[ "implementation" ]
null
null
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
The first line of input will contain an integer *n*Β (1<=≀<=*n*<=≀<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ...
Print a single integer, the number of crimes which will go untreated.
[ "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n" ]
[ "2\n", "1\n", "8\n" ]
Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c...
500
[ { "input": "3\n-1 -1 1", "output": "2" }, { "input": "8\n1 -1 1 -1 -1 1 1 1", "output": "1" }, { "input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "output": "8" }, { "input": "7\n-1 -1 1 1 -1 -1 1", "output": "2" }, { "input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ...
1,687,441,282
2,147,483,647
Python 3
OK
TESTS
63
62
9,932,800
# -*- coding: utf-8 -*- """ Created on Thu Jun 22 15:31:20 2023 @author: RadmediX """ import sys inp=[] for line in sys.stdin: inp += [int(x) for x in line.strip().split()] n = inp[0] freePolice = 0 untreated = 0 for i in inp[1:]: if i > 0: freePolice += i else: ...
Title: Police Recruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of...
```python # -*- coding: utf-8 -*- """ Created on Thu Jun 22 15:31:20 2023 @author: RadmediX """ import sys inp=[] for line in sys.stdin: inp += [int(x) for x in line.strip().split()] n = inp[0] freePolice = 0 untreated = 0 for i in inp[1:]: if i > 0: freePolice += i ...
3
703
A
Mishka and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined....
The first line of the input contains single integer *n* *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≀<=*m**i*,<=<=*c**i*<=≀<=6)Β β€” values on dice upper face after Mishka's and Chris' throws in *i*-th ...
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
[ "3\n3 5\n2 1\n4 2\n", "2\n6 1\n1 6\n", "3\n1 5\n3 3\n2 2\n" ]
[ "Mishka", "Friendship is magic!^^", "Chris" ]
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there...
500
[ { "input": "3\n3 5\n2 1\n4 2", "output": "Mishka" }, { "input": "2\n6 1\n1 6", "output": "Friendship is magic!^^" }, { "input": "3\n1 5\n3 3\n2 2", "output": "Chris" }, { "input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1", "output": "Mishka" }, { "input": "8\n2 4\n1 4\n1 ...
1,668,672,084
2,147,483,647
Python 3
OK
TESTS
69
46
0
n=int(input()) a=0 b=0 for i in range(n): y = list(map(int, input().split())) if y[0] > y[1]: a+=1 elif y[0] < y[1]: b+=1 if a==b: print("Friendship is magic!^^") elif a > b: print("Mishka") elif a<b: print("Chris")
Title: Mishka and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st...
```python n=int(input()) a=0 b=0 for i in range(n): y = list(map(int, input().split())) if y[0] > y[1]: a+=1 elif y[0] < y[1]: b+=1 if a==b: print("Friendship is magic!^^") elif a > b: print("Mishka") elif a<b: print("Chris") ```
3
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite ...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100<=000)Β β€” the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≀<=*x**i*<=≀<=100<=000)Β β€” prices of the bottles of the drink in the *i*-th shop. The third line contains a single i...
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "...
1,695,673,337
2,147,483,647
Python 3
OK
TESTS
103
1,028
13,516,800
def counter(arr, t): l = 0 r = len(arr) t += 1 while (l<r): mid = l + (r-l)//2 if (arr[mid]<t): l = mid+1 else: r = mid return l n = int(input()) xarr = input().split() xarr = [int(x) for x in xarr] x...
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha...
```python def counter(arr, t): l = 0 r = len(arr) t += 1 while (l<r): mid = l + (r-l)//2 if (arr[mid]<t): l = mid+1 else: r = mid return l n = int(input()) xarr = input().split() xarr = [int(x) for x i...
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,657,474,954
2,147,483,647
Python 3
OK
TESTS
34
46
0
n,x=map(int,input().split()) dist=0 for i in range(n): a,b=input().split() b=int(b) if(a=='+'): x+=b elif(a=='-'): if(x<b): dist+=1 else: x-=b print(x,dist)
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()) dist=0 for i in range(n): a,b=input().split() b=int(b) if(a=='+'): x+=b elif(a=='-'): if(x<b): dist+=1 else: x-=b print(x,dist) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,540,959,987
2,147,483,647
PyPy 3
OK
TESTS
30
404
0
s=input() i=0 ans="" while i<len(s): if (i+1)<len(s): if s[i]=='-': if s[i+1]=='.': ans+='1' if s[i+1]=='-': ans+='2' i+=2 else: ans+='0' i+=1 else: ans+='0' i+=1 prin...
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary ...
```python s=input() i=0 ans="" while i<len(s): if (i+1)<len(s): if s[i]=='-': if s[i+1]=='.': ans+='1' if s[i+1]=='-': ans+='2' i+=2 else: ans+='0' i+=1 else: ans+='0' i...
3.899
884
C
Bertown Subway
PROGRAMMING
1,500
[ "dfs and similar", "greedy", "math" ]
null
null
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are *n* stations in the subway. It was built according to the Bertown Transport Law: 1. For each station *i* there exists exactly one train that goes from this station...
The first line contains one integer number *n* (1<=≀<=*n*<=≀<=100000) β€” the number of stations. The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≀<=*p**i*<=≀<=*n*) β€” the current structure of the subway. All these numbers are distinct.
Print one number β€” the maximum possible value of convenience.
[ "3\n2 1 3\n", "5\n1 5 4 3 2\n" ]
[ "9\n", "17\n" ]
In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3). In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<...
0
[ { "input": "3\n2 1 3", "output": "9" }, { "input": "5\n1 5 4 3 2", "output": "17" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 2", "output": "4" }, { "input": "2\n2 1", "output": "4" }, { "input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 ...
1,510,084,356
2,147,483,647
Python 3
OK
TESTS
27
187
6,860,800
def dfs(i, Colour, P): Stack = [i] size = 0 while Stack: v = Stack[-1] if Colour[v] == 0: Colour[v] = 1 size += 1 if Colour[P[v] - 1] == 0: Stack.append(P[v] - 1) else: Colour[v] = 2 S...
Title: Bertown Subway Time Limit: None seconds Memory Limit: None megabytes Problem Description: The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are *n* stations in the subway. It was built according to the Bertown...
```python def dfs(i, Colour, P): Stack = [i] size = 0 while Stack: v = Stack[-1] if Colour[v] == 0: Colour[v] = 1 size += 1 if Colour[P[v] - 1] == 0: Stack.append(P[v] - 1) else: Colour[v] = 2 ...
3
864
B
Polycarp and Letters
PROGRAMMING
1,000
[ "brute force", "implementation", "strings" ]
null
null
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters. Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met: - letters on positions from *A* in the string are all distinct and lowerc...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=200) β€” length of string *s*. The second line contains a string *s* consisting of lowercase and uppercase Latin letters.
Print maximum number of elements in pretty set of positions for string *s*.
[ "11\naaaaBaabAbA\n", "12\nzACaAbbaazzC\n", "3\nABC\n" ]
[ "2\n", "3\n", "0\n" ]
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There...
1,000
[ { "input": "11\naaaaBaabAbA", "output": "2" }, { "input": "12\nzACaAbbaazzC", "output": "3" }, { "input": "3\nABC", "output": "0" }, { "input": "1\na", "output": "1" }, { "input": "2\naz", "output": "2" }, { "input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLr...
1,603,728,725
2,147,483,647
Python 3
OK
TESTS
55
156
716,800
from sys import stdin,stderr,maxsize mod = int(1e9)+7 def I(): return int(stdin.readline()) def lint(): return [int(x) for x in stdin.readline().split()] def S(): return input().strip() def grid(r, c): return [lint() for i in range(r)] def debug(*args, c=6): print('\033[3{}m'.format(c), *args, '\033[0m', file=std...
Title: Polycarp and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters. Let *A* be a set of positions in the string. Let's call it pretty if...
```python from sys import stdin,stderr,maxsize mod = int(1e9)+7 def I(): return int(stdin.readline()) def lint(): return [int(x) for x in stdin.readline().split()] def S(): return input().strip() def grid(r, c): return [lint() for i in range(r)] def debug(*args, c=6): print('\033[3{}m'.format(c), *args, '\033[0m'...
3
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≀<=*n*<=≀<=10) β€” the number of rows and columns of the table.
Print a single line containing a positive integer *m* β€” the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,641,527,012
2,147,483,647
PyPy 3
OK
TESTS
10
77
0
n = int(input()) dp = [[1 for _ in range(n)] for _ in range(n)] ans = 0 for i in range(1, n): for j in range(1, n): dp[i][j] = dp[i - 1][j] + dp[i][j - 1] print(dp[-1][-1])
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n = int(input()) dp = [[1 for _ in range(n)] for _ in range(n)] ans = 0 for i in range(1, n): for j in range(1, n): dp[i][j] = dp[i - 1][j] + dp[i][j - 1] print(dp[-1][-1]) ```
3
279
B
Books
PROGRAMMING
1,400
[ "binary search", "brute force", "implementation", "two pointers" ]
null
null
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to...
The first line contains two integers *n* and *t* (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*t*<=≀<=109) β€” the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=104), where number *a**i* shows the number of minutes that the boy n...
Print a single integer β€” the maximum number of books Valera can read.
[ "4 5\n3 1 2 1\n", "3 3\n2 2 3\n" ]
[ "3\n", "1\n" ]
none
1,000
[ { "input": "4 5\n3 1 2 1", "output": "3" }, { "input": "3 3\n2 2 3", "output": "1" }, { "input": "1 3\n5", "output": "0" }, { "input": "1 10\n4", "output": "1" }, { "input": "2 10\n6 4", "output": "2" }, { "input": "6 10\n2 3 4 2 1 1", "output": "4...
1,682,257,720
2,147,483,647
Python 3
OK
TESTS
38
498
6,451,200
n, t = map(int, input().split()) books = list(map(int, input().split())) i = j = 0 time = ans = 0 while j <= n - 1: time += books[j] while time > t: time -= books[i] i += 1 if time <= t: ans = max(ans, j - i + 1) j += 1 print(ans)
Title: Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t...
```python n, t = map(int, input().split()) books = list(map(int, input().split())) i = j = 0 time = ans = 0 while j <= n - 1: time += books[j] while time > t: time -= books[i] i += 1 if time <= t: ans = max(ans, j - i + 1) j += 1 print(ans) ```
3
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ...
The first line contains the only integer *n* (1<=≀<=*n*<=≀<=107) β€” the required length of the cyclic path.
Print the only integer β€” the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" ...
1,684,397,485
2,147,483,647
PyPy 3
OK
TESTS
36
872
5,734,400
import sys,random,bisect from collections import deque,defaultdict,Counter from heapq import heapify,heappop,heappush from math import gcd from types import GeneratorType #from functools import cache 3.9 mod = int(1e9 + 7) #998244353 inf = int(1e20) input = lambda :sys.stdin.readline().rstrip() mi = lambda :m...
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m...
```python import sys,random,bisect from collections import deque,defaultdict,Counter from heapq import heapify,heappop,heappush from math import gcd from types import GeneratorType #from functools import cache 3.9 mod = int(1e9 + 7) #998244353 inf = int(1e20) input = lambda :sys.stdin.readline().rstrip() mi =...
3
500
A
New Year Transportation
PROGRAMMING
1,000
[ "dfs and similar", "graphs", "implementation" ]
null
null
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=Γ—<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0...
The first line contains two space-separated integers *n* (3<=≀<=*n*<=≀<=3<=Γ—<=104) and *t* (2<=≀<=*t*<=≀<=*n*) β€” the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≀<=*a**i*<=≀<=*n*<=-<=*i*). It is guara...
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
[ "8 4\n1 2 1 2 1 2 1\n", "8 5\n1 2 1 2 1 1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
500
[ { "input": "8 4\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "8 5\n1 2 1 2 1 1 1", "output": "NO" }, { "input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "output": "YES" }, { "input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ...
1,647,104,190
2,147,483,647
Python 3
OK
TESTS
34
46
1,536,000
n,t=map(int,input().split()) l=input().split() temp=1 l=[int(i) for i in l] while(temp!=t): k=l[temp-1]+temp if k==t: print("YES") exit() elif k>t: break else: temp=k print("NO")
Title: New Year Transportation Time Limit: None seconds Memory Limit: None megabytes Problem Description: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=Γ—<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o...
```python n,t=map(int,input().split()) l=input().split() temp=1 l=[int(i) for i in l] while(temp!=t): k=l[temp-1]+temp if k==t: print("YES") exit() elif k>t: break else: temp=k print("NO") ```
3
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" ...
1,677,909,649
2,147,483,647
Python 3
OK
TESTS
46
358
9,625,600
from math import * import sys n = int(input()) laps=[] for i in range(n): laps.append([int(x) for x in input().split()]) laps.sort(key=lambda x: x[1]) for i in range(n-1): if (laps[i][0]>laps[i+1][0]): print('Happy Alex') sys.exit() print('Poor Alex')
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the...
```python from math import * import sys n = int(input()) laps=[] for i in range(n): laps.append([int(x) for x in input().split()]) laps.sort(key=lambda x: x[1]) for i in range(n-1): if (laps[i][0]>laps[i+1][0]): print('Happy Alex') sys.exit() print('Poor Alex') `...
3
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
The first line contains an integer *N* (1<=≀<=*N*<=≀<=1000) β€” the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* β€” the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers β€” the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20...
1,563,558,671
2,147,483,647
Python 3
OK
TESTS
61
248
0
#Towers n = int(input()) a = list(map(int, input().split())) a.sort() temp = a[0] max = 1 h = 0 count = 1 for i in range(n): if temp == a[i]: h += 1 if h > max: max = h else: count += 1 temp = a[i] h = 1 print("{} {}".format(max, count...
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct...
```python #Towers n = int(input()) a = list(map(int, input().split())) a.sort() temp = a[0] max = 1 h = 0 count = 1 for i in range(n): if temp == a[i]: h += 1 if h > max: max = h else: count += 1 temp = a[i] h = 1 print("{} {}".format(...
3.938
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,574,440,614
2,147,483,647
PyPy 3
OK
TESTS
102
140
0
x = input() y = input() N=int(x, 2)^int(y,2) a = '{0:b}'.format(N) if len(a)<len(x): a = '0'*(len(x)-len(a))+a print(a)
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 x = input() y = input() N=int(x, 2)^int(y,2) a = '{0:b}'.format(N) if len(a)<len(x): a = '0'*(len(x)-len(a))+a print(a) ```
3.965
1,004
B
Sonya and Exhibition
PROGRAMMING
1,300
[ "constructive algorithms", "greedy", "implementation", "math" ]
null
null
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions shoul...
The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$)Β β€” the number of flowers and visitors respectively. Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive.
Print the string of $n$ characters. The $i$-th symbol should be Β«0Β» if you want to put a rose in the $i$-th position, otherwise Β«1Β» if you want to put a lily. If there are multiple answers, print any.
[ "5 3\n1 3\n2 4\n2 5\n", "6 3\n5 6\n1 4\n4 6\n" ]
[ "01100", "110010" ]
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty ...
1,000
[ { "input": "5 3\n1 3\n2 4\n2 5", "output": "01010" }, { "input": "6 3\n5 6\n1 4\n4 6", "output": "010101" }, { "input": "10 4\n3 3\n1 6\n9 9\n10 10", "output": "0101010101" }, { "input": "1 1\n1 1", "output": "0" }, { "input": "1000 10\n3 998\n2 1000\n1 999\n2 100...
1,530,860,201
2,147,483,647
Python 3
OK
TESTS
27
124
0
n,k=input().split() n=int(n) strn="" for i in range(0,n): if(i%2==0): strn+="1" else: strn+="0" print(strn)
Title: Sonya and Exhibition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the ...
```python n,k=input().split() n=int(n) strn="" for i in range(0,n): if(i%2==0): strn+="1" else: strn+="0" print(strn) ```
3
292
B
Network Topology
PROGRAMMING
1,200
[ "graphs", "implementation" ]
null
null
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them...
The first line contains two space-separated integers *n* and *m* (4<=≀<=*n*<=≀<=105;Β 3<=≀<=*m*<=≀<=105) β€” the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≀<=*x**i*,<=*...
In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo...
[ "4 3\n1 2\n2 3\n3 4\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "4 3\n1 2\n1 3\n1 4\n", "4 4\n1 2\n2 3\n3 1\n1 4\n" ]
[ "bus topology\n", "ring topology\n", "star topology\n", "unknown topology\n" ]
none
1,000
[ { "input": "4 3\n1 2\n2 3\n3 4", "output": "bus topology" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "ring topology" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "star topology" }, { "input": "4 4\n1 2\n2 3\n3 1\n1 4", "output": "unknown topology" }, { "i...
1,647,219,956
2,147,483,647
Python 3
OK
TESTS
45
778
17,715,200
# Network Topology ui = input().split() n, m = int(ui[0]), int(ui[1]) graph = [set() for x in range(n+1)] for _ in range(m): ui = input().split() n1, n2 = int(ui[0]), int(ui[1]) graph[n1].add(n2) graph[n2].add(n1) if(n == m): # Check for ring topology for i in range(1, n+1): if(len(g...
Title: Network Topology Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in...
```python # Network Topology ui = input().split() n, m = int(ui[0]), int(ui[1]) graph = [set() for x in range(n+1)] for _ in range(m): ui = input().split() n1, n2 = int(ui[0]), int(ui[1]) graph[n1].add(n2) graph[n2].add(n1) if(n == m): # Check for ring topology for i in range(1, n+1): ...
3
761
D
Dasha and Very Difficult Problem
PROGRAMMING
1,700
[ "binary search", "brute force", "constructive algorithms", "greedy", "sortings" ]
null
null
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences *a* and *b* of length *n* each you need to write a sequence *c* of length *n*, the *i*-th element of which is calculated as follows: *c**i*<==<=*b**i*<=-<=*a**i*. About sequences *a* and *b* we know that their ele...
The first line contains three integers *n*, *l*, *r* (1<=≀<=*n*<=≀<=105,<=1<=≀<=*l*<=≀<=*r*<=≀<=109) β€” the length of the sequence and boundaries of the segment where the elements of sequences *a* and *b* are. The next line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (*l*<=≀<=*a**i*<=≀<=*r*) β€” the elements o...
If there is no the suitable sequence *b*, then in the only line print "-1". Otherwise, in the only line print *n* integers β€” the elements of any suitable sequence *b*.
[ "5 1 5\n1 1 1 1 1\n3 1 5 4 2\n", "4 2 9\n3 4 8 9\n3 2 1 4\n", "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6\n" ]
[ "3 1 5 4 2 ", "2 2 2 9 ", "-1\n" ]
Sequence *b* which was found in the second sample is suitable, because calculated sequence *c* = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1,  - 2,  - 6, 0] (note that *c*<sub class="lower-index">*i*</sub> = *b*<sub class="lower-index">*i*</sub> - *a*<sub class="lower-index">*i*</sub>) has compressed sequence equals to *p* = ...
2,000
[ { "input": "5 1 5\n1 1 1 1 1\n3 1 5 4 2", "output": "3 1 5 4 2 " }, { "input": "4 2 9\n3 4 8 9\n3 2 1 4", "output": "2 2 2 9 " }, { "input": "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6", "output": "-1" }, { "input": "5 1 7\n1 4 4 6 5\n5 2 1 4 3", "output": "2 2 1 6 4 " }, { ...
1,593,491,240
2,147,483,647
PyPy 3
OK
TESTS
63
624
37,785,600
n, l, r = map(int, input().split()) a = list(map(int, input().split())) out = [-1] * n p = list(map(int, input().split())) pp = [(p[i],i) for i in range(n)] pp.sort() curr = -(l+r) for v, i in pp: best = curr + 1 + a[i] if best < l: best = l out[i] = best curr = best - a[i] if m...
Title: Dasha and Very Difficult Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences *a* and *b* of length *n* each you need to write a sequence *c* of length *n*, the *i*-th elemen...
```python n, l, r = map(int, input().split()) a = list(map(int, input().split())) out = [-1] * n p = list(map(int, input().split())) pp = [(p[i],i) for i in range(n)] pp.sort() curr = -(l+r) for v, i in pp: best = curr + 1 + a[i] if best < l: best = l out[i] = best curr = best - a[...
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,689,533,133
2,147,483,647
Python 3
OK
TESTS
34
46
0
n = int(input()) data = list(map(int, input().split())) l, r, d, s = 0, n - 1, 0, 0 while l <= r: if (l + r) % 2 == (n - 1) % 2: if data[l] > data[r]: s += data[l] l += 1 else: s += data[r] r -= 1 else: if data[l] > data[r]: ...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python n = int(input()) data = list(map(int, input().split())) l, r, d, s = 0, n - 1, 0, 0 while l <= r: if (l + r) % 2 == (n - 1) % 2: if data[l] > data[r]: s += data[l] l += 1 else: s += data[r] r -= 1 else: if data[l] > ...
3
1,003
A
Polycarp's Pockets
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i...
The first line of the input contains one integer $n$ ($1 \le n \le 100$) β€” the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) β€” values of coins.
Print only one integer β€” the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
[ "6\n1 2 4 3 3 2\n", "1\n100\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "6\n1 2 4 3 3 2", "output": "2" }, { "input": "1\n100", "output": "1" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
1,663,150,115
2,147,483,647
Python 3
OK
TESTS
37
46
102,400
from collections import Counter l=int(input()) l1=[int(i) for i in input().split()] s=Counter(l1) val=list(s.values()) print(max(val))
Title: Polycarp's Pockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Po...
```python from collections import Counter l=int(input()) l1=[int(i) for i in input().split()] s=Counter(l1) val=list(s.values()) print(max(val)) ```
3
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=200<=000)Β β€” the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i*Β β€” the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one numberΒ β€” the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,675,861,902
2,147,483,647
Python 3
OK
TESTS
30
249
0
faces = { "Tetrahedron": 4, "Cube": 6, "Octahedron": 8, "Dodecahedron": 12, "Icosahedron": 20 } ans = 0 for _ in range(int(input())): ans += faces[input()] print(ans)
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python faces = { "Tetrahedron": 4, "Cube": 6, "Octahedron": 8, "Dodecahedron": 12, "Icosahedron": 20 } ans = 0 for _ in range(int(input())): ans += faces[input()] print(ans) ```
3
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are...
The only line contains a string of length *n* (1<=≀<=*n*<=≀<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integerΒ β€” the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { ...
1,592,640,004
2,147,483,647
Python 3
OK
TESTS
43
109
307,200
def answer(): a = [x for x in list(input()) if x in "AQ"] i=0 ans=0 while i<len(a): if a[i]=="Q": j=i+1 while j<len(a): if a[j]=="A": k=j+1 while k<len(a): if a[k]=="Q": ...
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"...
```python def answer(): a = [x for x in list(input()) if x in "AQ"] i=0 ans=0 while i<len(a): if a[i]=="Q": j=i+1 while j<len(a): if a[j]=="A": k=j+1 while k<len(a): if a[k]=="Q": ...
3
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves β€” the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do...
The first line contains integer *n* (1<=≀<=*n*<=≀<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half...
Print a single number β€” the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the...
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n...
1,453,562,515
2,147,483,647
Python 3
OK
TESTS
59
124
0
n = int(input()) arr_a, arr_b = [], [] for _ in range(n): a, b = map(int, input().split()) arr_a.append(a) arr_b.append(b) if sum(arr_a) % 2 + sum(arr_b) % 2 == 0: print(0) exit() for i in range(n): arr_a[i], arr_b[i] = arr_b[i], arr_a[i] if sum(arr_a) % 2 + sum(arr_b) % 2 == ...
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves β€” the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n...
```python n = int(input()) arr_a, arr_b = [], [] for _ in range(n): a, b = map(int, input().split()) arr_a.append(a) arr_b.append(b) if sum(arr_a) % 2 + sum(arr_b) % 2 == 0: print(0) exit() for i in range(n): arr_a[i], arr_b[i] = arr_b[i], arr_a[i] if sum(arr_a) % 2 + sum(arr_...
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,568,569,491
2,147,483,647
Python 3
OK
TESTS
32
218
0
num = int(input()) x = list(map(int,input().strip().split()))[:num] arry =[0]*101 for i in range(num): if x[i] % 2 == 0: arry[i] = "a" elif x[i] % 2 == 1 : arry[i] = "b" if arry.count("b")>1: print(arry.index("a")+1) else: print(arry.index("b")+...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” t...
```python num = int(input()) x = list(map(int,input().strip().split()))[:num] arry =[0]*101 for i in range(num): if x[i] % 2 == 0: arry[i] = "a" elif x[i] % 2 == 1 : arry[i] = "b" if arry.count("b")>1: print(arry.index("a")+1) else: print(arry.i...
3.9455
714
A
Meeting of Old Friends
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Today an outstanding event is going to happen in the forestΒ β€” hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to ...
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≀<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≀<=1018, *l*1<=≀<=*r*1, *l*2<=≀<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integerΒ β€” the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
500
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input":...
1,474,090,908
2,147,483,647
Python 3
OK
TESTS
96
62
0
line = input() l = line.split() l1 = int(l[0]) r1 = int(l[1]) l2 = int(l[2]) r2 = int(l[3]) k = int(l[4]) spent = 0 if l2 > r1 or r2 < l1: spent = 0 else: if l1 > l2: start = l1 else: start = l2 if r1 < r2: finish = r1 else: finish = r2 spent = finish - start + 1 if k >= start and k <= finish: ...
Title: Meeting of Old Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today an outstanding event is going to happen in the forestΒ β€” hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi...
```python line = input() l = line.split() l1 = int(l[0]) r1 = int(l[1]) l2 = int(l[2]) r2 = int(l[3]) k = int(l[4]) spent = 0 if l2 > r1 or r2 < l1: spent = 0 else: if l1 > l2: start = l1 else: start = l2 if r1 < r2: finish = r1 else: finish = r2 spent = finish - start + 1 if k >= start and k <=...
3
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
The first line contains a non-empty string *s* β€” the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": ...
1,694,969,119
2,147,483,647
PyPy 3-64
OK
TESTS
21
122
0
start = sorted(str(input()).split("+")) final = str() for i in start: final += str(i) + "+" print(final[:-1])
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak...
```python start = sorted(str(input()).split("+")) final = str() for i in start: final += str(i) + "+" print(final[:-1]) ```
3
415
B
Mashmokh and Tokens
PROGRAMMING
1,500
[ "binary search", "greedy", "implementation", "math" ]
null
null
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest o...
The first line of input contains three space-separated integers *n*,<=*a*,<=*b*Β (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*a*,<=*b*<=≀<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n*Β (1<=≀<=*x**i*<=≀<=109).
Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day.
[ "5 1 4\n12 6 11 9 1\n", "3 1 2\n1 2 3\n", "1 1 1\n1\n" ]
[ "0 2 3 1 1 ", "1 0 1 ", "0 " ]
none
1,000
[ { "input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1 " }, { "input": "3 1 2\n1 2 3", "output": "1 0 1 " }, { "input": "1 1 1\n1", "output": "0 " }, { "input": "1 1 1000000000\n1000000000", "output": "0 " }, { "input": "1 1 1000000000\n999999999", "output": "9...
1,398,169,740
2,147,483,647
Python 3
OK
TESTS
47
327
9,625,600
import math n,a,b=map(int,input().split()) xlist=[int(x) for x in input().split()] savestring='' for i in range(n): maxmoney=math.floor(xlist[i]*a/b) saves=xlist[i]-math.ceil(maxmoney*b/a) savestring+=str(saves)+' ' print(savestring)
Title: Mashmokh and Tokens Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each...
```python import math n,a,b=map(int,input().split()) xlist=[int(x) for x in input().split()] savestring='' for i in range(n): maxmoney=math.floor(xlist[i]*a/b) saves=xlist[i]-math.ceil(maxmoney*b/a) savestring+=str(saves)+' ' print(savestring) ```
3
1,009
A
Game Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy ...
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the inp...
Print a single integer β€” the number of games Maxim will buy.
[ "5 4\n2 4 5 2 4\n5 3 4 6\n", "5 2\n20 40 50 20 40\n19 20\n", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n" ]
[ "3\n", "0\n", "4\n" ]
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
0
[ { "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3" }, { "input": "5 2\n20 40 50 20 40\n19 20", "output": "0" }, { "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4" }, { "input": "5 1\n1 1 1 1 1\n5", "output": "1" }, { "input": "5 1\n10 1 1 1 1\n...
1,564,741,525
2,147,483,647
Python 3
OK
TESTS
19
109
0
n,m = map(int, input().split()) li = list(map(int, input().split())) li2 = list(map(int, input().split())) c = 0 for i in li: c += (c < len(li2) and li2[c] >= i) print(c)
Title: Game Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ...
```python n,m = map(int, input().split()) li = list(map(int, input().split())) li2 = list(map(int, input().split())) c = 0 for i in li: c += (c < len(li2) and li2[c] >= i) print(c) ```
3
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≀<=*n*<=≀<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9",...
1,674,190,027
2,147,483,647
PyPy 3-64
OK
TESTS
47
122
0
str_num = input() store = ['1', '14', '141'] temp = "" found = False for i, n in enumerate(str_num): temp += n if temp == '1': if i < len(str_num) - 1 and str_num[i + 1] != '4': temp = "" elif temp == '14': if i < len(str_num) - 1 and str_num[i + 1] != '4': temp = "" elif temp ==...
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're ...
```python str_num = input() store = ['1', '14', '141'] temp = "" found = False for i, n in enumerate(str_num): temp += n if temp == '1': if i < len(str_num) - 1 and str_num[i + 1] != '4': temp = "" elif temp == '14': if i < len(str_num) - 1 and str_num[i + 1] != '4': temp = "" el...
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* β€” it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,548,417,071
2,147,483,647
Python 3
OK
TESTS
30
218
0
s = input() lw = 0 up = 0 for i in range(len(s)): if s[i].isupper(): up += 1 else: lw += 1 if up <= lw: print(s.lower()) else: print(s.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s = input() lw = 0 up = 0 for i in range(len(s)): if s[i].isupper(): up += 1 else: lw += 1 if up <= lw: print(s.lower()) else: print(s.upper()) ```
3.9455
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winnerΒ β€” Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100<=000)Β β€” the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D'Β β€” the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*...
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while DanikΒ β€” only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": ...
1,698,685,558
2,147,483,647
Python 3
OK
TESTS
25
46
102,400
n=int(input()) m=input() a=0 d=0 for i in range(n): if m[i]=="A": a+=1 else: d+=1 if a>d: print("Anton") elif a==d: print("Friendship") else: print("Danik")
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winnerΒ β€” Anton or Danik. None of the games ended with a tie. Now Anton wonders, w...
```python n=int(input()) m=input() a=0 d=0 for i in range(n): if m[i]=="A": a+=1 else: d+=1 if a>d: print("Anton") elif a==d: print("Friendship") else: print("Danik") ```
3
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number β€” the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,692,158,586
2,147,483,647
PyPy 3
OK
TESTS
27
109
0
a = input() if a=='{}': print(0) else: print(abs(len(set(a))-4))
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python a = input() if a=='{}': print(0) else: print(abs(len(set(a))-4)) ```
3
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercise...
The first line contains integer *n* (1<=≀<=*n*<=≀<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=25) β€” the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos...
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 ...
1,655,064,780
2,147,483,647
Python 3
OK
TESTS
61
92
0
u = int(input()) u2 = input() u2 = u2.split(" ") ch = 0 ba = 0 bi = 0 for i in range(0,u,3): ch += int(u2[i]) for i in range(1,u,3): bi += int(u2[i]) for i in range(2,u,3): ba += int(u2[i]) if (ch >= ba and ch > bi) or (ch >= bi and ch > ba) : print('chest') elif (ba >= ch and ba > bi) or (ba >= bi and ...
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ...
```python u = int(input()) u2 = input() u2 = u2.split(" ") ch = 0 ba = 0 bi = 0 for i in range(0,u,3): ch += int(u2[i]) for i in range(1,u,3): bi += int(u2[i]) for i in range(2,u,3): ba += int(u2[i]) if (ch >= ba and ch > bi) or (ch >= bi and ch > ba) : print('chest') elif (ba >= ch and ba > bi) or (ba ...
3
0
none
none
none
0
[ "none" ]
null
null
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limeligh...
The first line of the input contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=100<=000)Β β€” the number of cows and the length of Farmer John's nap, respectively.
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps.
[ "5 2\n", "1 10\n" ]
[ "10\n", "0\n" ]
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible mess...
0
[ { "input": "5 2", "output": "10" }, { "input": "1 10", "output": "0" }, { "input": "100000 2", "output": "399990" }, { "input": "1 1", "output": "0" }, { "input": "8 3", "output": "27" }, { "input": "7 1", "output": "11" }, { "input": "1000...
1,465,011,859
2,147,483,647
PyPy 3
OK
TESTS
92
264
26,419,200
n, k = [int(i) for i in input().split()] cow = [(i+1) for i in range(n)] j = 0 q = n - 1 ans = 0 while j < q and k > 0: ans += (2*n-3) n -= 2 j += 1 q -= 1 k -= 1 print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However,...
```python n, k = [int(i) for i in input().split()] cow = [(i+1) for i in range(n)] j = 0 q = n - 1 ans = 0 while j < q and k > 0: ans += (2*n-3) n -= 2 j += 1 q -= 1 k -= 1 print(ans) ```
3
417
A
Elimination
PROGRAMMING
1,500
[ "dp", "implementation", "math" ]
null
null
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of *c* problems, the winners of the round are the first *n* people in the rating list....
The first line contains two integers *c* and *d* (1<=≀<=*c*,<=*d*<=≀<=100)Β β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). Finally, the third line contains an integer *k* (1<=≀<=*k*<=≀<=100)Β β€” the number of the pre...
In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare.
[ "1 10\n7 2\n1\n", "2 2\n2 1\n2\n" ]
[ "2\n", "0\n" ]
none
500
[ { "input": "1 10\n7 2\n1", "output": "2" }, { "input": "2 2\n2 1\n2", "output": "0" }, { "input": "8 9\n2 2\n3", "output": "8" }, { "input": "5 5\n8 8\n7", "output": "40" }, { "input": "1 8\n8 10\n8", "output": "9" }, { "input": "5 7\n9 1\n8", "out...
1,547,381,107
2,147,483,647
Python 3
OK
TESTS
48
109
0
c,d = list(map(int, input().split(" "))) n, m = list(map(int, input().split(" "))) k = int(input()) mini = n*m-k if mini < 1: print(0) elif d * n <= c: # easier one at a time print(d*mini) else: total = (mini // n) * c mini = mini % n total += min(c, d*mini) print(total)
Title: Elimination Time Limit: None seconds Memory Limit: None megabytes Problem Description: The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination round...
```python c,d = list(map(int, input().split(" "))) n, m = list(map(int, input().split(" "))) k = int(input()) mini = n*m-k if mini < 1: print(0) elif d * n <= c: # easier one at a time print(d*mini) else: total = (mini // n) * c mini = mini % n total += min(c, d*mini) print(total) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* β€” it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,646,068,063
2,147,483,647
Python 3
OK
TESTS
30
62
0
a=str(input()) small=0 upper=0 for i in a: if i.islower()== True: small+=1 elif i.isupper() == True: upper+=1 if small>=upper: print(a.lower()) else: print(a.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python a=str(input()) small=0 upper=0 for i in a: if i.islower()== True: small+=1 elif i.isupper() == True: upper+=1 if small>=upper: print(a.lower()) else: print(a.upper()) ```
3.9845
609
B
The Best Gift
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find th...
The first line contains two positive integers *n* and *m* (2<=≀<=*n*<=≀<=2Β·105,<=2<=≀<=*m*<=≀<=10) β€” the number of books in the bookstore and the number of genres. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≀<=*a**i*<=≀<=*m*) equals the genre of the *i*-th book. It is guaranteed ...
Print the only integer β€” the number of ways in which Jack can choose books. It is guaranteed that the answer doesn't exceed the value 2Β·109.
[ "4 3\n2 1 3 1\n", "7 4\n4 2 3 1 2 4 3\n" ]
[ "5\n", "18\n" ]
The answer to the first test sample equals 5 as Sasha can choose: 1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
0
[ { "input": "4 3\n2 1 3 1", "output": "5" }, { "input": "7 4\n4 2 3 1 2 4 3", "output": "18" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "3 2\n1 2 2", "output": "2" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "45" }, { "input": "9 2...
1,620,196,022
2,147,483,647
PyPy 3
OK
TESTS
42
218
12,492,800
n,m=map(int,input().split()) a=list(map(int,input().split())) result=0 for i in range(m): count=a.count(i+1) result+=count*(n-count) print(result//2)
Title: The Best Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack deci...
```python n,m=map(int,input().split()) a=list(map(int,input().split())) result=0 for i in range(m): count=a.count(i+1) result+=count*(n-count) print(result//2) ```
3
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894"...
1,636,267,737
2,147,483,647
Python 3
OK
TESTS
37
46
4,300,800
n,k=[int(x) for x in input().split()] if n%k==0: print(((n//k)+1)*k) else: print(n+k-n%k)
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *...
```python n,k=[int(x) for x in input().split()] if n%k==0: print(((n//k)+1)*k) else: print(n+k-n%k) ```
3
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the h...
The first line of the input contains integers *n* and *k* (1<=≀<=*n*<=≀<=1.5Β·105,<=1<=≀<=*k*<=≀<=*n*) β€” the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≀<=*h**i*<=≀<=100), where *h**i* is the height of the *i*-th...
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "inp...
1,691,647,076
2,147,483,647
PyPy 3
OK
TESTS
51
140
13,414,400
n,k=map(int, input().split()) a=list(map(int, input().split())) b=[] b.append(0) i=0 while i<n: b.append(b[i]+a[i]) i+=1 # print(a) # print(b) s=sum(a)+1 # print(s) ind=1 i=k while i<n+1: if b[i]-b[i-k]<s: ind=i-k+1 s=b[i]-b[i-k] i+=1 print(ind)
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ...
```python n,k=map(int, input().split()) a=list(map(int, input().split())) b=[] b.append(0) i=0 while i<n: b.append(b[i]+a[i]) i+=1 # print(a) # print(b) s=sum(a)+1 # print(s) ind=1 i=k while i<n+1: if b[i]-b[i-k]<s: ind=i-k+1 s=b[i]-b[i-k] i+=1 print(ind) ```
3
743
C
Vladik and fractions
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "math", "number theory" ]
null
null
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form . Help Vladik with that, i.e for a given *n* find three distinct positive integers *x*, *y* and *z* such that . Because ...
The single line contains single integer *n* (1<=≀<=*n*<=≀<=104).
If the answer exists, print 3 distinct numbers *x*, *y* and *z* (1<=≀<=*x*,<=*y*,<=*z*<=≀<=109, *x*<=β‰ <=*y*, *x*<=β‰ <=*z*, *y*<=β‰ <=*z*). Otherwise print -1. If there are multiple answers, print any of them.
[ "3\n", "7\n" ]
[ "2 7 42\n", "7 8 56\n" ]
none
1,250
[ { "input": "3", "output": "2 7 42" }, { "input": "7", "output": "7 8 56" }, { "input": "2", "output": "2 3 6" }, { "input": "5", "output": "5 6 30" }, { "input": "4", "output": "4 5 20" }, { "input": "7", "output": "7 8 56" }, { "input": "8...
1,490,721,133
2,147,483,647
Python 3
OK
TESTS
62
62
4,608,000
a = int(input()) if a == 1: print(-1) else: print(a, a+1, a*(a+1))
Title: Vladik and fractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form . Help Vladik ...
```python a = int(input()) if a == 1: print(-1) else: print(a, a+1, a*(a+1)) ```
3
977
C
Less or Equal
PROGRAMMING
1,200
[ "sortings" ]
null
null
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$. Note that the sequence can contain equal elements. If there is no suc...
The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β€” the sequence itself.
Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$. If there is no such $x$, print "-1" (without quotes).
[ "7 4\n3 7 5 1 10 3 20\n", "7 2\n3 7 5 1 10 3 20\n" ]
[ "6", "-1\n" ]
In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$. In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ el...
0
[ { "input": "7 4\n3 7 5 1 10 3 20", "output": "5" }, { "input": "7 2\n3 7 5 1 10 3 20", "output": "-1" }, { "input": "1 0\n1", "output": "-1" }, { "input": "1 0\n2", "output": "1" }, { "input": "1 1\n1000000000", "output": "1000000000" }, { "input": "3 ...
1,695,090,095
2,147,483,647
PyPy 3-64
OK
TESTS
38
140
26,726,400
n,k = map(int, input().split()) a = list(map(int, input().split())) a.sort() if k == 0: print(a[0] - 1 if a[0] - 1 > 0 else -1) elif n == k: print(a[-1]) else: if a[k-1] < a[k]: print(a[k-1]) else: print(-1)
Title: Less or Equal Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are...
```python n,k = map(int, input().split()) a = list(map(int, input().split())) a.sort() if k == 0: print(a[0] - 1 if a[0] - 1 > 0 else -1) elif n == k: print(a[-1]) else: if a[k-1] < a[k]: print(a[k-1]) else: print(-1) ```
3
847
G
University Classes
PROGRAMMING
900
[ "implementation" ]
null
null
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the ...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of groups. Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones β€” the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot...
Print minimum number of rooms needed to hold all groups classes on Monday.
[ "2\n0101010\n1010101\n", "3\n0101011\n0011001\n0110111\n" ]
[ "1\n", "3\n" ]
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group. In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
0
[ { "input": "2\n0101010\n1010101", "output": "1" }, { "input": "3\n0101011\n0011001\n0110111", "output": "3" }, { "input": "1\n0111000", "output": "1" }, { "input": "1\n0000000", "output": "0" }, { "input": "1\n1111111", "output": "1" }, { "input": "2\n...
1,544,797,451
2,147,483,647
Python 3
OK
TESTS
21
124
102,400
print(max([sum(x) for x in list(zip(*[list(map(int,list(input()))) for x in range(int(input()))]))]))
Title: University Classes Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known ...
```python print(max([sum(x) for x in list(zip(*[list(map(int,list(input()))) for x in range(int(input()))]))])) ```
3
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex...
The first line contains a single number *n* (2<=≀<=*n*<=≀<=1000) β€” the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≀<=*a**i*,<=*b**i*<=≀<=1000) β€” the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ...
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1...
1,693,630,322
2,147,483,647
PyPy 3-64
OK
TESTS
71
186
1,638,400
# Read the input values n = int(input()) passenger_capacity = 0 max_capacity = 0 # Simulate the process at each stop for _ in range(n): passengers_exit, passengers_enter = map(int, input().split()) passenger_capacity = passenger_capacity - passengers_exit + passengers_enter max_capacity = max(max_...
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ...
```python # Read the input values n = int(input()) passenger_capacity = 0 max_capacity = 0 # Simulate the process at each stop for _ in range(n): passengers_exit, passengers_enter = map(int, input().split()) passenger_capacity = passenger_capacity - passengers_exit + passengers_enter max_capacity ...
3
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,680,233,392
2,147,483,647
PyPy 3-64
OK
TESTS
71
124
0
def st():return str(input()) def ls():return list(map(int, input().split())) def mx(a):return max(a) def it():return int(input()) def mn(a):return min(a) def yes():return print('YES') def no():return print('NO') def re(a):return range(a) def pr(a):return print(a) def prs(a):return print(str(a)) def mapa():ret...
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 def st():return str(input()) def ls():return list(map(int, input().split())) def mx(a):return max(a) def it():return int(input()) def mn(a):return min(a) def yes():return print('YES') def no():return print('NO') def re(a):return range(a) def pr(a):return print(a) def prs(a):return print(str(a)) def ...
3.969
427
A
Police Recruits
PROGRAMMING
800
[ "implementation" ]
null
null
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
The first line of input will contain an integer *n*Β (1<=≀<=*n*<=≀<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ...
Print a single integer, the number of crimes which will go untreated.
[ "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n" ]
[ "2\n", "1\n", "8\n" ]
Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c...
500
[ { "input": "3\n-1 -1 1", "output": "2" }, { "input": "8\n1 -1 1 -1 -1 1 1 1", "output": "1" }, { "input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "output": "8" }, { "input": "7\n-1 -1 1 1 -1 -1 1", "output": "2" }, { "input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ...
1,677,687,333
2,147,483,647
PyPy 3-64
OK
TESTS
63
77
13,721,600
dl = int(input()) lista = input().split() for i in range(dl): lista[i] = int(lista[i]) wynik = 0 dostepni = 0 for i in range(dl): if lista[i] > 0: dostepni += lista[i] else: if dostepni <= 0: wynik += 1 else: dostepni -= 1 print(wynik)
Title: Police Recruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of...
```python dl = int(input()) lista = input().split() for i in range(dl): lista[i] = int(lista[i]) wynik = 0 dostepni = 0 for i in range(dl): if lista[i] > 0: dostepni += lista[i] else: if dostepni <= 0: wynik += 1 else: dostepni -= 1 print(wynik) ```
3
580
B
Kefa and Company
PROGRAMMING
1,500
[ "binary search", "sortings", "two pointers" ]
null
null
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend...
The first line of the input contains two space-separated integers, *n* and *d* (1<=≀<=*n*<=≀<=105, ) β€” the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively. Next *n* lines contain the descriptions of Kefa's friends, the (*i*<=+<=1)-th line contains the...
Print the maximum total friendship factir that can be reached.
[ "4 5\n75 5\n0 100\n150 20\n75 1\n", "5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n" ]
[ "100\n", "111\n" ]
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse. In the second sample test we can take all the friends.
1,250
[ { "input": "4 5\n75 5\n0 100\n150 20\n75 1", "output": "100" }, { "input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "output": "111" }, { "input": "1 1000000000\n15 12", "output": "12" }, { "input": "5 1\n5 9\n2 10\n8 5\n18 12\n1 1", "output": "12" }, { "input": "3...
1,695,144,959
2,147,483,647
PyPy 3-64
OK
TESTS
35
514
16,998,400
import sys input = sys.stdin.readline n, d = map(int,input().split()) ls = [] for _ in range(n) : ls.append(list(map(int,input().split()))) ls.sort() i, j = 0, 0 sm, mx = 0, 0 while i < n : while i < n and (ls[i][0]-ls[j][0]+1) <= d : sm += ls[i][1] i += 1 mx = max(mx,sm) s...
Title: Kefa and Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the a...
```python import sys input = sys.stdin.readline n, d = map(int,input().split()) ls = [] for _ in range(n) : ls.append(list(map(int,input().split()))) ls.sort() i, j = 0, 0 sm, mx = 0, 0 while i < n : while i < n and (ls[i][0]-ls[j][0]+1) <= d : sm += ls[i][1] i += 1 mx = max(mx,...
3
58
B
Coins
PROGRAMMING
1,300
[ "greedy" ]
B. Coins
2
256
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d...
The first and only line contains an integer *n* (1<=≀<=*n*<=≀<=106) which represents the denomination of the most expensive coin.
Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coin...
[ "10\n", "4\n", "3\n" ]
[ "10 5 1\n", "4 2 1\n", "3 1\n" ]
none
1,000
[ { "input": "10", "output": "10 5 1" }, { "input": "4", "output": "4 2 1" }, { "input": "3", "output": "3 1" }, { "input": "2", "output": "2 1" }, { "input": "5", "output": "5 1" }, { "input": "6", "output": "6 3 1" }, { "input": "7", "o...
1,608,587,123
2,147,483,647
Python 3
OK
TESTS
50
434
0
x=int(input("")) ch=x print(x) for i in range((ch//2),0,-1): if ch % i ==0 : print(i) ch=i
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following...
```python x=int(input("")) ch=x print(x) for i in range((ch//2),0,-1): if ch % i ==0 : print(i) ch=i ```
3.8915
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest in...
The only line of the input contains two integers *a* and *b* (1<=≀<=*a*<=≀<=*b*<=≀<=10100).
Output one integerΒ β€” greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000...
1,653,568,249
2,147,483,647
Python 3
OK
TESTS
28
46
0
a,b = input().split() c=1 if a==b: print(a) else: print(c)
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre...
```python a,b = input().split() c=1 if a==b: print(a) else: print(c) ```
3
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: -...
The single line contains six space-separated integers *l**i* (1<=≀<=*l**i*<=≀<=9) β€” the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wΔ±thout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "...
1,418,013,467
2,147,483,647
Python 3
OK
TESTS
29
62
0
def main(): l = [0] * 10 for x in map(int, input().split()): l[x] += 1 l.sort() x = l[9] * 3 + l[8] if x in (18, 14): print('Elephant') elif x in (16, 13): print('Bear') else: print('Alien') if __name__ == '__main__': main()
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an...
```python def main(): l = [0] * 10 for x in map(int, input().split()): l[x] += 1 l.sort() x = l[9] * 3 + l[8] if x in (18, 14): print('Elephant') elif x in (16, 13): print('Bear') else: print('Alien') if __name__ == '__main__': main() ```
3
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "in...
1,619,584,249
2,147,483,647
Python 3
OK
TESTS
58
77
0
N=input() S="" N=N.lower() A=0 for i in range(len(N)): if(N[i]=="h"): S=S+N[i] A=i break for i in range(A+1,len(N)): if(N[i]=="e"): S=S+N[i] A=i break for i in range(A+1,len(N)): if(N[i]=="i"): S=S+N[i] A=i break for i in range(A+1,len...
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ...
```python N=input() S="" N=N.lower() A=0 for i in range(len(N)): if(N[i]=="h"): S=S+N[i] A=i break for i in range(A+1,len(N)): if(N[i]=="e"): S=S+N[i] A=i break for i in range(A+1,len(N)): if(N[i]=="i"): S=S+N[i] A=i break for i in ran...
3
46
C
Hamsters and Tigers
PROGRAMMING
1,600
[ "two pointers" ]
C. Hamsters and Tigers
2
256
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number *n* (2<=≀<=*n*<=≀<=1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of *n* symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
[ "3\nHTH\n", "9\nHTHTHTHHT\n" ]
[ "0\n", "2\n" ]
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
0
[ { "input": "3\nHTH", "output": "0" }, { "input": "9\nHTHTHTHHT", "output": "2" }, { "input": "2\nTH", "output": "0" }, { "input": "4\nHTTH", "output": "0" }, { "input": "4\nHTHT", "output": "1" }, { "input": "7\nTTTHTTT", "output": "0" }, { ...
1,687,898,287
2,147,483,647
PyPy 3-64
OK
TESTS
27
248
8,601,600
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict N = int(input()) S = [c for c in input()] ans = float("inf") for _ in range(N): SS = S[::] lib = defaultdict(list) for i in range(N): lib[S[i]].append(i) cnt = 0 for i in ...
Title: Hamsters and Tigers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap ...
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict N = int(input()) S = [c for c in input()] ans = float("inf") for _ in range(N): SS = S[::] lib = defaultdict(list) for i in range(N): lib[S[i]].append(i) cnt = 0 ...
3.921978
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,512,691,539
2,147,483,647
Python 3
OK
TESTS
102
77
5,529,600
L1=input() L2=input() res="" for i in range(len(L1)): if L1[i]!=L2[i]: res+="1" else: res+="0" print(res)
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 L1=input() L2=input() res="" for i in range(len(L1)): if L1[i]!=L2[i]: res+="1" else: res+="0" print(res) ```
3.97045
946
C
String Transformation
PROGRAMMING
1,300
[ "greedy", "strings" ]
null
null
You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number...
The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≀<=|*s*|<=≀<=105) small english letters.
If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print Β«-1Β» (without quotes).
[ "aacceeggiikkmmooqqssuuwwyy\n", "thereisnoanswer\n" ]
[ "abcdefghijklmnopqrstuvwxyz\n", "-1\n" ]
none
0
[ { "input": "aacceeggiikkmmooqqssuuwwyy", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "thereisnoanswer", "output": "-1" }, { "input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs", "output": "-1" }, { "input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaen...
1,601,115,203
803
PyPy 3
OK
TESTS
102
155
4,096,000
import sys s = list(input()) cc = 97 for i in range(len(s)): if cc >= ord(s[i]): s[i] = chr(cc) cc += 1 if cc > 122: print(''.join(s)) break else: print(-1)
Title: String Transformation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be rep...
```python import sys s = list(input()) cc = 97 for i in range(len(s)): if cc >= ord(s[i]): s[i] = chr(cc) cc += 1 if cc > 122: print(''.join(s)) break else: print(-1) ```
3
811
A
Vladik and Courtesy
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving eac...
Single line of input data contains two space-separated integers *a*, *b* (1<=≀<=*a*,<=*b*<=≀<=109) β€” number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
[ "1 1\n", "7 6\n" ]
[ "Valera\n", "Vladik\n" ]
Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e...
500
[ { "input": "1 1", "output": "Valera" }, { "input": "7 6", "output": "Vladik" }, { "input": "25 38", "output": "Vladik" }, { "input": "8311 2468", "output": "Valera" }, { "input": "250708 857756", "output": "Vladik" }, { "input": "957985574 24997558", ...
1,495,880,698
2,998
Python 3
OK
TESTS
42
77
0
# -*- coding: utf-8 -*- from sys import stdin def regalar_dulces(dulces_vladik, dulces_valera): cantidad_dulces = 1 dona_vladik = True dona_valera = False while True: if dona_vladik is True: if dulces_vladik >= cantidad_dulces: dulces_vladik -= cantidad_dulces ...
Title: Vladik and Courtesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla...
```python # -*- coding: utf-8 -*- from sys import stdin def regalar_dulces(dulces_vladik, dulces_valera): cantidad_dulces = 1 dona_vladik = True dona_valera = False while True: if dona_vladik is True: if dulces_vladik >= cantidad_dulces: dulces_vladik -= cantidad_d...
3
1,006
B
Polycarp's Practice
PROGRAMMING
1,200
[ "greedy", "implementation", "sortings" ]
null
null
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann...
The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) β€” the number of problems and the number of days, respectively. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) β€” difficulties of problems in Polycarp's list, in the order they are p...
In the first line of the output print the maximum possible total profit. In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible ...
[ "8 3\n5 4 2 6 5 1 9 2\n", "5 1\n1 1 1 1 1\n", "4 2\n1 2000 2000 2\n" ]
[ "20\n3 2 3", "1\n5\n", "4000\n2 2\n" ]
The first example is described in the problem statement. In the second example there is only one possible distribution. In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$.
0
[ { "input": "8 3\n5 4 2 6 5 1 9 2", "output": "20\n4 1 3" }, { "input": "5 1\n1 1 1 1 1", "output": "1\n5" }, { "input": "4 2\n1 2000 2000 2", "output": "4000\n2 2" }, { "input": "1 1\n2000", "output": "2000\n1" }, { "input": "1 1\n1234", "output": "1234\n1" ...
1,595,831,570
2,147,483,647
PyPy 3
OK
TESTS
37
156
23,449,600
z,zz=input,lambda:map(int,z().split());n,k=zz() l=sorted(zip(zz(),range(n)))[-k:] print(sum(i[0] for i in l)) p=sorted(i[1] for i in l)+[n];p[0]=0 for x,y in zip(p,p[1:]): print(y-x,end=' ')
Title: Polycarp's Practice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least...
```python z,zz=input,lambda:map(int,z().split());n,k=zz() l=sorted(zip(zz(),range(n)))[-k:] print(sum(i[0] for i in l)) p=sorted(i[1] for i in l)+[n];p[0]=0 for x,y in zip(p,p[1:]): print(y-x,end=' ') ```
3
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ—<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input...
1,628,868,384
2,147,483,647
PyPy 3
OK
TESTS
80
218
21,708,800
n = int(input()) arr = list(map(int, input().split())) mx = -1 for i in range(n): j = i-1 last=arr[i] p=0 while j>=0 and arr[j]<=last: last=arr[j] j-=1 p+=1 j=i+1 last=arr[i] while j<n and arr[j]<=last: last = arr[j] j+=1 p +=...
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ—<=*n* in size, when viewed from above. This rectangle is divided into *...
```python n = int(input()) arr = list(map(int, input().split())) mx = -1 for i in range(n): j = i-1 last=arr[i] p=0 while j>=0 and arr[j]<=last: last=arr[j] j-=1 p+=1 j=i+1 last=arr[i] while j<n and arr[j]<=last: last = arr[j] j+=1 ...
3.905064
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,579,930,588
2,147,483,647
Python 3
OK
TESTS
102
124
0
p=str(input()) q=str(input()) x="" for i in range(len(p)): if p[i]==q[i]: x=x+"0" else: x=x+"1" 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 p=str(input()) q=str(input()) x="" for i in range(len(p)): if p[i]==q[i]: x=x+"0" else: x=x+"1" print(x) ```
3.969
366
B
Dima and To-do List
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ...
The first line of the input contains two integers *n*,<=*k*Β (1<=≀<=*k*<=≀<=*n*<=≀<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*Β (1<=≀<=*a**i*<=≀<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task. It is guaranteed that *n*...
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
[ "6 2\n3 2 1 6 5 4\n", "10 5\n1 3 5 7 9 9 4 1 8 5\n" ]
[ "1\n", "3\n" ]
Explanation of the first example. If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. I...
1,000
[ { "input": "6 2\n3 2 1 6 5 4", "output": "1" }, { "input": "10 5\n1 3 5 7 9 9 4 1 8 5", "output": "3" }, { "input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 10\n8 4 5 7 6 9 2 2 3 5", "output": "7" }, { "input": "50 10\n1 2 3...
1,460,276,616
2,147,483,647
Python 3
OK
TESTS
36
171
7,065,600
n, k = list(map(int, input().split())) num = list(map(int, input().split())) dp = [0] * (2 * n) for i in range(n - 1, -1, -1): dp[i] = dp[i + k] + num[i] ans = 2**100 for i in range(0, k): ans = min(ans, dp[i]) print(dp.index(ans) + 1)
Title: Dima and To-do List Time Limit: None seconds Memory Limit: None megabytes Problem Description: You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything h...
```python n, k = list(map(int, input().split())) num = list(map(int, input().split())) dp = [0] * (2 * n) for i in range(n - 1, -1, -1): dp[i] = dp[i + k] + num[i] ans = 2**100 for i in range(0, k): ans = min(ans, dp[i]) print(dp.index(ans) + 1) ```
3
777
B
Game of Credit Cards
PROGRAMMING
1,300
[ "data structures", "dp", "greedy", "sortings" ]
null
null
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the number of digits in the cards Sherlock and Moriarty are going to use. The second line contains *n* digitsΒ β€” Sherlock's credit card number. The third line contains *n* digitsΒ β€” Moriarty's credit card number.
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
[ "3\n123\n321\n", "2\n88\n00\n" ]
[ "0\n2\n", "2\n0\n" ]
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
1,000
[ { "input": "3\n123\n321", "output": "0\n2" }, { "input": "2\n88\n00", "output": "2\n0" }, { "input": "1\n4\n5", "output": "0\n1" }, { "input": "1\n8\n7", "output": "1\n0" }, { "input": "2\n55\n55", "output": "0\n0" }, { "input": "3\n534\n432", "out...
1,617,742,766
2,147,483,647
PyPy 3
OK
TESTS
55
109
1,740,800
import sys import itertools import collections def rs(x=''): return sys.stdin.readline().strip() if len(x) == 0 else input(x).strip() def ri(x=''): return int(rs(x)) def rm(x=''): return map(str, rs(x).split()) def rl(x=''): return rs(x).split() def rmi(x=''): return map(int, rs(x).split()) def rli(x=''): ret...
Title: Game of Credit Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simpl...
```python import sys import itertools import collections def rs(x=''): return sys.stdin.readline().strip() if len(x) == 0 else input(x).strip() def ri(x=''): return int(rs(x)) def rm(x=''): return map(str, rs(x).split()) def rl(x=''): return rs(x).split() def rmi(x=''): return map(int, rs(x).split()) def rli(...
3
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors...
In the first line of input there is one integer $n$ ($0 \le n \le 6$)Β β€” the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ...
In the first line output one integer $m$ ($0 \le m \le 6$)Β β€” the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReal...
1,700,318,384
2,147,483,647
Python 3
OK
TESTS
64
46
0
a = int(input()) d = {"purple": "Power", "green": "Time", "blue": "Space", "orange": "Soul", "red": "Reality", "yellow": "Mind"} for i in range(0, a): b = input() del d[b] print(len(d)) for i in d: print(d[i])
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So...
```python a = int(input()) d = {"purple": "Power", "green": "Time", "blue": "Space", "orange": "Soul", "red": "Reality", "yellow": "Mind"} for i in range(0, a): b = input() del d[b] print(len(d)) for i in d: print(d[i]) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,679,491,395
2,147,483,647
Python 3
OK
TESTS
20
31
0
t=int(input()) def solve(): ch=input() if(len(ch)<=10): return ch else: return ch[0]+str(len(ch)-2)+ch[len(ch)-1] answer="" while(t!=0): answer+=solve()+"\n" t-=1 print(answer)
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 t=int(input()) def solve(): ch=input() if(len(ch)<=10): return ch else: return ch[0]+str(len(ch)-2)+ch[len(ch)-1] answer="" while(t!=0): answer+=solve()+"\n" t-=1 print(answer) ```
3.9845
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,678,362,466
2,147,483,647
PyPy 3-64
OK
TESTS
28
77
3,584,000
a,b=map(int,input().split()) for i in range(1,a+1): if i%2!=0:a='#' else: a='.' print(end=' '); if i%4==0:print('#',end='') for j in range(b-1): print(a,end='') if i%4!=0:print('#',end='') print('')
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 a,b=map(int,input().split()) for i in range(1,a+1): if i%2!=0:a='#' else: a='.' print(end=' '); if i%4==0:print('#',end='') for j in range(b-1): print(a,end='') if i%4!=0:print('#',end='') print('') ```
3
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
The only line contains an integer *n* (12<=≀<=*n*<=≀<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, ...
1,676,352,450
2,147,483,647
PyPy 3-64
OK
TESTS
33
62
1,331,200
def P(n): d = 2 if n<=1: return True while n % d != 0: d += 1 return d == n a = int(input()) for x in range(a//2+1): b = a - (x+1) c = a-b if P(b)==False and P(c)==False: print(b,c) break
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statemen...
```python def P(n): d = 2 if n<=1: return True while n % d != 0: d += 1 return d == n a = int(input()) for x in range(a//2+1): b = a - (x+1) c = a-b if P(b)==False and P(c)==False: print(b,c) break ```
3
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number β€” the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,686,604,863
2,147,483,647
Python 3
OK
TESTS
27
61
0
print(len(set((x := input()).strip('{}').split(', '))) - (x == '{}'))
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python print(len(set((x := input()).strip('{}').split(', '))) - (x == '{}')) ```
3
501
A
Contest
PROGRAMMING
900
[ "implementation" ]
null
null
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ...
The first line contains four integers *a*, *b*, *c*, *d* (250<=≀<=*a*,<=*b*<=≀<=3500, 0<=≀<=*c*,<=*d*<=≀<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round).
Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.
[ "500 1000 20 30\n", "1000 1000 1 1\n", "1500 1000 176 177\n" ]
[ "Vasya\n", "Tie\n", "Misha\n" ]
none
500
[ { "input": "500 1000 20 30", "output": "Vasya" }, { "input": "1000 1000 1 1", "output": "Tie" }, { "input": "1500 1000 176 177", "output": "Misha" }, { "input": "1500 1000 74 177", "output": "Misha" }, { "input": "750 2500 175 178", "output": "Vasya" }, { ...
1,584,711,898
2,147,483,647
PyPy 3
OK
TESTS
40
155
0
a,b,c,d=map(int,input().split()) x=max((3*a//10),(a-(a*c//250))) y=max((3*b//10),(b-(b*d//250))) if(x>y): print("Misha") elif(x==y): print("Tie") elif(y>x): print("Vasya")
Title: Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t...
```python a,b,c,d=map(int,input().split()) x=max((3*a//10),(a-(a*c//250))) y=max((3*b//10),(b-(b*d//250))) if(x>y): print("Misha") elif(x==y): print("Tie") elif(y>x): print("Vasya") ```
3
174
A
Problem About Equation
PROGRAMMING
1,100
[ "math" ]
null
null
A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same. Polycarpus has already began the...
The first line contains a pair of integers *n*, *b* (2<=≀<=*n*<=≀<=100,<=1<=≀<=*b*<=≀<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=100), where *a**i* is the ...
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus ...
[ "5 50\n1 2 3 4 5\n", "2 2\n1 100\n" ]
[ "12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n", "-1\n" ]
none
500
[ { "input": "5 50\n1 2 3 4 5", "output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000" }, { "input": "2 2\n1 100", "output": "-1" }, { "input": "2 2\n1 1", "output": "1.000000\n1.000000" }, { "input": "3 2\n1 2 1", "output": "1.000000\n0.000000\n1.000000" }, { ...
1,557,809,595
2,147,483,647
Python 3
OK
TESTS
54
248
0
N, S = map(int, input().split()) A = list(map(int, input().split())) ave = (S + sum(A)) / N ans = [] for a in A: if a > ave: ans.append(-1) break else: ans.append(ave - a) if ans[-1] == -1: print(-1) else: for a in ans: print("%.6f" ...
Title: Problem About Equation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In...
```python N, S = map(int, input().split()) A = list(map(int, input().split())) ave = (S + sum(A)) / N ans = [] for a in A: if a > ave: ans.append(-1) break else: ans.append(ave - a) if ans[-1] == -1: print(-1) else: for a in ans: pri...
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*Β·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≀<=<=*k*,<=*w*<=<=≀<=<=1000, 0<=≀<=*n*<=≀<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer β€” the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }...
1,696,136,518
2,147,483,647
PyPy 3-64
OK
TESTS
15
62
0
k,n,w = map(int,input().split()) c = k*(w*(w+1)//2) if c <=n: print(0) else: print(abs(n-c))
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*Β·*k* dollars for the *i*-th banana). He h...
```python k,n,w = map(int,input().split()) c = k*(w*(w+1)//2) if c <=n: print(0) else: print(abs(n-c)) ```
3
35
A
Shell Game
PROGRAMMING
1,000
[ "implementation" ]
A. Shell Game
2
64
Today the Β«ZΒ» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so ...
The first input line contains an integer from 1 to 3 β€” index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 β€” indexes of the cups which the performer shuffled this time. The cups are numbered...
In the first line output an integer from 1 to 3 β€” index of the cup which will have the ball after all the shuffles.
[ "1\n1 2\n2 1\n2 1\n", "1\n2 1\n3 1\n1 3\n" ]
[ "2\n", "2\n" ]
none
500
[ { "input": "1\n1 2\n2 1\n2 1", "output": "2" }, { "input": "1\n2 1\n3 1\n1 3", "output": "2" }, { "input": "3\n3 1\n2 1\n1 2", "output": "1" }, { "input": "1\n1 3\n1 2\n2 3", "output": "2" }, { "input": "3\n3 2\n3 1\n3 1", "output": "2" }, { "input": "...
1,648,660,406
2,147,483,647
Python 3
OK
TESTS
20
92
0
path = 'input.txt' readFile = open(path, 'r') pos = int(readFile.readline()) for i in range(3): cup1, cup2 = [int(item) for item in readFile.readline().split(' ')] if cup1 == pos: pos = cup2 elif cup2 == pos: pos = cup1 readFile.close() writeFile = open("output.txt", 'w') writeF...
Title: Shell Game Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Today the Β«ZΒ» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly put...
```python path = 'input.txt' readFile = open(path, 'r') pos = int(readFile.readline()) for i in range(3): cup1, cup2 = [int(item) for item in readFile.readline().split(' ')] if cup1 == pos: pos = cup2 elif cup2 == pos: pos = cup1 readFile.close() writeFile = open("output.txt", 'w...
3.977
777
A
Shell Game
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "math" ]
null
null
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess...
The first line of the input contains an integer *n* (1<=≀<=*n*<=≀<=2Β·109)Β β€” the number of movements made by the operator. The second line contains a single integer *x* (0<=≀<=*x*<=≀<=2)Β β€” the index of the shell where the ball was found after *n* movements.
Print one integer from 0 to 2Β β€” the index of the shell where the ball was initially placed.
[ "4\n2\n", "1\n1\n" ]
[ "1\n", "0\n" ]
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th...
500
[ { "input": "4\n2", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "2\n2", "output": "0" }, { "input": "3\n1", "output": "1" }, { "input": "3\n2", "output": "0" }, { "input": "3\n0", "output": "2" }, { "input": "2000000000\n...
1,573,723,457
2,147,483,647
Python 3
OK
TESTS
68
109
0
n=int(input()) x=int(input()) seq=[[0,1,2],[1,0,2],[1,2,0],[2,1,0],[2,0,1],[0,2,1]] p=n%6 print(seq[p][x])
Title: Shell Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben...
```python n=int(input()) x=int(input()) seq=[[0,1,2],[1,0,2],[1,2,0],[2,1,0],[2,0,1],[0,2,1]] p=n%6 print(seq[p][x]) ```
3
702
A
Maximum Increase
PROGRAMMING
800
[ "dp", "greedy", "implementation" ]
null
null
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109).
Print the maximum length of an increasing subarray of the given array.
[ "5\n1 7 2 11 15\n", "6\n100 100 100 100 100 100\n", "3\n1 2 3\n" ]
[ "3\n", "1\n", "3\n" ]
none
0
[ { "input": "5\n1 7 2 11 15", "output": "3" }, { "input": "6\n100 100 100 100 100 100", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n1000000000", "output": "1" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7...
1,679,585,705
2,147,483,647
Python 3
OK
TESTS
32
124
8,806,400
n = int(input()) entrada = input() arreglo = entrada.split() arreglo_ent = [] numero = float('inf') contador = 1 maximo = contador for i in range(n): arreglo_ent.append(int(arreglo[i])) for i in range(n): if(arreglo_ent[i] > numero): numero = arreglo_ent[i] contador += 1 else: ...
Title: Maximum Increase Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called...
```python n = int(input()) entrada = input() arreglo = entrada.split() arreglo_ent = [] numero = float('inf') contador = 1 maximo = contador for i in range(n): arreglo_ent.append(int(arreglo[i])) for i in range(n): if(arreglo_ent[i] > numero): numero = arreglo_ent[i] contador += 1 else...
3
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*...
The first line contains an integer *n*Β (1<=≀<=*n*<=≀<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n*Β (1<=≀<=*v**i*<=≀<=109) β€” costs of the stones. The third line contains an integer *m*Β (1<=≀<=*m*<=≀<=105) β€” the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t...
Print *m* lines. Each line must contain an integer β€” the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1...
1,647,261,092
2,147,483,647
PyPy 3
OK
TESTS
46
639
22,528,000
import sys input = sys.stdin.readline def solve(L, pref, sorty_pref, t, l, r): l -= 1 if t == 1: return pref[r] - pref[l] return sorty_pref[r] - sorty_pref[l] N = int(input()) L = list(map(int, input().split())) sorty_L = sorted(L) pref = [0] sorty_pref = [0] for i in range(N): pref.appe...
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s...
```python import sys input = sys.stdin.readline def solve(L, pref, sorty_pref, t, l, r): l -= 1 if t == 1: return pref[r] - pref[l] return sorty_pref[r] - sorty_pref[l] N = int(input()) L = list(map(int, input().split())) sorty_L = sorted(L) pref = [0] sorty_pref = [0] for i in range(N): ...
3
499
A
Watching a movie
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie...
The first line contains two space-separated integers *n*, *x* (1<=≀<=*n*<=≀<=50, 1<=≀<=*x*<=≀<=105) β€” the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains tw...
Output a single number β€” the answer to the problem.
[ "2 3\n5 6\n10 12\n", "1 1\n1 100000\n" ]
[ "6\n", "100000\n" ]
In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch th...
500
[ { "input": "2 3\n5 6\n10 12", "output": "6" }, { "input": "1 1\n1 100000", "output": "100000" }, { "input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53974" }, { "input": "1...
1,591,537,343
2,147,483,647
PyPy 3
OK
TESTS
41
140
0
n,x = map(int, input().split()) data = [] result = 0 for _ in range(n): data.append(list(map(int, input().split()))) for i in range(n): if i==0: result += (data[i][0]-1)%x else: result += (data[i][0]-data[i-1][1]-1)%x result += data[i][1]-data[i][0]+1 print(result)
Title: Watching a movie Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the pl...
```python n,x = map(int, input().split()) data = [] result = 0 for _ in range(n): data.append(list(map(int, input().split()))) for i in range(n): if i==0: result += (data[i][0]-1)%x else: result += (data[i][0]-data[i-1][1]-1)%x result += data[i][1]-data[i][0]+1 print(res...
3
700
A
As Fast As Possible
PROGRAMMING
1,900
[ "binary search", "math" ]
null
null
On vacations *n* pupils decided to go on excursion and gather all together. They need to overcome the path with the length *l* meters. Each of the pupils will go with the speed equal to *v*1. To get to the excursion quickly, it was decided to rent a bus, which has seats for *k* people (it means that it can't fit more t...
The first line of the input contains five positive integers *n*, *l*, *v*1, *v*2 and *k* (1<=≀<=*n*<=≀<=10<=000, 1<=≀<=*l*<=≀<=109, 1<=≀<=*v*1<=&lt;<=*v*2<=≀<=109, 1<=≀<=*k*<=≀<=*n*)Β β€” the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of ...
Print the real numberΒ β€” the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won't exceed 10<=-<=6.
[ "5 10 1 2 5\n", "3 6 1 2 1\n" ]
[ "5.0000000000\n", "4.7142857143\n" ]
In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.
500
[ { "input": "5 10 1 2 5", "output": "5.0000000000" }, { "input": "3 6 1 2 1", "output": "4.7142857143" }, { "input": "39 252 51 98 26", "output": "3.5344336938" }, { "input": "59 96 75 98 9", "output": "1.2315651330" }, { "input": "87 237 3 21 40", "output": "3...
1,656,584,579
2,147,483,647
Python 3
OK
TESTS
42
46
0
n,l,v,r,k=map(int,input().split()) n=(n+k-1)//k a=(n-1)*(r-v)/(v+r) print(l/r/(n-a)*(n+a))
Title: As Fast As Possible Time Limit: None seconds Memory Limit: None megabytes Problem Description: On vacations *n* pupils decided to go on excursion and gather all together. They need to overcome the path with the length *l* meters. Each of the pupils will go with the speed equal to *v*1. To get to the excursion...
```python n,l,v,r,k=map(int,input().split()) n=(n+k-1)//k a=(n-1)*(r-v)/(v+r) print(l/r/(n-a)*(n+a)) ```
3
556
A
Case of the Zeros and Ones
PROGRAMMING
900
[ "greedy" ]
null
null
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an...
First line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=2Β·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
[ "4\n1100\n", "5\n01010\n", "8\n11101111\n" ]
[ "0\n", "1\n", "6\n" ]
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like...
250
[ { "input": "4\n1100", "output": "0" }, { "input": "5\n01010", "output": "1" }, { "input": "8\n11101111", "output": "6" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "2" }, { "input"...
1,639,080,473
2,147,483,647
Python 3
OK
TESTS
49
62
204,800
length = int(input()) astring = input() one = astring.count("1") print(length - 2*min(length - one, one))
Title: Case of the Zeros and Ones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Cons...
```python length = int(input()) astring = input() one = astring.count("1") print(length - 2*min(length - one, one)) ```
3
910
A
The Way to Home
PROGRAMMING
800
[ "dfs and similar", "dp", "greedy", "implementation" ]
null
null
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* ...
The first line contains two integers *n* and *d* (2<=≀<=*n*<=≀<=100, 1<=≀<=*d*<=≀<=*n*<=-<=1) β€” the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ...
If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
[ "8 4\n10010101\n", "4 2\n1001\n", "8 4\n11100101\n", "12 3\n101111100101\n" ]
[ "2\n", "-1\n", "3\n", "4\n" ]
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a ...
500
[ { "input": "8 4\n10010101", "output": "2" }, { "input": "4 2\n1001", "output": "-1" }, { "input": "8 4\n11100101", "output": "3" }, { "input": "12 3\n101111100101", "output": "4" }, { "input": "5 4\n11011", "output": "1" }, { "input": "5 4\n10001", ...
1,588,907,977
2,147,483,647
Python 3
OK
TESTS
63
109
6,963,200
""" https://codeforces.com/problemset/problem/910/A Input n point that has to be reached d max length of jump s consisting of zeroes and ones 0 = no lily flower 1 = lily flower (frog can jump here) Output x min number of jumps needed to reach n -1 if n can't be reached """ n, d = map(int, input(...
Title: The Way to Home Time Limit: None seconds Memory Limit: None megabytes Problem Description: A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c...
```python """ https://codeforces.com/problemset/problem/910/A Input n point that has to be reached d max length of jump s consisting of zeroes and ones 0 = no lily flower 1 = lily flower (frog can jump here) Output x min number of jumps needed to reach n -1 if n can't be reached """ n, d = map(i...
3
0
none
none
none
0
[ "none" ]
null
null
There is a rectangular grid of *n* rows of *m* initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset of columns *C**i* are chosen. For each row *r* in *R**i* and each column *c* in *C**i*, the...
The first line contains two space-separated integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=50)Β β€” the number of rows and columns of the grid, respectively. Each of the following *n* lines contains a string of *m* characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desir...
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower).
[ "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n", "5 5\n..#..\n..#..\n#####\n..#..\n..#..\n", "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n" ]
[ "Yes\n", "No\n", "No\n" ]
For the first example, the desired setup can be produced by 3 operations, as is shown below. For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it w...
0
[ { "input": "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..", "output": "Yes" }, { "input": "5 5\n..#..\n..#..\n#####\n..#..\n..#..", "output": "No" }, { "input": "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#", "output": "No" }, { "input": "1 1\n#", "o...
1,523,876,368
2,147,483,647
Python 3
OK
TESTS
50
109
7,065,600
n,m = map(int, input().split()) x = [] for i in range(n): l = list(input()) x.append(l) for i in range(n): for j in range(n): if x[i] != x[j]: for z in range(m): if x[i][z] == x[j][z] == '#': print('No') exit() pri...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a rectangular grid of *n* rows of *m* initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset o...
```python n,m = map(int, input().split()) x = [] for i in range(n): l = list(input()) x.append(l) for i in range(n): for j in range(n): if x[i] != x[j]: for z in range(m): if x[i][z] == x[j][z] == '#': print('No') exi...
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,657,044,670
2,147,483,647
Python 3
OK
TESTS
60
46
0
n=int(input()) part=[] for i in range(n): x=input().split() part.append([x[0]]+list(map(int,x[1:]))) for i in part: if i[1]>=2400 and i[2]>i[1]: print("YES") break else: 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()) part=[] for i in range(n): x=input().split() part.append([x[0]]+list(map(int,x[1:]))) for i in part: if i[1]>=2400 and i[2]>i[1]: print("YES") break else: print("NO") ```
3
999
D
Equalize the Remainders
PROGRAMMING
1,900
[ "data structures", "greedy", "implementation" ]
null
null
You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$. In a single move, you can choose any position $i$ between $1$ and $n$ and increase $a_i$ by $1$. Let's calculate $c_r$ ($0 \le r \le m-1)$ β€” the number of elements havin...
The first line of input contains two integers $n$ and $m$ ($1 \le n \le 2 \cdot 10^5, 1 \le m \le n$). It is guaranteed that $m$ is a divisor of $n$. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$), the elements of the array.
In the first line, print a single integer β€” the minimum number of moves required to satisfy the following condition: for each remainder from $0$ to $m - 1$, the number of elements of the array having this remainder equals $\frac{n}{m}$. In the second line, print any array satisfying the condition and can be obtained f...
[ "6 3\n3 2 0 6 10 12\n", "4 2\n0 1 2 3\n" ]
[ "3\n3 2 0 7 10 14 \n", "0\n0 1 2 3 \n" ]
none
0
[ { "input": "6 3\n3 2 0 6 10 12", "output": "3\n3 2 0 7 10 14 " }, { "input": "4 2\n0 1 2 3", "output": "0\n0 1 2 3 " }, { "input": "1 1\n1000000000", "output": "0\n1000000000 " }, { "input": "6 3\n3 2 0 6 10 11", "output": "1\n3 2 0 7 10 11 " }, { "input": "100 25...
1,659,819,056
2,147,483,647
PyPy 3-64
OK
TESTS
47
389
53,862,400
from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) A = list(map(int, input().split())) target = n // m ...
Title: Equalize the Remainders Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$. In a single move, you can choose any position $i$ between $1$...
```python from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) A = list(map(int, input().split())) target...
3
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≀<=*n*<=≀<=10) β€” the number of rows and columns of the table.
Print a single line containing a positive integer *m* β€” the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,608,171,709
2,147,483,647
Python 3
OK
TESTS
10
108
307,200
n=int(input()) if n==1: print("1") else: dic=dict() L1=[1 for i in range(n)] dic[0]=L1 for i in range(1,n): L=[1 for i in range(n)] dic[i]=L for j in range(1,n): dic[i][j]=dic[i-1][j]+dic[i][j-1] print(max(dic[len(dic)-1]))
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n=int(input()) if n==1: print("1") else: dic=dict() L1=[1 for i in range(n)] dic[0]=L1 for i in range(1,n): L=[1 for i in range(n)] dic[i]=L for j in range(1,n): dic[i][j]=dic[i-1][j]+dic[i][j-1] print(max(dic[len(dic)-1])) ```
3
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≀<=*n*<=≀<=10) β€” the number of rows and columns of the table.
Print a single line containing a positive integer *m* β€” the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,649,780,326
2,147,483,647
PyPy 3-64
OK
TESTS
10
46
0
n=int(input()) if n<3: print(n) else: l=[] for i in range(n): p=[] for j in range(n): if i==0 or j==0: p.append(1) else: p.append(p[j-1]+l[i-1][j]) l.append(p) print(l[n-1][n-1])
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n=int(input()) if n<3: print(n) else: l=[] for i in range(n): p=[] for j in range(n): if i==0 or j==0: p.append(1) else: p.append(p[j-1]+l[i-1][j]) l.append(p) print(l[n-1][n-1]) ```
3
869
A
The Artful Expedient
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, deno...
The first line of input contains a positive integer *n* (1<=≀<=*n*<=≀<=2<=000) β€” the length of both sequences. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≀<=*x**i*<=≀<=2Β·106) β€” the integers finally chosen by Koyomi. The third line contains *n* space-separated integers *y*1,<=...
Output one line β€” the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
[ "3\n1 2 3\n4 5 6\n", "5\n2 4 6 8 10\n9 7 5 3 1\n" ]
[ "Karen\n", "Karen\n" ]
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number. In the second example, there are 16 such pairs, and Karen wins again.
500
[ { "input": "3\n1 2 3\n4 5 6", "output": "Karen" }, { "input": "5\n2 4 6 8 10\n9 7 5 3 1", "output": "Karen" }, { "input": "1\n1\n2000000", "output": "Karen" }, { "input": "2\n97153 2000000\n1999998 254", "output": "Karen" }, { "input": "15\n31 30 29 28 27 26 25 24...
1,507,577,167
2,147,483,647
Python 3
OK
TESTS
49
62
307,200
a = int(input()) b= input() c = input() print("Karen")
Title: The Artful Expedient Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive int...
```python a = int(input()) b= input() c = input() print("Karen") ```
3
32
A
Reconnaissance
PROGRAMMING
800
[ "brute force" ]
A. Reconnaissance
2
256
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som...
The first line contains two integers *n* and *d* (1<=≀<=*n*<=≀<=1000,<=1<=≀<=*d*<=≀<=109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 1...
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
[ "5 10\n10 20 50 60 65\n", "5 1\n55 30 29 31 55\n" ]
[ "6\n", "6\n" ]
none
500
[ { "input": "5 10\n10 20 50 60 65", "output": "6" }, { "input": "5 1\n55 30 29 31 55", "output": "6" }, { "input": "6 10\n4 6 4 1 9 3", "output": "30" }, { "input": "7 100\n19 1694 261 162 1 234 513", "output": "8" }, { "input": "8 42\n37 53 74 187 568 22 5 65", ...
1,558,289,754
2,147,483,647
Python 3
OK
TESTS
32
778
307,200
n,d = input().split() l = list(map(int,input().split())) l.sort() c=0 for i in range(0,len(l)): for j in range(i+1,len(l)): if l[j]-l[i] <= int(d): c=c+1 else:break print(2*c)
Title: Reconnaissance Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h...
```python n,d = input().split() l = list(map(int,input().split())) l.sort() c=0 for i in range(0,len(l)): for j in range(i+1,len(l)): if l[j]-l[i] <= int(d): c=c+1 else:break print(2*c) ```
3.804928
126
B
Password
PROGRAMMING
1,700
[ "binary search", "dp", "hashing", "string suffix structures", "strings" ]
null
null
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the...
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
[ "fixprefixsuffix\n", "abcdabc\n" ]
[ "fix", "Just a legend" ]
none
1,000
[ { "input": "fixprefixsuffix", "output": "fix" }, { "input": "abcdabc", "output": "Just a legend" }, { "input": "qwertyqwertyqwerty", "output": "qwerty" }, { "input": "papapapap", "output": "papap" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaa" }, { "...
1,538,008,691
2,147,483,647
Python 3
OK
TESTS
97
1,900
34,099,200
def kmpTable(s, n): res = [0]*n check_idx = 0 for i in range(1, n): while check_idx > 0 and s[check_idx] != s[i]: check_idx = res[check_idx-1] if s[check_idx] == s[i]: check_idx += 1 res[i] = check_idx return res s = input() n = len(s) kmp_ta...
Title: Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carve...
```python def kmpTable(s, n): res = [0]*n check_idx = 0 for i in range(1, n): while check_idx > 0 and s[check_idx] != s[i]: check_idx = res[check_idx-1] if s[check_idx] == s[i]: check_idx += 1 res[i] = check_idx return res s = input() n = len(...
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≀<=*a*,<=*b*<=≀<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }...
1,583,404,690
2,147,483,647
Python 3
OK
TESTS
43
248
307,200
def remove_zero(arg)->int: return int("".join(list(filter(lambda v : v!='0',str(arg))))) a = int(input()) b = int(input()) c = a + b # print(remove_zero(c) == remove_zero(a) + remove_zero(b)) if ( remove_zero(c) == remove_zero(a) + remove_zero(b) ): print("YES") pass else : print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu...
```python def remove_zero(arg)->int: return int("".join(list(filter(lambda v : v!='0',str(arg))))) a = int(input()) b = int(input()) c = a + b # print(remove_zero(c) == remove_zero(a) + remove_zero(b)) if ( remove_zero(c) == remove_zero(a) + remove_zero(b) ): print("YES") pass else : print("NO") ```
3.937428
452
A
Eevee
PROGRAMMING
1,000
[ "brute force", "implementation", "strings" ]
null
null
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Syl...
First line contains an integer *n* (6<=≀<=*n*<=≀<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).
Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).
[ "7\nj......\n", "7\n...feon\n", "7\n.l.r.o.\n" ]
[ "jolteon\n", "leafeon\n", "flareon\n" ]
Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
500
[ { "input": "7\n...feon", "output": "leafeon" }, { "input": "7\n.l.r.o.", "output": "flareon" }, { "input": "6\n.s..o.", "output": "espeon" }, { "input": "7\nglaceon", "output": "glaceon" }, { "input": "8\n.a.o.e.n", "output": "vaporeon" }, { "input": "...
1,406,484,628
4,228
Python 3
OK
TESTS
20
77
0
import re t = int(input()) pat = input(); pat ='^'+pat+'$' if re.match( pat, "vaporeon", re.M|re.I): print ("vaporeon") elif re.match( pat, "jolteon", re.M|re.I): print ("jolteon") elif re.match( pat, "flareon", re.M|re.I): print ("flareon") elif re.match( pat, "espeon", re.M|re.I): print ("esp...
Title: Eevee Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight...
```python import re t = int(input()) pat = input(); pat ='^'+pat+'$' if re.match( pat, "vaporeon", re.M|re.I): print ("vaporeon") elif re.match( pat, "jolteon", re.M|re.I): print ("jolteon") elif re.match( pat, "flareon", re.M|re.I): print ("flareon") elif re.match( pat, "espeon", re.M|re.I): p...
3
501
A
Contest
PROGRAMMING
900
[ "implementation" ]
null
null
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ...
The first line contains four integers *a*, *b*, *c*, *d* (250<=≀<=*a*,<=*b*<=≀<=3500, 0<=≀<=*c*,<=*d*<=≀<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round).
Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.
[ "500 1000 20 30\n", "1000 1000 1 1\n", "1500 1000 176 177\n" ]
[ "Vasya\n", "Tie\n", "Misha\n" ]
none
500
[ { "input": "500 1000 20 30", "output": "Vasya" }, { "input": "1000 1000 1 1", "output": "Tie" }, { "input": "1500 1000 176 177", "output": "Misha" }, { "input": "1500 1000 74 177", "output": "Misha" }, { "input": "750 2500 175 178", "output": "Vasya" }, { ...
1,615,490,352
2,147,483,647
Python 3
OK
TESTS
40
62
0
liste=input('').split() M = int(liste[0]) V = int(liste[1]) Mt = int(liste[2]) Vt = int(liste[3]) p1 = max(3/10*M, M -M/250*Mt) p2 = max(3/10*V, V -V/250*Vt) if p1>p2: print('Misha') elif p2>p1: print('Vasya') else: print('Tie')
Title: Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t...
```python liste=input('').split() M = int(liste[0]) V = int(liste[1]) Mt = int(liste[2]) Vt = int(liste[3]) p1 = max(3/10*M, M -M/250*Mt) p2 = max(3/10*V, V -V/250*Vt) if p1>p2: print('Misha') elif p2>p1: print('Vasya') else: print('Tie') ```
3
550
C
Divisibility by Eight
PROGRAMMING
1,500
[ "brute force", "dp", "math" ]
null
null
You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a no...
The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits.
Print "NO" (without quotes), if there is no such way to remove some digits from number *n*. Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8. If there are multiple possible answers, you may print any ...
[ "3454\n", "10\n", "111111\n" ]
[ "YES\n344\n", "YES\n0\n", "NO\n" ]
none
1,000
[ { "input": "3454", "output": "YES\n344" }, { "input": "10", "output": "YES\n0" }, { "input": "111111", "output": "NO" }, { "input": "8996988892", "output": "YES\n8" }, { "input": "5555555555", "output": "NO" }, { "input": "1", "output": "NO" }, ...
1,698,468,091
2,147,483,647
PyPy 3-64
OK
TESTS
73
77
1,945,600
n = list(input()) f = 0 s = len(n) for i in range (0, s): if f == 1: break if (int(n[i])) % 8 == 0: print ("YES") print (n[i]) f = 1 break for j in range (i + 1, s): if f == 1: break if (int(n[i]) * 10 + int(n[j])) % 8 == 0: print ("YES") print (n[i], end = "") print (n[j])...
Title: Divisibility by Eight Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of t...
```python n = list(input()) f = 0 s = len(n) for i in range (0, s): if f == 1: break if (int(n[i])) % 8 == 0: print ("YES") print (n[i]) f = 1 break for j in range (i + 1, s): if f == 1: break if (int(n[i]) * 10 + int(n[j])) % 8 == 0: print ("YES") print (n[i], end = "") pr...
3
814
B
An express train to reveries
PROGRAMMING
1,300
[ "constructive algorithms" ]
null
null
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege...
The first line of input contains a positive integer *n* (2<=≀<=*n*<=≀<=1<=000) β€” the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=*n*) β€” the sequence of colours in the firs...
Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
[ "5\n1 2 3 4 3\n1 2 5 4 5\n", "5\n4 4 2 3 1\n5 4 5 3 1\n", "4\n1 1 3 4\n1 4 3 4\n" ]
[ "1 2 5 4 3\n", "5 4 2 3 1\n", "1 2 3 4\n" ]
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
1,000
[ { "input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3" }, { "input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1" }, { "input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4" }, { "input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10", "output": "1 2 3 4 5 6 7 8 9...
1,584,474,018
2,147,483,647
PyPy 3
OK
TESTS
54
155
1,945,600
def solve(p, q): return sum(p[i] != q[i] for i in range(n)) == 1 n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] wa = [0 for i in range(n + 1)] wb = wa.copy() for i in a: wa[i] += 1 for i in b: wb[i] += 1 ta = [] for i in range(1, n + 1): i...
Title: An express train to reveries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her...
```python def solve(p, q): return sum(p[i] != q[i] for i in range(n)) == 1 n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] wa = [0 for i in range(n + 1)] wb = wa.copy() for i in a: wa[i] += 1 for i in b: wb[i] += 1 ta = [] for i in range(1, n + ...
3
667
A
Pouring Rain
PROGRAMMING
1,100
[ "geometry", "math" ]
null
null
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β€” when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything ...
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≀<=*d*,<=*h*,<=*v*,<=*e*<=≀<=104), where: - *d* β€” the diameter of your cylindrical cup, - *h* β€” the initial level of water in the cup, - *v* β€” the speed of drinking process from the cup in milliliters per second, - *e* β€” the growth ...
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number β€” time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is...
[ "1 2 3 100\n", "1 1 1 1\n" ]
[ "NO\n", "YES\n3.659792366325\n" ]
In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca...
500
[ { "input": "1 2 3 100", "output": "NO" }, { "input": "1 1 1 1", "output": "YES\n3.659792366325" }, { "input": "48 7946 7992 72", "output": "NO" }, { "input": "72 6791 8546 46", "output": "NO" }, { "input": "100 5635 9099 23", "output": "NO" }, { "input...
1,634,780,400
2,147,483,647
PyPy 3-64
OK
TESTS
23
62
28,364,800
from math import pi d,h,v,e = [int(i) for i in input().split()] v = v / (pi * (d/2)**2) if v <= e: print("NO") else: print("YES") print(h / (v-e))
Title: Pouring Rain Time Limit: None seconds Memory Limit: None megabytes Problem Description: A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β€” when it rains, you go on the street and stay silent for a moment, cont...
```python from math import pi d,h,v,e = [int(i) for i in input().split()] v = v / (pi * (d/2)**2) if v <= e: print("NO") else: print("YES") print(h / (v-e)) ```
3
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,676,392,216
2,147,483,647
Python 3
OK
TESTS
50
61
0
n,m=map(int,input().split()) arr=[] for i in range(n): input_arr=list(map(str,input().split())) arr=arr+input_arr c_ct=arr.count('C') m_ct=arr.count('M') y_ct=arr.count('Y') if c_ct != 0 or m_ct != 0 or y_ct != 0: print('#Color') else: print('#Black&White')
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()) arr=[] for i in range(n): input_arr=list(map(str,input().split())) arr=arr+input_arr c_ct=arr.count('C') m_ct=arr.count('M') y_ct=arr.count('Y') if c_ct != 0 or m_ct != 0 or y_ct != 0: print('#Color') else: print('#Black&White') ...
3
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote...
The first line contains integer *n* (1<=≀<=*n*<=≀<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≀<=*a**i*<=≀<=2000) where *a**i* is the rating of *i*-th student (1<=≀<=*i*<=≀<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first positi...
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4...
1,598,650,918
2,147,483,647
Python 3
OK
TESTS
36
124
307,200
n = int(input()) a = [int(s) for s in input().split(' ')] a_sorted = sorted(a, reverse=True) predictions = [] for score in a: predictions.append(str(a_sorted.index(score) + 1)) print(' '.join(predictions))
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the star...
```python n = int(input()) a = [int(s) for s in input().split(' ')] a_sorted = sorted(a, reverse=True) predictions = [] for score in a: predictions.append(str(a_sorted.index(score) + 1)) print(' '.join(predictions)) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,635,499,518
2,147,483,647
Python 3
OK
TESTS
30
92
4,505,600
k = input() n = len(k) i = 0 ans = "" while i < n: if k[i] == '.': ans += '0' i += 1 else: if k[i+1] == '.': ans += '1' else: ans += '2' i += 2 print(ans)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary ...
```python k = input() n = len(k) i = 0 ans = "" while i < n: if k[i] == '.': ans += '0' i += 1 else: if k[i+1] == '.': ans += '1' else: ans += '2' i += 2 print(ans) ```
3.968608
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,695,112,950
2,147,483,647
Python 3
OK
TESTS
30
92
0
s = input() a = s.upper() b = s.lower() n = 0 m = 0 v = 0 for i in range(len(a)): n = n + ord(a[i]) for i in range(len(b)): m = m + ord(b[i]) for i in range(len(s)): v = v + ord(s[i]) if abs(n-v) < abs(m-v): print(a) else: print(b)
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() a = s.upper() b = s.lower() n = 0 m = 0 v = 0 for i in range(len(a)): n = n + ord(a[i]) for i in range(len(b)): m = m + ord(b[i]) for i in range(len(s)): v = v + ord(s[i]) if abs(n-v) < abs(m-v): print(a) else: print(b) ```
3.977
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,606,492,981
2,147,483,647
Python 3
OK
TESTS
32
216
307,200
n=int(input()) a=list(map(int,input().split())) e=0 o=0 c=0 if(a[0]%2==0): e=1 else: o=1 if(a[1]%2==0): if(e==0): if(a[2]%2==0): print(1) else: print(2) if(e==1): c=1 else: if(o==0): if(a[2]%2!=0): print(1) ...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” t...
```python n=int(input()) a=list(map(int,input().split())) e=0 o=0 c=0 if(a[0]%2==0): e=1 else: o=1 if(a[1]%2==0): if(e==0): if(a[2]%2==0): print(1) else: print(2) if(e==1): c=1 else: if(o==0): if(a[2]%2!=0): prin...
3.945428
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,582,142,126
2,147,483,647
PyPy 3
OK
TESTS
37
310
4,608,000
bin_num=list(input()) if "0" in bin_num: for i in range(len(bin_num)): if bin_num[i]=="0": del bin_num[i] break print(''.join(bin_num)) else: del bin_num[0] print(''.join(bin_num))
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 bin_num=list(input()) if "0" in bin_num: for i in range(len(bin_num)): if bin_num[i]=="0": del bin_num[i] break print(''.join(bin_num)) else: del bin_num[0] print(''.join(bin_num)) ```
3
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s...
The first line contains two space separated integers *n*, *d* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*d*<=≀<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch...
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,597,667,933
2,147,483,647
Python 3
OK
TESTS
26
109
307,200
t = input() temp = t.split() n = int(temp[0]) d = int(temp[1]) songLenthList = [] songLength = input() List = songLength.split() songLenthList = [int(i) for i in List] devuBreaktime = (n-1)*10 devuTotalTime = devuBreaktime + sum(songLenthList) churuTime = d - devuTotalTime + devuBreaktime if (devuTotalTime >...
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit...
```python t = input() temp = t.split() n = int(temp[0]) d = int(temp[1]) songLenthList = [] songLength = input() List = songLength.split() songLenthList = [int(i) for i in List] devuBreaktime = (n-1)*10 devuTotalTime = devuBreaktime + sum(songLenthList) churuTime = d - devuTotalTime + devuBreaktime if (devuT...
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,601,386,910
2,147,483,647
Python 3
OK
TESTS
79
139
9,216,000
n = int(input()) arr = list(map(int,input().split())) if len(set(arr)) == 1 : print('YES') elif len(set(arr)) == 2 : print('YES') elif len(set(arr)) >= 4 : print('NO') else: st = set(arr) #print(st) arr2 = list(sorted(st)) #print(arr2) if (arr2[1] * 2 == arr2[0] + ar...
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 n = int(input()) arr = list(map(int,input().split())) if len(set(arr)) == 1 : print('YES') elif len(set(arr)) == 2 : print('YES') elif len(set(arr)) >= 4 : print('NO') else: st = set(arr) #print(st) arr2 = list(sorted(st)) #print(arr2) if (arr2[1] * 2 == ar...
3