contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
listlengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
690
F1
Tree of Life (easy)
PROGRAMMING
1,300
[]
null
null
Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of *n* points...
The first line of the input contains a single integer *n* – the number of vertices in the tree (1<=≤<=*n*<=≤<=10000). The vertices are labeled with the numbers from 1 to *n*. Then *n*<=-<=1 lines follow, each describing one edge using two space-separated numbers *a* *b* – the labels of the vertices connected by the edg...
Print one integer – the number of lifelines in the tree.
[ "4\n1 2\n1 3\n1 4\n", "5\n1 2\n2 3\n3 4\n3 5\n" ]
[ "3", "4" ]
In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5.
0
[ { "input": "4\n1 2\n1 3\n1 4", "output": "3" }, { "input": "5\n1 2\n2 3\n3 4\n3 5", "output": "4" }, { "input": "2\n1 2", "output": "0" }, { "input": "3\n2 1\n3 2", "output": "1" }, { "input": "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4", "output": "11" ...
1,573,650,920
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
n=int(input()) L=np.zeros((n,n),int) for k in range(n-1): a,b=map(int,input().split()) print(n-2)
Title: Tree of Life (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a r...
```python n=int(input()) L=np.zeros((n,n),int) for k in range(n-1): a,b=map(int,input().split()) print(n-2) ```
-1
678
B
The Same Calendar
PROGRAMMING
1,600
[ "implementation" ]
null
null
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ...
The only line contains integer *y* (1000<=≤<=*y*<=&lt;<=100'000) — the year of the calendar.
Print the only integer *y*' — the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar.
[ "2016\n", "2000\n", "50501\n" ]
[ "2044\n", "2028\n", "50507\n" ]
Today is Monday, the 13th of June, 2016.
0
[ { "input": "2016", "output": "2044" }, { "input": "2000", "output": "2028" }, { "input": "50501", "output": "50507" }, { "input": "1000", "output": "1006" }, { "input": "1900", "output": "1906" }, { "input": "1899", "output": "1905" }, { "i...
1,603,859,087
2,147,483,647
PyPy 3
OK
TESTS
40
140
0
def isLeapYear(year): return ((year % 400) == 0) or ( ((year % 4) == 0) and not ((year % 100) == 0) ) year = int(input()) newYear = year isLeap = isLeapYear(year) offset = 0 while True: #add year offset = (offset + 365 + (1 * isLeapYear(newYear))) % 7 newYear += 1 if offset == 0 and isLeap ...
Title: The Same Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful t...
```python def isLeapYear(year): return ((year % 400) == 0) or ( ((year % 4) == 0) and not ((year % 100) == 0) ) year = int(input()) newYear = year isLeap = isLeapYear(year) offset = 0 while True: #add year offset = (offset + 365 + (1 * isLeapYear(newYear))) % 7 newYear += 1 if offset == 0 a...
3
685
E
Travelling Through the Snow Queen's Kingdom
PROGRAMMING
2,800
[ "bitmasks", "brute force", "divide and conquer", "graphs" ]
null
null
Gerda is travelling to the palace of the Snow Queen. The road network consists of *n* intersections and *m* bidirectional roads. Roads are numbered from 1 to *m*. Snow Queen put a powerful spell on the roads to change the weather conditions there. Now, if Gerda steps on the road *i* at the moment of time less or equal...
The first line of the input contains integers *n*, *m* and *q* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*m*,<=*q*<=≤<=200<=000) — the number of intersections in the road network of Snow Queen's Kingdom, the number of roads and the number of queries you have to answer. The *i*-th of the following *m* lines contains the description o...
For each query print "Yes" (without quotes) if Gerda can be at the Snow Queen palace on time (not later than *r**i*) or "No" (without quotes) otherwise.
[ "5 4 6\n1 2\n2 3\n3 4\n3 5\n1 3 1 4\n1 3 2 4\n1 4 4 5\n1 4 4 1\n2 3 1 4\n2 2 2 3\n" ]
[ "Yes\nYes\nYes\nNo\nNo\nYes\n" ]
none
2,500
[]
1,689,634,398
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689634398.720702")# 1689634398.7207227
Title: Travelling Through the Snow Queen's Kingdom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerda is travelling to the palace of the Snow Queen. The road network consists of *n* intersections and *m* bidirectional roads. Roads are numbered from 1 to *m*. Snow Queen put a powerful s...
```python print("_RANDOM_GUESS_1689634398.720702")# 1689634398.7207227 ```
0
805
A
Fake NP
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times...
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.
[ "19 29\n", "3 6\n" ]
[ "2\n", "3\n" ]
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {...
500
[ { "input": "19 29", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "39 91", "output": "2" }, { "input": "76 134", "output": "2" }, { "input": "93 95", "output": "2" }, { "input": "17 35", "output": "2" }, { "input": "94 95",...
1,591,677,353
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
0
l,r=map(int,input().split(' ')) maxc=0 max=0 i=2 while(i<r): count=0 for j in range(l,r+1): if j%i==0: count+=1 if count>=maxc: maxc=count max=i i+=1 print(max)
Title: Fake NP Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the...
```python l,r=map(int,input().split(' ')) maxc=0 max=0 i=2 while(i<r): count=0 for j in range(l,r+1): if j%i==0: count+=1 if count>=maxc: maxc=count max=i i+=1 print(max) ```
0
411
A
Password Check
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
[ "abacaba\n", "X12345\n", "CONTEST_is_STARTED!!11\n" ]
[ "Too weak\n", "Too weak\n", "Correct\n" ]
none
0
[ { "input": "abacaba", "output": "Too weak" }, { "input": "X12345", "output": "Too weak" }, { "input": "CONTEST_is_STARTED!!11", "output": "Correct" }, { "input": "1zA__", "output": "Correct" }, { "input": "1zA_", "output": "Too weak" }, { "input": "zA_...
1,397,559,507
53,907
Python 3
WRONG_ANSWER
TESTS
0
46
0
n = input().strip() u = False l = False k = False for i in n: if i.isupper(): u = True elif i.islower(): l = True elif i.isdigit: k = True if u and k and l and len(n) > 5: print('Correct') else: print('Too weak!')
Title: Password Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password...
```python n = input().strip() u = False l = False k = False for i in n: if i.isupper(): u = True elif i.islower(): l = True elif i.isdigit: k = True if u and k and l and len(n) > 5: print('Correct') else: print('Too weak!') ```
0
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each frie...
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer — the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { ...
1,696,085,402
2,147,483,647
Python 3
OK
TESTS
27
62
0
n,k,l,c,d,p,nl,np = list(map(int,input().split())) k = k*l x = (c*d) # final amount of lime slice x = x//n y = (k//nl) #final amount of drink y = y//n z = (p//np) #final amount of salt z = z//n print(min(x,y,z))
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut...
```python n,k,l,c,d,p,nl,np = list(map(int,input().split())) k = k*l x = (c*d) # final amount of lime slice x = x//n y = (k//nl) #final amount of drink y = y//n z = (p//np) #final amount of salt z = z//n print(min(x,y,z)) ```
3
221
A
Little Elephant and Function
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works...
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists.
[ "1\n", "2\n" ]
[ "1 ", "2 1 " ]
none
500
[ { "input": "1", "output": "1 " }, { "input": "2", "output": "2 1 " }, { "input": "3", "output": "3 1 2 " }, { "input": "4", "output": "4 1 2 3 " }, { "input": "5", "output": "5 1 2 3 4 " }, { "input": "6", "output": "6 1 2 3 4 5 " }, { "inp...
1,624,377,773
2,147,483,647
Python 3
OK
TESTS
34
124
102,400
from collections import deque, defaultdict, Counter from itertools import product, groupby, permutations, combinations from math import gcd, floor, ceil n = int(input()) ans = [n] + [i for i in range(1, n)] print(*ans)
Title: Little Elephant and Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm...
```python from collections import deque, defaultdict, Counter from itertools import product, groupby, permutations, combinations from math import gcd, floor, ceil n = int(input()) ans = [n] + [i for i in range(1, n)] print(*ans) ```
3
979
A
Pizza, Pizza, Pizza!!!
PROGRAMMING
1,000
[ "math" ]
null
null
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele...
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
A single integer — the number of straight cuts Shiro needs.
[ "3\n", "4\n" ]
[ "2", "5" ]
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
500
[ { "input": "3", "output": "2" }, { "input": "4", "output": "5" }, { "input": "10", "output": "11" }, { "input": "10000000000", "output": "10000000001" }, { "input": "1234567891", "output": "617283946" }, { "input": "7509213957", "output": "37546069...
1,526,357,086
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
6,963,200
n = int(input()) c=0 if(n % 2 == 0): c = n+1 else: c = (n+1)/2 print(c)
Title: Pizza, Pizza, Pizza!!! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthd...
```python n = int(input()) c=0 if(n % 2 == 0): c = n+1 else: c = (n+1)/2 print(c) ```
0
91
A
Newspaper Headline
PROGRAMMING
1,500
[ "greedy", "strings" ]
A. Newspaper Headline
2
256
A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a n...
The input data contain two lines. The first line contain the heading *s*1, the second line contains the word *s*2. The lines only consist of lowercase Latin letters (1<=≤<=|*s*1|<=≤<=104,<=1<=≤<=|*s*2|<=≤<=106).
If it is impossible to get the word *s*2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings *s*1, which Fangy will need to receive the word *s*2.
[ "abc\nxyz\n", "abcd\ndabc\n" ]
[ "-1\n", "2\n" ]
none
500
[ { "input": "abc\nxyz", "output": "-1" }, { "input": "abcd\ndabc", "output": "2" }, { "input": "ab\nbabaaab", "output": "5" }, { "input": "ab\nbaaabba", "output": "6" }, { "input": "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\nhbghjgijijcdafcbgiedichdeebaddfddb", "ou...
1,672,293,925
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
2
154
2,150,400
latter = 'abcdefghijklmnopqrstuvwxyz' d = {} from bisect import bisect_right for i in range(len(latter)): d[latter[i]] = [] s = input() for i in range(len(s)): d[s[i]].append(i) y = input() count = 0 last_ind = float("inf") for i in y: if len(d[i])==0: count = -1 ...
Title: Newspaper Headline Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order...
```python latter = 'abcdefghijklmnopqrstuvwxyz' d = {} from bisect import bisect_right for i in range(len(latter)): d[latter[i]] = [] s = input() for i in range(len(s)): d[s[i]].append(i) y = input() count = 0 last_ind = float("inf") for i in y: if len(d[i])==0: co...
-1
469
A
I Wanna Be the Guy
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can...
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100). The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels...
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
[ "4\n3 1 2 3\n2 2 4\n", "4\n3 1 2 3\n2 2 3\n" ]
[ "I become the guy.\n", "Oh, my keyboard!\n" ]
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
500
[ { "input": "4\n3 1 2 3\n2 2 4", "output": "I become the guy." }, { "input": "4\n3 1 2 3\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6", "output": "Oh, my keyboard!" }, { "input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8", "output":...
1,695,650,368
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) p = map(int, a for a in input().split()) q = map(int, a for a in input().split()) for i in range(1, n+1): if not i in p and i not in q: print('Oh, my keyboard!') break else: print('I become the guy.')
Title: I Wanna Be the Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the g...
```python n = int(input()) p = map(int, a for a in input().split()) q = map(int, a for a in input().split()) for i in range(1, n+1): if not i in p and i not in q: print('Oh, my keyboard!') break else: print('I become the guy.') ```
-1
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10...
1,688,638,188
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
4,300,800
k = int(input()) i = 10 s = 19 while k>0: if sum(map(int, str(s))) == 10: k-=1 s+=1 print(s-1)
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A singl...
```python k = int(input()) i = 10 s = 19 while k>0: if sum(map(int, str(s))) == 10: k-=1 s+=1 print(s-1) ```
0
104
A
Blackjack
PROGRAMMING
800
[ "implementation" ]
A. Blackjack
2
256
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to...
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
[ "12\n", "20\n", "10\n" ]
[ "4", "15", "0" ]
In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there ...
500
[ { "input": "12", "output": "4" }, { "input": "20", "output": "15" }, { "input": "10", "output": "0" }, { "input": "11", "output": "4" }, { "input": "15", "output": "4" }, { "input": "18", "output": "4" }, { "input": "25", "output": "0" ...
1,694,023,964
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
122
0
n=int(input()) d=n-10 if(d==0 or d>11): print(0) elif(d==10): print(15) else: print(4)
Title: Blackjack Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Co...
```python n=int(input()) d=n-10 if(d==0 or d>11): print(0) elif(d==10): print(15) else: print(4) ```
0
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,674,069,827
2,147,483,647
Python 3
OK
TESTS
30
92
0
code = input() i = 0 while i < len(code): if(i == len(code) - 1): print("0") break if code[i] == '-' and code[i+1] == '.': print("1", end = '') i = i + 1 elif code[i] == '-' and code[i+1] == '-': print("2", end = '') i = i + 1 else: ...
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 code = input() i = 0 while i < len(code): if(i == len(code) - 1): print("0") break if code[i] == '-' and code[i+1] == '.': print("1", end = '') i = i + 1 elif code[i] == '-' and code[i+1] == '-': print("2", end = '') i = i + 1 ...
3.977
465
A
inc ARG
PROGRAMMING
900
[ "implementation" ]
null
null
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan...
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
[ "4\n1100\n", "4\n1111\n" ]
[ "3\n", "4\n" ]
In the first sample the cell ends up with value 0010, in the second sample — with 0000.
500
[ { "input": "4\n1100", "output": "3" }, { "input": "4\n1111", "output": "4" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "1" }, { "input": "2\n01", "output": "1" }, { "input": "2\n1...
1,596,875,473
2,147,483,647
Python 3
OK
TESTS
29
109
6,656,000
n=int(input()) s=input() if(s[0]=="0"): print(1) else: if "0" in s: a=s.index("0") print(len(s[0:a+1])) else: print(n)
Title: inc ARG Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea...
```python n=int(input()) s=input() if(s[0]=="0"): print(1) else: if "0" in s: a=s.index("0") print(len(s[0:a+1])) else: print(n) ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,683,433,994
2,147,483,647
Python 3
OK
TESTS
40
92
0
x=input() a=[i for i in x] y=input() b=[i for i in y] c=0 b.reverse() if len(a)!=len(b): print("NO") else: for i in range(0,len(a)): if b[i]==a[i]: c=c+1 if c==len(a): print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python x=input() a=[i for i in x] y=input() b=[i for i in y] c=0 b.reverse() if len(a)!=len(b): print("NO") else: for i in range(0,len(a)): if b[i]==a[i]: c=c+1 if c==len(a): print("YES") else: print("NO") ```
3.977
778
A
String Game
PROGRAMMING
1,700
[ "binary search", "greedy", "strings" ]
null
null
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert...
The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*...
Print a single integer number, the maximum number of letters that Nastya can remove.
[ "ababcba\nabb\n5 3 4 1 7 6 2\n", "bbbabb\nbb\n1 6 3 4 2 5\n" ]
[ "3", "4" ]
In the first sample test sequence of removing made by Nastya looks like this: "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https...
500
[ { "input": "ababcba\nabb\n5 3 4 1 7 6 2", "output": "3" }, { "input": "bbbabb\nbb\n1 6 3 4 2 5", "output": "4" }, { "input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2", "output": "9" }, { "input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1...
1,492,976,471
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
4,608,000
s = input().strip() t = input().strip() sq = [int(a) for a in input().strip().split()] m = [] l = len(s) lt = len(t) for i in range(l): m.append(s[sq[i]-1]) def check(x): idx = 0 for i in range(x,l): if m[i]==t[idx]: idx+=1 if idx==lt: return T...
Title: String Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gi...
```python s = input().strip() t = input().strip() sq = [int(a) for a in input().strip().split()] m = [] l = len(s) lt = len(t) for i in range(l): m.append(s[sq[i]-1]) def check(x): idx = 0 for i in range(x,l): if m[i]==t[idx]: idx+=1 if idx==lt: ...
0
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's we...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li...
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output...
1,699,439,976
2,147,483,647
Python 3
OK
TESTS
62
46
0
n = list(input().split(" ")) limak = int(n[0]) bob = int(n[1]) year = 0 while (limak <= bob): year += 1 limak = limak * 3 bob = bob * 2 print(year)
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e...
```python n = list(input().split(" ")) limak = int(n[0]) bob = int(n[1]) year = 0 while (limak <= bob): year += 1 limak = limak * 3 bob = bob * 2 print(year) ```
3
0
none
none
none
0
[ "none" ]
null
null
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order.
[ "21\n", "20\n" ]
[ "1\n15\n", "0\n" ]
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
0
[ { "input": "21", "output": "1\n15" }, { "input": "20", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "1\n1" }, { "input": "3", "output": "0" }, { "input": "100000001", "output": "2\n99999937\n100000000" }, { "i...
1,508,157,304
5,404
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
5
1,000
5,529,600
k = int(input()) minm = k//2 ansl = [] ans= 0 for i in range(minm,k): #print(i) temp = i sums=0 while(temp!=0): sums+=(temp%10) temp//=10 #print(i,sums) if((i+sums)==k): ans+=1 ansl.append(i) print(ans) if(ans>0): for i in range(len(ansl)): ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova th...
```python k = int(input()) minm = k//2 ansl = [] ans= 0 for i in range(minm,k): #print(i) temp = i sums=0 while(temp!=0): sums+=(temp%10) temp//=10 #print(i,sums) if((i+sums)==k): ans+=1 ansl.append(i) print(ans) if(ans>0): for i in range(le...
0
180
C
Letter
PROGRAMMING
1,400
[ "dp" ]
null
null
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to...
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Print a single number — the least number of actions needed to make the message fancy.
[ "PRuvetSTAaYA\n", "OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n", "helloworld\n" ]
[ "5\n", "0\n", "0\n" ]
none
0
[ { "input": "PRuvetSTAaYA", "output": "5" }, { "input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA", "output": "0" }, { "input": "helloworld", "output": "0" }, { "input": "P", "output": "0" }, { "input": "t", "output": "0" }, { "input": "XdJ", "output": "1...
1,699,062,670
2,147,483,647
Python 3
OK
TESTS
40
92
102,400
s=input() a,r=0,0 for x in s: if x.islower():a+=1 elif x.isupper() and a>0:a-=1;r+=1 print(r)
Title: Letter Time Limit: None seconds Memory Limit: None megabytes Problem Description: Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them...
```python s=input() a,r=0,0 for x in s: if x.islower():a+=1 elif x.isupper() and a>0:a-=1;r+=1 print(r) ```
3
1,009
C
Annoying Present
PROGRAMMING
1,700
[ "greedy", "math" ]
null
null
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $m$ changes of the following form. For some int...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes. Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
[ "2 3\n-1 3\n0 0\n-1 -4\n", "3 2\n0 2\n5 0\n" ]
[ "-2.500000000000000\n", "7.000000000000000\n" ]
none
0
[ { "input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000" }, { "input": "3 2\n0 2\n5 0", "output": "7.000000000000000" }, { "input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64", "output": "-16.500000000000000" }, { "input": "1 1\n0 0", ...
1,533,837,699
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
1,228,800
n, m = map(int, input().split()) actions = (list(map(int, input().split())) for i in range(m)) array = [0 for i in range(n)] for x, d in actions: i = 0 if d > 0 else round(n/2) for j in range(n): array[i] += x+d*abs(i-j) answer = sum(array)/n print(answer)
Title: Annoying Present Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice got an array of length $n$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some c...
```python n, m = map(int, input().split()) actions = (list(map(int, input().split())) for i in range(m)) array = [0 for i in range(n)] for x, d in actions: i = 0 if d > 0 else round(n/2) for j in range(n): array[i] += x+d*abs(i-j) answer = sum(array)/n print(answer) ```
0
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-s...
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "inpu...
1,690,695,017
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
k = raw_input() if 'H' in k or 'Q' in k or '9' in k: print ("YES") else: print ("NO")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in...
```python k = raw_input() if 'H' in k or 'Q' in k or '9' in k: print ("YES") else: print ("NO") ```
-1
601
A
The Two Routes
PROGRAMMING
1,600
[ "graphs", "shortest paths" ]
null
null
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to...
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=...
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
[ "4 2\n1 3\n3 4\n", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n" ]
[ "2\n", "-1\n", "3\n" ]
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codefo...
500
[ { "input": "4 2\n1 3\n3 4", "output": "2" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "-1" }, { "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "output": "3" }, { "input": "5 4\n1 2\n3 2\n3 4\n5 4", "output": "4" }, { "input": "3 1\n1 2", "output": "...
1,465,823,205
2,147,483,647
Python 3
OK
TESTS
59
358
14,336,000
from collections import defaultdict as dfdict def bfs(G,rail_connected=False) : level=[1] visited=set([1]) cnt=0 while len(level)>0 : nxtlevel=[] for i in level : nxt=G[i] if not rail_connected else all_vertice-G[i] for j in nxt : if j ...
Title: The Two Routes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road bet...
```python from collections import defaultdict as dfdict def bfs(G,rail_connected=False) : level=[1] visited=set([1]) cnt=0 while len(level)>0 : nxtlevel=[] for i in level : nxt=G[i] if not rail_connected else all_vertice-G[i] for j in nxt : ...
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,642,747,442
2,147,483,647
PyPy 3
OK
TESTS
34
184
0
n=int(input()) d={} for _ in range(n): team=input() d[team]=d.get(team,0)+1 fin = max(list(d.values())) for key in d: if d[key]==fin: print(key) break
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python n=int(input()) d={} for _ in range(n): team=input() d[team]=d.get(team,0)+1 fin = max(list(d.values())) for key in d: if d[key]==fin: print(key) break ```
3.954
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,694,255,880
2,147,483,647
Python 3
OK
TESTS
34
46
0
x=int(input()) print((x-1)//5+1)
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python x=int(input()) print((x-1)//5+1) ```
3
268
B
Buttons
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the seque...
A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has.
In a single line print the number of times Manao has to push a button in the worst-case scenario.
[ "2\n", "3\n" ]
[ "3\n", "7\n" ]
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.
1,000
[ { "input": "2", "output": "3" }, { "input": "3", "output": "7" }, { "input": "4", "output": "14" }, { "input": "1", "output": "1" }, { "input": "10", "output": "175" }, { "input": "2000", "output": "1333335000" }, { "input": "1747", "ou...
1,688,692,609
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
92
0
import math n = int(input()) print(2**n - math.ceil(n/3))
Title: Buttons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the loc...
```python import math n = int(input()) print(2**n - math.ceil(n/3)) ```
0
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od...
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t...
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617...
1,693,476,251
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
from math import* n,m=list(map(int,input().split())) min=1000 q=list(map(int,input().split())) for i in range(len(q)): for u in range(i,len(q)): j=abs(q[i]-q[u]) if j>=n and j<min: min=j print(min)
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a...
```python from math import* n,m=list(map(int,input().split())) min=1000 q=list(map(int,input().split())) for i in range(len(q)): for u in range(i,len(q)): j=abs(q[i]-q[u]) if j>=n and j<min: min=j print(min) ```
0
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,681,561,220
2,147,483,647
PyPy 3
OK
TESTS
38
528
9,113,600
n,t = map(int,input().split(' ')) arr = list(map(int,input().split(' '))) start_i = 0 max_count = 0 summary = 0 for i in range(n): summary += arr[i] if summary > t: max_count = max(max_count, i - start_i) last_start_i = start_i for j in range(last_start_i,i+1): ...
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(' ')) arr = list(map(int,input().split(' '))) start_i = 0 max_count = 0 summary = 0 for i in range(n): summary += arr[i] if summary > t: max_count = max(max_count, i - start_i) last_start_i = start_i for j in range(last_start_i,i+1)...
3
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The produ...
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second...
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1...
1,680,596,283
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #include <cmath> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <algorithm> #include <string> #include <sstream> #include <limits> #include <list> #include <iterator> #include <bitset> //#...
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. T...
```python #include <iostream> #include <cmath> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <algorithm> #include <string> #include <sstream> #include <limits> #include <list> #include <iterator> #include <bi...
-1
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output...
1,658,085,297
2,147,483,647
PyPy 3-64
OK
TESTS
51
124
1,638,400
import sys import math import collections import heapq s=input() n=len(s) c=0 while(n>1): s1=0 for i in range(n): s1+=int(s[i]) s1=str(s1) s=s1 n=len(s1) c+=1 print(c)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came...
```python import sys import math import collections import heapq s=input() n=len(s) c=0 while(n>1): s1=0 for i in range(n): s1+=int(s[i]) s1=str(s1) s=s1 n=len(s1) c+=1 print(c) ```
3.966052
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,664,077,488
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
31
0
s = str(input()) Q = [] A = [] for x in range(len(s)): if(s[x] == "Q"): Q.append(x) if(s[x] == "A"): A.append(x) for x in range(len(A)): if(A[0] < Q[0]): A.remove(0) for i in range(len(A)): if(A[len(A) - 1] > Q[len(Q) - 1]): A.remove(A[len(A) - 1]) print(len(A) * len(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 s = str(input()) Q = [] A = [] for x in range(len(s)): if(s[x] == "Q"): Q.append(x) if(s[x] == "A"): A.append(x) for x in range(len(A)): if(A[0] < Q[0]): A.remove(0) for i in range(len(A)): if(A[len(A) - 1] > Q[len(Q) - 1]): A.remove(A[len(A) - 1]) print(len(A) ...
-1
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,595,896,192
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
20,172,800
def calc(n,m,a): a = sorted(a) return -sum(a[:m]) # get inputs n,m = map(int, input().split()) a = list(map(int, input().split())) print(calc(n,m,a))
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python def calc(n,m,a): a = sorted(a) return -sum(a[:m]) # get inputs n,m = map(int, input().split()) a = list(map(int, input().split())) print(calc(n,m,a)) ```
0
0
none
none
none
0
[ "none" ]
null
null
You are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you've decided that you won't leave this level until you've gained the maximum possible number of points there. The bonus level consists of *n* small platf...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of platforms on the bonus level. The second line contains (*n*<=-<=1) integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=&lt;<=*n*) — the number of transitions from one end to the other that the bridge between platforms *i* and *i*<=+<=1 can b...
Print a single integer — the maximum number of points a player can get on the bonus level. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "5\n2 1 2 1\n" ]
[ "5\n" ]
One possibility of getting 5 points in the sample is starting from platform 3 and consequently moving to platforms 4, 3, 2, 1 and 2. After that the only undestroyed bridge is the bridge between platforms 4 and 5, but this bridge is too far from platform 2 where the hero is located now.
0
[]
1,689,433,490
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1689433490.0245218")# 1689433490.0245426
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you've decided that you won't leave this level until you've gained...
```python print("_RANDOM_GUESS_1689433490.0245218")# 1689433490.0245426 ```
0
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,600,233,632
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
109
0
n = int(input()) sherlock = input() mority = input() reverseCount = [0]*10 for i in range(len(sherlock)): reverseCount[int(mority[i])] += 1 hits = 0 for i in range(len(sherlock)): j = 0 while True: if int(sherlock[i]) == int(mority[j]): hits += 1 break ...
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 n = int(input()) sherlock = input() mority = input() reverseCount = [0]*10 for i in range(len(sherlock)): reverseCount[int(mority[i])] += 1 hits = 0 for i in range(len(sherlock)): j = 0 while True: if int(sherlock[i]) == int(mority[j]): hits += 1 b...
0
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ...
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "4...
1,596,696,591
2,147,483,647
Python 3
OK
TESTS
76
108
6,656,000
n = int(input()) if n%2!=0: x = 0 elif n==2: x=0 elif n%4==0: x = int(n//4)-1 else: x = int(n//4) print(x)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv...
```python n = int(input()) if n%2!=0: x = 0 elif n==2: x=0 elif n%4==0: x = int(n//4)-1 else: x = int(n//4) print(x) ```
3
825
B
Five-In-a-Row
PROGRAMMING
1,600
[ "brute force", "implementation" ]
null
null
Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins i...
You are given matrix 10<=×<=10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed th...
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
[ "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X", "output": "NO" }, { "input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.", "output": "N...
1,500,223,287
5,787
Python 3
CHALLENGED
CHALLENGES
14
61
5,529,600
board = [['.' for i in range(10)] for j in range(10)] for h in range(10): line = input() for k in range(10): present = line[k] if present == 'X' or present == 'O': board[h][k] = present # print(board[h]) # first looking at all the horizontal groups of five horizontal = False vert...
Title: Five-In-a-Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some t...
```python board = [['.' for i in range(10)] for j in range(10)] for h in range(10): line = input() for k in range(10): present = line[k] if present == 'X' or present == 'O': board[h][k] = present # print(board[h]) # first looking at all the horizontal groups of five horizontal = ...
-1
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,641,566,493
2,147,483,647
Python 3
OK
TESTS
30
122
0
s = list(input()) count=0 for i in s: if i.isupper(): count+=1 l = len(s) if count>l//2: print("".join(s).upper()) else: print("".join(s).lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s = list(input()) count=0 for i in s: if i.isupper(): count+=1 l = len(s) if count>l//2: print("".join(s).upper()) else: print("".join(s).lower()) ```
3.9695
252
A
Little Xor
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.
Print a single integer — the required maximal *xor* of a segment of consecutive elements.
[ "5\n1 2 1 1 2\n", "3\n1 2 7\n", "4\n4 2 4 8\n" ]
[ "3\n", "7\n", "14\n" ]
In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
500
[ { "input": "5\n1 2 1 1 2", "output": "3" }, { "input": "3\n1 2 7", "output": "7" }, { "input": "4\n4 2 4 8", "output": "14" }, { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "15" }, { "inpu...
1,554,386,653
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> //#include <bitset> int main() { int n; //std::bitset<30> binario; std::cin >> n; int v[n]; int somas[n][n]; int ant; for(int i = 0; i < n; i++) std::cin >> v[i]; int max = 0; for(int i = 0; i < n; i++){ ant = v[i]; somas[i][i] = v[i]; for(int j = i; j < n; ...
Title: Little Xor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, ...
```python #include <iostream> //#include <bitset> int main() { int n; //std::bitset<30> binario; std::cin >> n; int v[n]; int somas[n][n]; int ant; for(int i = 0; i < n; i++) std::cin >> v[i]; int max = 0; for(int i = 0; i < n; i++){ ant = v[i]; somas[i][i] = v[i]; for(int j = ...
-1
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,624,471,026
2,147,483,647
Python 3
OK
TESTS
35
124
0
a=list(map(int,input().split())) arearect=a[0]*a[1] n=arearect//2 print(n)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python a=list(map(int,input().split())) arearect=a[0]*a[1] n=arearect//2 print(n) ```
3.969
628
B
New Skateboard
PROGRAMMING
1,300
[ "dp" ]
null
null
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which...
The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9.
Print integer *a* — the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "124\n", "04\n", "5810438174\n" ]
[ "4\n", "3\n", "9\n" ]
none
0
[ { "input": "124", "output": "4" }, { "input": "04", "output": "3" }, { "input": "5810438174", "output": "9" }, { "input": "1", "output": "0" }, { "input": "039", "output": "1" }, { "input": "97247", "output": "6" }, { "input": "5810438174",...
1,698,509,996
2,147,483,647
PyPy 3
OK
TESTS
22
202
19,968,000
import math import sys from collections import defaultdict import heapq from collections import deque #input = sys.stdin.readline USE_FILE = False def search(k, v): p = 0 a, n = len(v), len(v) while a >= 1: while p + a < n and k > v[p+a]: p += a a //= 2 if k > v[p+a]: ...
Title: New Skateboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother...
```python import math import sys from collections import defaultdict import heapq from collections import deque #input = sys.stdin.readline USE_FILE = False def search(k, v): p = 0 a, n = len(v), len(v) while a >= 1: while p + a < n and k > v[p+a]: p += a a //= 2 if k > v[p...
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,548,609,726
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
342
1,126,400
from fractions import Fraction a,b=map(int,input().split()) m=7-max(a,b) if m==0: print(0,"/",1) elif m==6: print(1,"1",1) else: print(Fraction(m,6))
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python from fractions import Fraction a,b=map(int,input().split()) m=7-max(a,b) if m==0: print(0,"/",1) elif m==6: print(1,"1",1) else: print(Fraction(m,6)) ```
0
315
A
Sereja and Bottles
PROGRAMMING
1,400
[ "brute force" ]
null
null
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
In a single line print a single integer — the answer to the problem.
[ "4\n1 1\n2 2\n3 3\n4 4\n", "4\n1 2\n2 3\n3 4\n4 1\n" ]
[ "4\n", "0\n" ]
none
500
[ { "input": "4\n1 1\n2 2\n3 3\n4 4", "output": "4" }, { "input": "4\n1 2\n2 3\n3 4\n4 1", "output": "0" }, { "input": "3\n2 828\n4 392\n4 903", "output": "3" }, { "input": "4\n2 3\n1 772\n3 870\n3 668", "output": "2" }, { "input": "5\n1 4\n6 6\n4 3\n3 4\n4 758", ...
1,663,689,234
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
32
92
102,400
from collections import Counter def solve(a, b): n = len(a) openable = set() cnt = Counter(a) self_open = set() for i in range(n): if a[i] != b[i]: openable.add(b[i]) else: if a[i] in self_open: openable.add(a[i]) el...
Title: Sereja and Bottles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th...
```python from collections import Counter def solve(a, b): n = len(a) openable = set() cnt = Counter(a) self_open = set() for i in range(n): if a[i] != b[i]: openable.add(b[i]) else: if a[i] in self_open: openable.add(a[i]) ...
0
158
B
Taxi
PROGRAMMING
1,100
[ "*special", "greedy", "implementation" ]
null
null
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers....
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
[ "5\n1 2 4 3 3\n", "8\n2 3 4 4 2 1 3 1\n" ]
[ "4\n", "5\n" ]
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There a...
1,000
[ { "input": "5\n1 2 4 3 3", "output": "4" }, { "input": "8\n2 3 4 4 2 1 3 1", "output": "5" }, { "input": "5\n4 4 4 4 4", "output": "5" }, { "input": "12\n1 1 1 1 1 1 1 1 1 1 1 1", "output": "3" }, { "input": "2\n2 1", "output": "1" }, { "input": "4\n3 ...
1,697,215,051
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
63
248
7,065,600
# 4 = 1 # 3 = 1, 3 # 2 = 2, 2 1, 2 2, 1, 1 from collections import Counter from math import ceil n = int(input()) lst = list(map(int, input().split())) lst_count = dict(Counter(lst)) taxies = lst_count.get(4, 0) for i in range(lst_count.get(3, 0)): taxies += 1 if 1 in lst_count: lst_...
Title: Taxi Time Limit: None seconds Memory Limit: None megabytes Problem Description: After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpu...
```python # 4 = 1 # 3 = 1, 3 # 2 = 2, 2 1, 2 2, 1, 1 from collections import Counter from math import ceil n = int(input()) lst = list(map(int, input().split())) lst_count = dict(Counter(lst)) taxies = lst_count.get(4, 0) for i in range(lst_count.get(3, 0)): taxies += 1 if 1 in lst_count: ...
0
39
I
Tram
PROGRAMMING
2,500
[]
I. Tram
2
64
In a Berland city S*** there is a tram engine house and only one tram. Three people work in the house — the tram driver, the conductor and the head of the engine house. The tram used to leave the engine house every morning and drove along his loop route. The tram needed exactly *c* minutes to complete the route. The he...
The first line contains integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=105) — the number of crossroads and tramlines in S*** respectively. The next *m* lines contain the descriptions of the tramlines in "*u* *v*" format, where *u* is the initial tramline crossroad and *v* is its final crossroad. The crossroads are numbered ...
In the first line output the value of *t*. In the next line output the value of *k* — the required number of the cameras. In the next line output space-separated numbers of the crossroads, where the cameras should be installed. Output the numbers in increasing order.
[ "4 5\n1 2\n2 3\n3 4\n4 1\n1 4\n" ]
[ "2\n2\n1 3\n" ]
none
0
[]
1,694,092,960
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
inp=int(raw_input()) inp2=raw_input().split() '''s=[] for i in inp2: i=int(i)''' inp2 = [int(x) for x in inp2] inp2.sort() print ' '.join(str(x) for x in inp2)
Title: Tram Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: In a Berland city S*** there is a tram engine house and only one tram. Three people work in the house — the tram driver, the conductor and the head of the engine house. The tram used to leave the engine house every morning and drove al...
```python inp=int(raw_input()) inp2=raw_input().split() '''s=[] for i in inp2: i=int(i)''' inp2 = [int(x) for x in inp2] inp2.sort() print ' '.join(str(x) for x in inp2) ```
-1
190
E
Counter Attack
PROGRAMMING
2,100
[ "data structures", "dsu", "graphs", "hashing", "sortings" ]
null
null
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has *n* cities, numbered from 1 to *n*, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=5·105,<=0<=≤<=*m*<=≤<=106) — the number of cities and the number of roads marked on the flatland map, correspondingly. Next *m* lines contain descriptions of the cities on the map. The *i*-th line contains two integers *a**i* and *b**i* (1...
On the first line print number *k* — the number of groups of cities in Flatland, such that in each group you can get from any city to any other one by flatland roads. At the same time, the cities from different groups should be unreachable by flatland roads. On each of the following *k* lines first print *t**i* (1<=≤<...
[ "4 4\n1 2\n1 3\n4 2\n4 3\n", "3 1\n1 2\n" ]
[ "2\n2 1 4 \n2 2 3 \n", "1\n3 1 2 3 \n" ]
In the first sample there are roads only between pairs of cities 1-4 and 2-3. In the second sample there is no road between cities 1 and 2, but still you can get from one city to the other one through city number 3.
2,500
[ { "input": "4 4\n1 2\n1 3\n4 2\n4 3", "output": "2\n2 1 4 \n2 2 3 " }, { "input": "3 1\n1 2", "output": "1\n3 1 2 3 " }, { "input": "8 14\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n5 6\n6 7", "output": "2\n2 1 2 \n6 3 4 5 6 7 8 " }, { "input": "6 9\n1 4\n1 5...
1,684,571,349
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
11
3,000
142,848,000
# https://codeforces.com/contest/190 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n, m = map(int, input().split()) adj = [set() for _ in range(n + 1)] for _ in range(m): u, v = map(int, input().split()) adj[u] |= {v} adj[v] |= {u} ans = [] todo = set(range(1, n + 1)) while todo: ...
Title: Counter Attack Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has *n* cities, numbered from 1 to *n*, and some pairs of them are connected by bidirectional roads. The Flatlandian ...
```python # https://codeforces.com/contest/190 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n, m = map(int, input().split()) adj = [set() for _ in range(n + 1)] for _ in range(m): u, v = map(int, input().split()) adj[u] |= {v} adj[v] |= {u} ans = [] todo = set(range(1, n + 1)) wh...
0
405
E
Graph Cutting
PROGRAMMING
2,300
[ "dfs and similar", "graphs" ]
null
null
Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest. Chris is given a simple undirected connected graph with *n* vertices (numbered from 1 to *n*) and *m* edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to p...
The first line of input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105), the number of vertices and the number of edges in the graph. The next *m* lines contain the description of the graph's edges. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i...
If it is possible to cut the given graph into edge-distinct paths of length 2, output lines. In the *i*-th line print three space-separated integers *x**i*, *y**i* and *z**i*, the description of the *i*-th path. The graph should contain this path, i.e., the graph should contain edges (*x**i*,<=*y**i*) and (*y**i*,<=*z...
[ "8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n", "3 3\n1 2\n2 3\n3 1\n", "3 2\n1 2\n2 3\n" ]
[ "1 2 4\n1 3 2\n1 4 3\n5 3 6\n5 6 8\n6 7 8", "No solution\n", "1 2 3\n" ]
none
3,000
[]
1,691,108,326
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1691108326.646043")# 1691108326.6460583
Title: Graph Cutting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest. Chris is given a simple undirected connected graph with *n* vertices (numbered from 1 to *n*) and...
```python print("_RANDOM_GUESS_1691108326.646043")# 1691108326.6460583 ```
0
1,003
B
Binary String Constructing
PROGRAMMING
1,300
[ "constructive algorithms" ]
null
null
You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i &lt; n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists. For example, fo...
The first line of the input contains three integers $a$, $b$ and $x$ ($1 \le a, b \le 100, 1 \le x &lt; a + b)$.
Print only one string $s$, where $s$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.
[ "2 2 1\n", "3 3 3\n", "5 3 6\n" ]
[ "1100\n", "101100\n", "01010100\n" ]
All possible answers for the first example: - 1100; - 0011. All possible answers for the second example: - 110100; - 101100; - 110010; - 100110; - 011001; - 001101; - 010011; - 001011.
0
[ { "input": "2 2 1", "output": "1100" }, { "input": "3 3 3", "output": "101100" }, { "input": "5 3 6", "output": "01010100" }, { "input": "100 1 2", "output": "01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { ...
1,593,979,503
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
6,963,200
n,m,k=map(int,input().split()) l=[] for i in range(n+m): if i&1: l.append('0') else: l.append('1') i=1 c=1 while c!=k: i+=1 c+=1 if k&1: x='0' else: x='1' for j in range(i+1,len(l)): l[j]=x print("".join(l))
Title: Binary String Constructing Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $...
```python n,m,k=map(int,input().split()) l=[] for i in range(n+m): if i&1: l.append('0') else: l.append('1') i=1 c=1 while c!=k: i+=1 c+=1 if k&1: x='0' else: x='1' for j in range(i+1,len(l)): l[j]=x print("".join(l)) ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,530,078,464
2,147,483,647
Python 3
OK
TESTS
81
156
0
n = int(input()) f1 = 0 f2 = 0 f3 = 0 for i in range(n): a = [int(elem) for elem in input().split()] f1 += a[0] f2 += a[1] f3 += a[2] if f1 == f2 == f3 == 0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n = int(input()) f1 = 0 f2 = 0 f3 = 0 for i in range(n): a = [int(elem) for elem in input().split()] f1 += a[0] f2 += a[1] f3 += a[2] if f1 == f2 == f3 == 0: print("YES") else: print("NO") ```
3.961
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,658,394,089
2,147,483,647
PyPy 3-64
OK
TESTS
23
62
0
import math d, h, v, e = [int(s) for s in input().split()] radius = d / 2 area = math.pi * radius * radius vout = v / area if vout > e: print("YES") print(h / (vout - e)) else: print("NO")
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 import math d, h, v, e = [int(s) for s in input().split()] radius = d / 2 area = math.pi * radius * radius vout = v / area if vout > e: print("YES") print(h / (vout - e)) else: print("NO") ```
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,699,367,714
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
a=input().split() c=int(a[0]) m=int(a[1]) b=int(a[2]) if ((c*((b+1)*b)/2)-m)%2==0 or ((c*((b+1)*b)/2)-m+1)%2==1: print((c*((b+1)*b)/2)-m) else: print((c*((b+1)*b)/2)-m+1)
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 a=input().split() c=int(a[0]) m=int(a[1]) b=int(a[2]) if ((c*((b+1)*b)/2)-m)%2==0 or ((c*((b+1)*b)/2)-m+1)%2==1: print((c*((b+1)*b)/2)-m) else: print((c*((b+1)*b)/2)-m+1) ```
0
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,646,997,445
2,147,483,647
Python 3
OK
TESTS
25
62
0
# https://codeforces.com/problemset/problem/34/B n, m = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] arr.sort() result = 0 # print(abs(sum(arr[:m]))) for i in range(m): if arr[i] > 0: pass else: result += arr[i] print(abs(result))
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python # https://codeforces.com/problemset/problem/34/B n, m = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] arr.sort() result = 0 # print(abs(sum(arr[:m]))) for i in range(m): if arr[i] > 0: pass else: result += arr[i] print(abs(result)) ```
3.9845
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The produ...
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second...
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1...
1,600,756,328
2,147,483,647
PyPy 3
OK
TESTS
20
310
0
#https://codeforces.com/problemset/problem/300/A n=int(input()) l=list(map(int,input().split())) pos=[] neg=[] zero=[] for i in l: if i > 0: pos.append(i) elif i < 0: neg.append(i) else: zero.append(i) if not len(neg) &1: zero.append(neg[0]) neg.pop(0) if not len(pos): pos.append(neg[0]) pos.append(neg[1])...
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. T...
```python #https://codeforces.com/problemset/problem/300/A n=int(input()) l=list(map(int,input().split())) pos=[] neg=[] zero=[] for i in l: if i > 0: pos.append(i) elif i < 0: neg.append(i) else: zero.append(i) if not len(neg) &1: zero.append(neg[0]) neg.pop(0) if not len(pos): pos.append(neg[0]) pos.appe...
3
604
A
Uncowed Forces
PROGRAMMING
1,000
[ "implementation" ]
null
null
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a...
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted. The second line contains five space-separated integers *w*1, *w*2, *w*3, ...
Print a single integer, the value of Kevin's final score.
[ "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "119 119 119 119 119\n0 0 0 0 0\n10 0\n" ]
[ "4900\n", "4930\n" ]
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving pro...
500
[ { "input": "20 40 60 80 100\n0 1 2 3 4\n1 0", "output": "4900" }, { "input": "119 119 119 119 119\n0 0 0 0 0\n10 0", "output": "4930" }, { "input": "3 6 13 38 60\n6 10 10 3 8\n9 9", "output": "5088" }, { "input": "21 44 11 68 75\n6 2 4 8 4\n2 8", "output": "4522" }, {...
1,660,414,465
2,147,483,647
PyPy 3-64
OK
TESTS
57
62
0
m = [int(x) for x in input().split()] w = [int(x) for x in input().split()] h = [int(x) for x in input().split()] res = 0 for i in range(5): res += max(150 * (i + 1),500 * (i + 1) - 2 * m[i] * (i + 1) - 50 * w[i]) print(res + h[0] * 100 - h[1] * 50)
Title: Uncowed Forces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challengin...
```python m = [int(x) for x in input().split()] w = [int(x) for x in input().split()] h = [int(x) for x in input().split()] res = 0 for i in range(5): res += max(150 * (i + 1),500 * (i + 1) - 2 * m[i] * (i + 1) - 50 * w[i]) print(res + h[0] * 100 - h[1] * 50) ```
3
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ...
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five l...
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { ...
1,544,712,889
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
124
0
a,b,c = map(int,input().split()) if (a == 0 and c == 0) or (b == 0 and c == 0): print(0) elif a > b and c > a - b: c -= a - b a += a - b if (a + b) % 2 == 0: if c > 1: if c % 2 == 0: print(a+b+c) else: c -= 1 print(a+b+c) ...
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand....
```python a,b,c = map(int,input().split()) if (a == 0 and c == 0) or (b == 0 and c == 0): print(0) elif a > b and c > a - b: c -= a - b a += a - b if (a + b) % 2 == 0: if c > 1: if c % 2 == 0: print(a+b+c) else: c -= 1 print...
0
344
A
Magnets
PROGRAMMING
800
[ "implementation" ]
null
null
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit...
On the single line of the output print the number of groups of magnets.
[ "6\n10\n10\n10\n01\n10\n10\n", "4\n01\n01\n10\n10\n" ]
[ "3\n", "2\n" ]
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
500
[ { "input": "6\n10\n10\n10\n01\n10\n10", "output": "3" }, { "input": "4\n01\n01\n10\n10", "output": "2" }, { "input": "1\n10", "output": "1" }, { "input": "2\n01\n10", "output": "2" }, { "input": "2\n10\n10", "output": "1" }, { "input": "3\n10\n01\n10",...
1,699,014,661
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
# LUOGU_RID: 133148698 a = int(input()) c = 0 d = [] for i in range(1,a+1): b = input() d.append(b) m=d[1:] n=d[:-1] for i in zip(m, n): if i[0]!=i[1]: c += 1 if c == 0: print(1) elif c == 1: print(2) else: print(c)
Title: Magnets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets...
```python # LUOGU_RID: 133148698 a = int(input()) c = 0 d = [] for i in range(1,a+1): b = input() d.append(b) m=d[1:] n=d[:-1] for i in zip(m, n): if i[0]!=i[1]: c += 1 if c == 0: print(1) elif c == 1: print(2) else: print(c) ```
0
90
B
African Crossword
PROGRAMMING
1,100
[ "implementation", "strings" ]
B. African Crossword
2
256
An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid.
Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.
[ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n" ]
[ "abcd", "codeforces" ]
none
1,000
[ { "input": "3 3\ncba\nbcd\ncbc", "output": "abcd" }, { "input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf", "output": "codeforces" }, { "input": "4 4\nusah\nusha\nhasu\nsuha", "output": "ahhasusu" }, { "input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz", "output...
1,555,906,161
2,147,483,647
PyPy 3
OK
TESTS
43
436
2,150,400
import copy n, m = map(int, input().split()) arr = [] for i in range(n): arr.append([i for i in input()]) real = copy.deepcopy(arr) for i in range(n): for j in range(m): letter = arr[i][j] if letter == "": continue else: for x in range(i+1, n): if arr[x][j] == letter: real[x][...
Title: African Crossword Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To s...
```python import copy n, m = map(int, input().split()) arr = [] for i in range(n): arr.append([i for i in input()]) real = copy.deepcopy(arr) for i in range(n): for j in range(m): letter = arr[i][j] if letter == "": continue else: for x in range(i+1, n): if arr[x][j] == letter: ...
3.886995
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a c...
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th...
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01...
1,601,912,796
2,147,483,647
Python 3
OK
TESTS
38
109
0
cards = input() flips = 0 for card in cards: if (card in 'aeiou13579'): flips += 1 print(flips)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each car...
```python cards = input() flips = 0 for card in cards: if (card in 'aeiou13579'): flips += 1 print(flips) ```
3
804
D
Expected diameter of a tree
PROGRAMMING
2,500
[ "binary search", "brute force", "dfs and similar", "dp", "sortings", "trees" ]
null
null
Pasha is a good student and one of MoJaK's best friends. He always have a problem to think about. Today they had a talk about the following problem. We have a forest (acyclic undirected graph) with *n* vertices and *m* edges. There are *q* queries we should answer. In each query two vertices *v* and *u* are given. Let...
The first line contains three integers *n*, *m* and *q*(1<=≤<=*n*,<=*m*,<=*q*<=≤<=105) — the number of vertices, the number of edges in the graph and the number of queries. Each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*), that means there is an edge between vertices *...
For each query print the expected value of *d* as described in the problem statement. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Let's assume that your answer is *a*, and the jury's answer is *b*. The checker program will consider your answer correct, if .
[ "3 1 2\n1 3\n3 1\n2 3\n", "5 2 3\n2 4\n4 3\n4 2\n4 1\n2 5\n" ]
[ "-1\n2.0000000000\n", "-1\n2.6666666667\n2.6666666667\n" ]
In the first example the vertices 1 and 3 are in the same component, so the answer for the first query is -1. For the second query there are two options to add the edge: one option is to add the edge 1 - 2, the other one is 2 - 3. In both ways the resulting diameter is 2, so the answer is 2. In the second example the ...
2,000
[ { "input": "3 1 2\n1 3\n3 1\n2 3", "output": "-1\n2.0000000000" }, { "input": "5 2 3\n2 4\n4 3\n4 2\n4 1\n2 5", "output": "-1\n2.6666666667\n2.6666666667" }, { "input": "17 15 13\n3 15\n3 1\n15 9\n16 6\n1 5\n1 8\n16 12\n15 7\n9 4\n6 11\n15 14\n9 10\n15 13\n1 17\n11 2\n7 3\n9 6\n9 7\n1 8\...
1,524,939,022
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; const int mxn = (1e5) + 5; vector<int>tr[mxn]; int pr[mxn]; int sz[mxn]; int n,m,q; int find(int x) { if(x == pr[x])return x; return pr[x] = find(pr[x]); } void merge(int x,int y) { x = find(x); y = find(y); if(x == y)return; if...
Title: Expected diameter of a tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha is a good student and one of MoJaK's best friends. He always have a problem to think about. Today they had a talk about the following problem. We have a forest (acyclic undirected graph) with *n* vert...
```python #include<bits/stdc++.h> using namespace std; const int mxn = (1e5) + 5; vector<int>tr[mxn]; int pr[mxn]; int sz[mxn]; int n,m,q; int find(int x) { if(x == pr[x])return x; return pr[x] = find(pr[x]); } void merge(int x,int y) { x = find(x); y = find(y); if(x == y)retur...
-1
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,686,838,037
2,147,483,647
Python 3
OK
TESTS
102
46
0
a = str(input()) b = str(input()) c = "".join([str(int(a[i]) ^ int(b[i])) for i in range(len(a))]) print(c)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a = str(input()) b = str(input()) c = "".join([str(int(a[i]) ^ int(b[i])) for i in range(len(a))]) print(c) ```
3.9885
742
A
Arpa’s hard exam and Mehrdad’s naive cheat
PROGRAMMING
1,000
[ "implementation", "math", "number theory" ]
null
null
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, al...
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Print single integer — the last digit of 1378*n*.
[ "1\n", "2\n" ]
[ "8", "4" ]
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
500
[ { "input": "1", "output": "8" }, { "input": "2", "output": "4" }, { "input": "1000", "output": "6" }, { "input": "3", "output": "2" }, { "input": "4", "output": "6" }, { "input": "1000000000", "output": "6" }, { "input": "5", "output": ...
1,644,006,144
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
171
10,240,000
n = input() m = input() a = input() a = int(a) n = int(n) m = int(m) na = 1 ma = 1 if(a<n): if n != n/a * a: na = n/a +1 else: na = n/a if(a<m): if(m!= m/a*a): ma = m/a +1 else: ma = m/a print(na * ma)
Title: Arpa’s hard exam and Mehrdad’s naive cheat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques...
```python n = input() m = input() a = input() a = int(a) n = int(n) m = int(m) na = 1 ma = 1 if(a<n): if n != n/a * a: na = n/a +1 else: na = n/a if(a<m): if(m!= m/a*a): ma = m/a +1 else: ma = m/a print(na * ma) ```
-1
611
B
New Year and Old Property
PROGRAMMING
1,300
[ "bitmasks", "brute force", "implementation" ]
null
null
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Lim...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
[ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n" ]
[ "2\n", "1\n", "0\n", "26\n" ]
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<su...
750
[ { "input": "5 10", "output": "2" }, { "input": "2015 2015", "output": "1" }, { "input": "100 105", "output": "0" }, { "input": "72057594000000000 72057595000000000", "output": "26" }, { "input": "1 100", "output": "16" }, { "input": "100000000000000000...
1,602,528,712
2,147,483,647
Python 3
OK
TESTS
103
124
307,200
# -*- coding: utf-8 -*- """ Created on Tue Oct 13 00:43:06 2020 @author: Dark Soul """ [a,b]=list(map(int,input().split())) choto=a boro=b a=bin(a) a=list(a[2:]) b=bin(b) b=list(b[2:]) x=len(a) y=len(b) ans=0 for i in range(x,y+1): ini=2**(i)-1 for j in range(i-1): now=ini-(2**j)...
Title: New Year and Old Property Time Limit: None seconds Memory Limit: None megabytes Problem Description: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2...
```python # -*- coding: utf-8 -*- """ Created on Tue Oct 13 00:43:06 2020 @author: Dark Soul """ [a,b]=list(map(int,input().split())) choto=a boro=b a=bin(a) a=list(a[2:]) b=bin(b) b=list(b[2:]) x=len(a) y=len(b) ans=0 for i in range(x,y+1): ini=2**(i)-1 for j in range(i-1): now=...
3
46
A
Ball Game
PROGRAMMING
800
[ "brute force", "implementation" ]
A. Ball Game
2
256
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is...
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle.
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
[ "10\n", "3\n" ]
[ "2 4 7 1 6 2 9 7 6\n", "2 1\n" ]
none
0
[ { "input": "10", "output": "2 4 7 1 6 2 9 7 6" }, { "input": "3", "output": "2 1" }, { "input": "4", "output": "2 4 3" }, { "input": "5", "output": "2 4 2 1" }, { "input": "6", "output": "2 4 1 5 4" }, { "input": "7", "output": "2 4 7 4 2 1" }, ...
1,627,590,525
2,147,483,647
Python 3
OK
TESTS
33
154
6,758,400
n = int(input()) p = 0 for i in range(1, n): p = (p + i) % n print(p + 1, end= " ")
Title: Ball Game Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think...
```python n = int(input()) p = 0 for i in range(1, n): p = (p + i) % n print(p + 1, end= " ") ```
3.948911
743
B
Chloe and the sequence
PROGRAMMING
1,200
[ "binary search", "bitmasks", "constructive algorithms", "implementation" ]
null
null
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq...
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1).
Print single integer — the integer at the *k*-th position in the obtained sequence.
[ "3 2\n", "4 8\n" ]
[ "2", "4" ]
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2. In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.
1,000
[ { "input": "3 2", "output": "2" }, { "input": "4 8", "output": "4" }, { "input": "5 27", "output": "1" }, { "input": "7 44", "output": "3" }, { "input": "15 18432", "output": "12" }, { "input": "20 259676", "output": "3" }, { "input": "30 6...
1,597,057,990
2,147,483,647
PyPy 3
MEMORY_LIMIT_EXCEEDED
TESTS
6
421
268,390,400
n,k=map(int,input().split()) l=[1] for i in range(1,n): l1=l l.extend(l) l.insert(len(l)//2,i+1) print(l[k-1])
Title: Chloe and the sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following a...
```python n,k=map(int,input().split()) l=[1] for i in range(1,n): l1=l l.extend(l) l.insert(len(l)//2,i+1) print(l[k-1]) ```
0
525
A
Vitaliy and Pie
PROGRAMMING
1,100
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ...
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain ...
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
250
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg...
1,589,274,786
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
171
20,480,000
''' handle - pruvi007 questionName - A. Vitaly and Pie Contest - NA Topic - Hashing Platform - CF ''' from sys import stdin, stdout from collections import defaultdict def main(): n = int(stdin.readline()) s = stdin.readline().split('\n')[0] d = defaultdict(int) for i in range(len(s...
Title: Vitaliy and Pie Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from...
```python ''' handle - pruvi007 questionName - A. Vitaly and Pie Contest - NA Topic - Hashing Platform - CF ''' from sys import stdin, stdout from collections import defaultdict def main(): n = int(stdin.readline()) s = stdin.readline().split('\n')[0] d = defaultdict(int) for i in r...
0
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be...
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ...
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000...
1,588,671,045
2,147,483,647
Python 3
OK
TESTS
35
218
307,200
rows,columns = map(int,input().split()) flag = [] for i in range(rows): flag.append(list([char for char in input()])) for row_i in range(len(flag)-1): # if incorrect color if len(set(flag[row_i])) > 1 or flag[row_i][0] == flag[row_i+1][0]: print("NO") exit() if len(set(flag[len(flag)-1])) > 1:...
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of...
```python rows,columns = map(int,input().split()) flag = [] for i in range(rows): flag.append(list([char for char in input()])) for row_i in range(len(flag)-1): # if incorrect color if len(set(flag[row_i])) > 1 or flag[row_i][0] == flag[row_i+1][0]: print("NO") exit() if len(set(flag[len(flag)...
3.943211
754
D
Fedor and coupons
PROGRAMMING
2,100
[ "binary search", "data structures", "greedy", "sortings" ]
null
null
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has *n* discount coupons, the *i*-th of them can be used with products w...
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose. Each of the next *n* lines contains two integers *l**i* and *r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the description of the *i*-th coupon. The coupons...
In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted. In the second line print *k* distinct integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≤<=*p**i*<=≤<=*n*) — the ids of the coupo...
[ "4 2\n1 100\n40 70\n120 130\n125 180\n", "3 2\n1 12\n15 20\n25 30\n", "5 2\n1 10\n5 15\n14 50\n30 70\n99 100\n" ]
[ "31\n1 2 \n", "0\n1 2 \n", "21\n3 4 \n" ]
In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total. In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example.
2,000
[ { "input": "4 2\n1 100\n40 70\n120 130\n125 180", "output": "31\n1 2 " }, { "input": "3 2\n1 12\n15 20\n25 30", "output": "0\n1 2 " }, { "input": "5 2\n1 10\n5 15\n14 50\n30 70\n99 100", "output": "21\n3 4 " }, { "input": "7 6\n-8 6\n7 9\n-10 -5\n-6 10\n-7 -3\n5 8\n4 10", ...
1,665,489,410
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
109
8,806,400
''' https://codeforces.com/problemset/problem/754/D 输入 n, k (1≤k≤n≤3e5) 和 n 个闭区间,区间左右端点在 [-1e9,1e9] 内,区间的编号从 1 开始。 请你选择 k 个区间,使得这 k 个区间的交集的大小尽量大(只考虑整数), 输出这个最大值,以及对应的区间的编号。 思考题:如果改成并集呢? 输入 4 2 1 100 40 70 120 130 125 180 输出 31 1 2 输入 3 2 1 12 15 20 25 30 输出 0 1 2 输入 5 2 1 10 5 15 14 5...
Title: Fedor and coupons Time Limit: None seconds Memory Limit: None megabytes Problem Description: All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with i...
```python ''' https://codeforces.com/problemset/problem/754/D 输入 n, k (1≤k≤n≤3e5) 和 n 个闭区间,区间左右端点在 [-1e9,1e9] 内,区间的编号从 1 开始。 请你选择 k 个区间,使得这 k 个区间的交集的大小尽量大(只考虑整数), 输出这个最大值,以及对应的区间的编号。 思考题:如果改成并集呢? 输入 4 2 1 100 40 70 120 130 125 180 输出 31 1 2 输入 3 2 1 12 15 20 25 30 输出 0 1 2 输入 5 2 1 10 ...
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,571,983,776
2,147,483,647
Python 3
OK
TESTS
102
109
0
word1 = input() word2 = input() l = [] for i in range(len(word1)): if(word1[i] == word2[i] == '0' or word1[i] == word2[i] == '1'): l.append(str(0)) else: l.append(str(1)) print(''.join(l))
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 word1 = input() word2 = input() l = [] for i in range(len(word1)): if(word1[i] == word2[i] == '0' or word1[i] == word2[i] == '1'): l.append(str(0)) else: l.append(str(1)) print(''.join(l)) ```
3.97275
984
A
Game
PROGRAMMING
800
[ "sortings" ]
null
null
Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ...
The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Print one number that will be left on the board.
[ "3\n2 1 3\n", "3\n2 2 2\n" ]
[ "2", "2" ]
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board. In the second sample, $2$ is left on the board regardless of the actions of the players.
500
[ { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 2 2", "output": "2" }, { "input": "9\n44 53 51 80 5 27 74 79 94", "output": "53" }, { "input": "10\n38 82 23 37 96 4 81 60 67 86", "output": "60" }, { "input": "10\n58 26 77 15 53 81 68 48 22 65", "outpu...
1,649,959,006
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
n=int(input()) l=list(map(int,input().split())) l.sort() k=[] flag=0 c=0 i=0 j=1 while(c<n): if(flag==0): k.append(l[i]) # print(k) flag=1 elif(flag==1): k.append(l[-1*j]) flag=0 # print(k) c+=1 # print(k) for ele in l: if ele not in...
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the...
```python n=int(input()) l=list(map(int,input().split())) l.sort() k=[] flag=0 c=0 i=0 j=1 while(c<n): if(flag==0): k.append(l[i]) # print(k) flag=1 elif(flag==1): k.append(l[-1*j]) flag=0 # print(k) c+=1 # print(k) for ele in l: if ...
0
92
B
Binary Number
PROGRAMMING
1,300
[ "greedy" ]
B. Binary Number
1
256
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divide...
The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106.
Print the required number of actions.
[ "1\n", "1001001\n", "101110\n" ]
[ "0\n", "12\n", "8\n" ]
Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide...
1,000
[ { "input": "1", "output": "0" }, { "input": "1001001", "output": "12" }, { "input": "101110", "output": "8" }, { "input": "11", "output": "3" }, { "input": "11110001101", "output": "16" }, { "input": "101010100100111100011111001111100001010101111110101...
1,654,184,821
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
11
1,000
10,137,600
from sys import stdin, stdout x = '0'+stdin.readline().rstrip() c = 0 while x.lstrip('0') != '1': lx = len(x) if x[-1] == '0': zeros = lx - len(x.rstrip('0')) c += zeros x = x[:-zeros] else: ones = lx - len(x.rstrip('1')) c += 1 x = x[:-ones-1]...
Title: Binary Number Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to ...
```python from sys import stdin, stdout x = '0'+stdin.readline().rstrip() c = 0 while x.lstrip('0') != '1': lx = len(x) if x[-1] == '0': zeros = lx - len(x.rstrip('0')) c += zeros x = x[:-zeros] else: ones = lx - len(x.rstrip('1')) c += 1 x = x...
0
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,696,694,024
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
102,400
q=int(input()) w=0 if q==1: print(1) exit if q>=5: w+=1 q=q-5 if q>=5: w+=1 q=q-5 if q>=4: w+=1 q=q-4 if q>=3: w+=1 q=q-3 if q>=2: w+=1 q=q-2 if q>=1: w+=1 if q>=4: w+=1 q=q-4 ...
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python q=int(input()) w=0 if q==1: print(1) exit if q>=5: w+=1 q=q-5 if q>=5: w+=1 q=q-5 if q>=4: w+=1 q=q-4 if q>=3: w+=1 q=q-3 if q>=2: w+=1 q=q-2 if q>=1: w+=1 if q>=4: w+=1 ...
0
0
none
none
none
0
[ "none" ]
null
null
You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$. Find out the non-negative ...
The first line contains four integers $n, a, b$ and $k$ $(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$. The second line contains a sequence of length $k$ consisting of characters '+' and '-'. If the $i$-th character (0-indexed) is '+', then $s_{i} = 1$, otherwise $s_{i} = -1$. Note that onl...
Output a single integer — value of given expression modulo $10^{9} + 9$.
[ "2 2 3 3\n+-+\n", "4 1 5 1\n-\n" ]
[ "7\n", "999999228\n" ]
In the first example: $(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$ = $2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$ = 7 In the second example: $(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$.
0
[ { "input": "2 2 3 3\n+-+", "output": "7" }, { "input": "4 1 5 1\n-", "output": "999999228" }, { "input": "1 1 4 2\n-+", "output": "3" }, { "input": "3 1 4 4\n+--+", "output": "45" }, { "input": "5 1 1 6\n++---+", "output": "0" }, { "input": "5 2 2 6\n+...
1,613,521,187
6,587
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
614,400
n,a,b,k=map(int,input().split()) s=input() res=0 x=n//k MOD=10**9+9 aa=a**n bb=b**n ak=a**k bk=b**k akx=a**(k*x) if(a==b): for t in range(k): if(s[t]=='+'): res+=(x+1)*aa else: res-=(x+1)*aa res%=MOD print(res) else: hoge=(a**(k*(x+1))-b**(k*(x+1)))//(a**k-b**...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for e...
```python n,a,b,k=map(int,input().split()) s=input() res=0 x=n//k MOD=10**9+9 aa=a**n bb=b**n ak=a**k bk=b**k akx=a**(k*x) if(a==b): for t in range(k): if(s[t]=='+'): res+=(x+1)*aa else: res-=(x+1)*aa res%=MOD print(res) else: hoge=(a**(k*(x+1))-b**(k*(x+1)))/...
0
830
A
Office Keys
PROGRAMMING
1,800
[ "binary search", "brute force", "dp", "greedy", "sortings" ]
null
null
There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine th...
The first line contains three integers *n*, *k* and *p* (1<=≤<=*n*<=≤<=1<=000, *n*<=≤<=*k*<=≤<=2<=000, 1<=≤<=*p*<=≤<=109) — the number of people, the number of keys and the office location. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — positions in which people are ...
Print the minimum time (in seconds) needed for all *n* to reach the office with keys.
[ "2 4 50\n20 100\n60 10 40 80\n", "1 2 10\n11\n15 7\n" ]
[ "50\n", "7\n" ]
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is...
500
[ { "input": "2 4 50\n20 100\n60 10 40 80", "output": "50" }, { "input": "1 2 10\n11\n15 7", "output": "7" }, { "input": "2 5 15\n10 4\n29 23 21 22 26", "output": "23" }, { "input": "3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163", "output": "1394...
1,500,053,875
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
4,608,000
o=lambda:[int(f)for f in input().split()] n,k,p=o() a=o() b=o() print(max(min(abs(b[i + d] - a[i]) + abs(b[i + d] - p) for i in range(n)) for d in range(k - n + 1)))
Title: Office Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office...
```python o=lambda:[int(f)for f in input().split()] n,k,p=o() a=o() b=o() print(max(min(abs(b[i + d] - a[i]) + abs(b[i + d] - p) for i in range(n)) for d in range(k - n + 1))) ```
0
69
D
Dot
PROGRAMMING
1,900
[ "dp", "games" ]
D. Dot
3
256
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules: - On the checkered paper ...
The first line of the input file contains 4 integers *x*, *y*, *n*, *d* (<=-<=200<=≤<=*x*,<=*y*<=≤<=200,<=1<=≤<=*d*<=≤<=200,<=1<=≤<=*n*<=≤<=20) — the initial coordinates of the dot, the distance *d* and the number of vectors. It is guaranteed that the initial dot is at the distance less than *d* from the origin of the ...
You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.
[ "0 0 2 3\n1 1\n1 2\n", "0 0 2 4\n1 1\n1 2\n" ]
[ "Anton", "Dasha" ]
In the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move — to reflect relatively to the line *y* = *x*. Dasha will respond to it with the same move and return the d...
2,000
[ { "input": "0 0 2 3\n1 1\n1 2", "output": "Anton" }, { "input": "0 0 2 4\n1 1\n1 2", "output": "Dasha" }, { "input": "0 0 5 100\n12 105\n15 59\n21 1\n27 6\n27 76", "output": "Anton" }, { "input": "0 0 5 100\n16 24\n29 6\n44 24\n66 37\n102 19", "output": "Anton" }, { ...
1,672,922,880
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
30
530
14,950,400
# https://codeforces.com/problemset/problem/69/D from functools import lru_cache x, y, n, d = map(int, input().split()) vectors = [] for _ in range(n): vectors.append(list(map(int, input().split()))) @lru_cache(None) def dp(cx, cy): return any(not dp(cx + dx, cy + dy) for dx, dy in vectors if (cx + dx) ** 2...
Title: Dot Time Limit: 3 seconds Memory Limit: 256 megabytes Problem Description: Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a...
```python # https://codeforces.com/problemset/problem/69/D from functools import lru_cache x, y, n, d = map(int, input().split()) vectors = [] for _ in range(n): vectors.append(list(map(int, input().split()))) @lru_cache(None) def dp(cx, cy): return any(not dp(cx + dx, cy + dy) for dx, dy in vectors if (cx ...
-1
1,011
A
Stages
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are $n$ stages available. The ro...
The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket. The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th...
Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
[ "5 3\nxyabd\n", "7 4\nproblem\n", "2 2\nab\n", "12 1\nabaabbaaabbb\n" ]
[ "29", "34", "-1", "1" ]
In the first example, the following rockets satisfy the condition: - "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$). Rocket "adx" has the minimal weight, so the answer is $29$. In the second example, target rocket is "belo". Its weight ...
500
[ { "input": "5 3\nxyabd", "output": "29" }, { "input": "7 4\nproblem", "output": "34" }, { "input": "2 2\nab", "output": "-1" }, { "input": "12 1\nabaabbaaabbb", "output": "1" }, { "input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa", "output": ...
1,645,333,994
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
62
0
n,k = list(map(int,input().split())) r = list(input()) r.sort() r1 = [] count = 0 i = 0 while count<=k and i<n: if i==0: r1.append(r[i]) i+=1 count+=1 else: if ord(r[i])-ord(r[i-1])>=2: r1.append(r[i]) i+=1 count+=1 ...
Title: Stages Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — conca...
```python n,k = list(map(int,input().split())) r = list(input()) r.sort() r1 = [] count = 0 i = 0 while count<=k and i<n: if i==0: r1.append(r[i]) i+=1 count+=1 else: if ord(r[i])-ord(r[i-1])>=2: r1.append(r[i]) i+=1 count+=1 ...
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output...
1,624,287,135
2,147,483,647
PyPy 3
OK
TESTS
51
280
2,867,200
import sys import os import copy cin = [ lambda: input(), lambda: int(input()), lambda: input().split(), lambda: [int(a) for a in input().split()], ] def solve(): n = cin[0]() ans = 0 while len(n)!=1: s = 0 for c in n: s += int(c) n = str(s) ans += 1 print(ans) def main():...
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came...
```python import sys import os import copy cin = [ lambda: input(), lambda: int(input()), lambda: input().split(), lambda: [int(a) for a in input().split()], ] def solve(): n = cin[0]() ans = 0 while len(n)!=1: s = 0 for c in n: s += int(c) n = str(s) ans += 1 print(ans) d...
3.924841
61
B
Hard Work
PROGRAMMING
1,300
[ "strings" ]
B. Hard Work
2
256
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his *n* students took part in the exam. The teach...
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer *n* (0<=≤<=*n*<=≤<=1000), the number of stud...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
[ "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful\n", "Shapur;;\nis___\na_genius\n3\nShapur__a_is___geniUs\nis___shapu...
[ "ACC\nACC\nACC\nWA\nACC\nACC\nWA\n", "WA\nACC\nACC\n" ]
none
1,000
[ { "input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA" }, ...
1,543,112,330
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
def hard_work(ini, ans): n = len(ans) ini_lower = [None]*3 index = 0 for i in ini: i_mod = "" for x in i: if x in ["-","_",';']: i_mod += "" else: i_mod += x ini_lower[index] = i_mod.lower() index += 1 ...
Title: Hard Work Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teache...
```python def hard_work(ini, ans): n = len(ans) ini_lower = [None]*3 index = 0 for i in ini: i_mod = "" for x in i: if x in ["-","_",';']: i_mod += "" else: i_mod += x ini_lower[index] = i_mod.lower() ind...
-1
557
B
Pasha and Tea
PROGRAMMING
1,500
[ "constructive algorithms", "implementation", "math", "sortings" ]
null
null
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water. It turned out that among Pasha's friends there are exactly *n* boys a...
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters. The second line of the input contains the sequence of integers *...
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "2 4\n1 1 1 1\n", "3 18\n4 4 4 2 2 2\n", "1 5\n2 3\n" ]
[ "3", "18", "4.5" ]
Pasha also has candies that he is going to give to girls but that is another task...
1,000
[ { "input": "2 4\n1 1 1 1", "output": "3.0000000000" }, { "input": "3 18\n4 4 4 2 2 2", "output": "18.0000000000" }, { "input": "1 5\n2 3", "output": "4.5000000000" }, { "input": "1 1\n1000000000 1000000000", "output": "1.0000000000" }, { "input": "4 1000000000\n1 ...
1,545,320,514
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
78
0
n, w = [int(i) for i in input().split()] capacity = input() x = w / (3 * n) result = x * 3 * n print(round(result * 2) / 2)
Title: Pasha and Tea Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ...
```python n, w = [int(i) for i in input().split()] capacity = input() x = w / (3 * n) result = x * 3 * n print(round(result * 2) / 2) ```
0
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,551,485,209
2,147,483,647
Python 3
OK
TESTS
21
124
307,200
n=int(input()) classes=[] for i in range(n): s=input() f=[int(i) for i in s] classes.append(f) value=[] for i in range(7): k=0 for j in range(n): k+=classes[j][i] value.append(k) print(max(value))
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 n=int(input()) classes=[] for i in range(n): s=input() f=[int(i) for i in s] classes.append(f) value=[] for i in range(7): k=0 for j in range(n): k+=classes[j][i] value.append(k) print(max(value)) ```
3
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nck...
1,611,685,143
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
12
62
307,200
x = int(input()) d = [] for i in range(x): r = input() d.append(r) l = len(d[0]) if [d[i][i] for i in range(l)] == [d[l-1-i][i] for i in range(l-1,-1,-1)]: for i in range(1,len(d)-1): if (d[i][0] == d[i][-1] and (d[i][0] != d[0][0] and d[i][-1] != d[0][0])): pass else: ...
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a...
```python x = int(input()) d = [] for i in range(x): r = input() d.append(r) l = len(d[0]) if [d[i][i] for i in range(l)] == [d[l-1-i][i] for i in range(l-1,-1,-1)]: for i in range(1,len(d)-1): if (d[i][0] == d[i][-1] and (d[i][0] != d[0][0] and d[i][-1] != d[0][0])): pass ...
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,570,117,875
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
34
109
0
def solution(s) -> None: k = "hello" i = 0 for v in s: if v == k[i]: i += 1 if i == 4: break print(["NO", "YES"][i == 4]) def main(): s = input() solution(s) if __name__ == "__main__": main()
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python def solution(s) -> None: k = "hello" i = 0 for v in s: if v == k[i]: i += 1 if i == 4: break print(["NO", "YES"][i == 4]) def main(): s = input() solution(s) if __name__ == "__main__": main() ```
0
3
A
Shortest path of the king
PROGRAMMING
1,000
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le...
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago...
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
0
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" ...
1,608,351,595
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
280
0
import sys def rf(): lines = [] while True: try: lines.append(input()) except: break return lines def ri(): return int(input()) def rl(): return list(map(int,input().split())) start = input() arrival = input() alphabet = "abcdefgh"...
Title: Shortest path of the king Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ...
```python import sys def rf(): lines = [] while True: try: lines.append(input()) except: break return lines def ri(): return int(input()) def rl(): return list(map(int,input().split())) start = input() arrival = input() alphabet = ...
0
745
A
Hongcow Learns the Cyclic Shift
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ...
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
[ "abcd\n", "bbb\n", "yzyz\n" ]
[ "4\n", "1\n", "2\n" ]
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
500
[ { "input": "abcd", "output": "4" }, { "input": "bbb", "output": "1" }, { "input": "yzyz", "output": "2" }, { "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25" }, { "input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "output": "14...
1,481,992,790
290
Python 3
OK
TESTS
28
62
4,608,000
import sys import math #sz, x = [int(i) for i in input().split()] #ar = [int(i) for i in input().split()] st=str(input()) mp={} for i in range(len(st)+2): st=st[1:]+st[0] #print(st) mp[st]=1 print(len(mp))
Title: Hongcow Learns the Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to m...
```python import sys import math #sz, x = [int(i) for i in input().split()] #ar = [int(i) for i in input().split()] st=str(input()) mp={} for i in range(len(st)+2): st=st[1:]+st[0] #print(st) mp[st]=1 print(len(mp)) ```
3
855
B
Marvolo Gaunt's Ring
PROGRAMMING
1,500
[ "brute force", "data structures", "dp" ]
null
null
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he...
First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*.
[ "5 1 2 3\n1 2 3 4 5\n", "5 1 2 -3\n-1 -2 -3 -4 -5\n" ]
[ "30\n", "12\n" ]
In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
1,000
[ { "input": "5 1 2 3\n1 2 3 4 5", "output": "30" }, { "input": "5 1 2 -3\n-1 -2 -3 -4 -5", "output": "12" }, { "input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "output": "376059240645059046" }, { "input": "4 -96405765 -495906217 6...
1,581,880,385
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
22
358
9,625,600
maxi=ks=-4534554 l=list(map(int,input().split())) l1=list(map(int,input().split())) r_list,p_list=[0]*len(l1),[0]*len(l1) r_list[-1]=l[3]*l1[-1] p_list[0]=l1[0]*l[1] for i in range(len(l1)-2,-1,-1): r_list[i]=max(r_list[i+1],l1[i]*l[3]) for i in range(1,len(l1)): p_list[i]=max(p_list[i-1],l[1]*l1[i]) ...
Title: Marvolo Gaunt's Ring Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed i...
```python maxi=ks=-4534554 l=list(map(int,input().split())) l1=list(map(int,input().split())) r_list,p_list=[0]*len(l1),[0]*len(l1) r_list[-1]=l[3]*l1[-1] p_list[0]=l1[0]*l[1] for i in range(len(l1)-2,-1,-1): r_list[i]=max(r_list[i+1],l1[i]*l[3]) for i in range(1,len(l1)): p_list[i]=max(p_list[i-1],l[1...
0
351
A
Jeff and Rounding
PROGRAMMING
1,800
[ "dp", "greedy", "implementation", "math" ]
null
null
Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operations, each of them goes as follows: - choose indexes *i* and *j* (*i*<=≠<=*j*) that haven't been chose...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains 2*n* real numbers *a*1, *a*2, ..., *a*2*n* (0<=≤<=*a**i*<=≤<=10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
[ "3\n0.000 0.500 0.750 1.000 2.000 3.000\n", "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\n" ]
[ "0.250\n", "0.279\n" ]
In the first test case you need to perform the operations as follows: (*i* = 1, *j* = 4), (*i* = 2, *j* = 3), (*i* = 5, *j* = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
1,000
[ { "input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250" }, { "input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279" }, { "input": "3\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000", "output": "0.184" }, { "input": "3\n6470....
1,517,490,787
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
124
5,632,000
n = int(input()) l = list(map(float, input().split())) l = sorted([x - int(x) for x in l]) su = sum(l) print("%.3f" % abs(round(su) - su))
Title: Jeff and Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operati...
```python n = int(input()) l = list(map(float, input().split())) l = sorted([x - int(x) for x in l]) su = sum(l) print("%.3f" % abs(round(su) - su)) ```
0
769
A
Year of University Entrance
PROGRAMMING
800
[ "*special", "implementation", "sortings" ]
null
null
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups f...
The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined. The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed tha...
Print the year of Igor's university entrance.
[ "3\n2014 2016 2015\n", "1\n2050\n" ]
[ "2015\n", "2050\n" ]
In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance.
500
[ { "input": "3\n2014 2016 2015", "output": "2015" }, { "input": "1\n2050", "output": "2050" }, { "input": "1\n2010", "output": "2010" }, { "input": "1\n2011", "output": "2011" }, { "input": "3\n2010 2011 2012", "output": "2011" }, { "input": "3\n2049 20...
1,489,232,030
2,147,483,647
Python 3
OK
TESTS
45
62
4,608,000
__author__ = "Ryabchun Vladimir" n = int(input()) sum_years = 0 groups = list(map(int, input().split())) for elem in groups: sum_years += elem print(int(sum_years / n))
Title: Year of University Entrance Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of correspond...
```python __author__ = "Ryabchun Vladimir" n = int(input()) sum_years = 0 groups = list(map(int, input().split())) for elem in groups: sum_years += elem print(int(sum_years / n)) ```
3
437
A
The Child and Homework
PROGRAMMING
1,300
[ "implementation" ]
null
null
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The chi...
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description...
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
[ "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n", "A.ab\nB.abcde\nC.ab\nD.abc\n", "A.c\nB.cc\nC.c\nD.c\n" ]
[ "D\n", "C\n", "B\n" ]
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D. In the second sample, no ...
500
[ { "input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute", "output": "D" }, { "input": "A.ab\nB.abcde\nC.ab\nD.abc", "output": "C" }, { "input": "A.c\nB.cc\nC.c\nD.c", "output": "B" }, ...
1,512,039,502
1,102
PyPy 3
WRONG_ANSWER
TESTS
27
140
23,040,000
a = input() b = input() c = input() d = input() arr = [len(a)-2,len(b)-2,len(c)-2,len(d)-2] ak = min(arr) am = max(arr) flag,flag2=0,0 for i in range(4): if 2*ak<=arr[i]: flag+=1 if am>=2*arr[i]: flag2+=1 if flag2>=3: print(chr(arr.index(am)+65)) elif flag>=3: print(chr(arr.index(ak)+65)) else: print('C')
Title: The Child and Homework Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin...
```python a = input() b = input() c = input() d = input() arr = [len(a)-2,len(b)-2,len(c)-2,len(d)-2] ak = min(arr) am = max(arr) flag,flag2=0,0 for i in range(4): if 2*ak<=arr[i]: flag+=1 if am>=2*arr[i]: flag2+=1 if flag2>=3: print(chr(arr.index(am)+65)) elif flag>=3: print(chr(arr.index(ak)+65)) else: print...
0
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least...
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, ...
1,580,304,441
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
218
0
n,k=map(int,input().split()) l=list(map(int,input().split())) count=0 for i in range(n-1): if l[i]<l[i+1]: count+=1 elif l[i]<l[i+1]+k: count+=1 print(count)
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*...
```python n,k=map(int,input().split()) l=list(map(int,input().split())) count=0 for i in range(n-1): if l[i]<l[i+1]: count+=1 elif l[i]<l[i+1]+k: count+=1 print(count) ```
0
760
B
Frodo and pillows
PROGRAMMING
1,500
[ "binary search", "greedy" ]
null
null
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge...
The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n" ]
[ "2\n", "4\n", "3\n" ]
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third exa...
1,000
[ { "input": "4 6 2", "output": "2" }, { "input": "3 10 3", "output": "4" }, { "input": "3 6 1", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000 1", "output": "1000000000" }, { ...
1,557,819,883
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
108
0
n, m, k = map(int, input().split()) m -= n def valid(x): a = min(k - 1, x - 1) b = min(n - k, x - 1) s1 = a * (x - 1 + x - a) // 2 s2 = b * (x - 1 + x - b) // 2 return s1 + s2 + x <= m l, r = -1, (1<<62) while r > l+1: m = l + r >> 1 if valid(m): l = m else: ...
Title: Frodo and pillows Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma...
```python n, m, k = map(int, input().split()) m -= n def valid(x): a = min(k - 1, x - 1) b = min(n - k, x - 1) s1 = a * (x - 1 + x - a) // 2 s2 = b * (x - 1 + x - b) // 2 return s1 + s2 + x <= m l, r = -1, (1<<62) while r > l+1: m = l + r >> 1 if valid(m): l = m ...
0
977
F
Consecutive Subsequence
PROGRAMMING
1,700
[ "dp" ]
null
null
You are given an integer array of length $n$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $[x, x + 1, \dots, x + k - 1]$ for some value $x$ and length $k$. Su...
The first line of the input containing integer number $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array. The second line of the input containing $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the array itself.
On the first line print $k$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
[ "7\n3 3 4 7 5 6 8\n", "6\n1 3 5 2 4 6\n", "4\n10 9 8 7\n", "9\n6 7 8 3 4 5 9 10 11\n" ]
[ "4\n2 3 5 6 \n", "2\n1 4 \n", "1\n1 \n", "6\n1 2 3 7 8 9 \n" ]
All valid answers for the first example (as sequences of indices): - $[1, 3, 5, 6]$ - $[2, 3, 5, 6]$ All valid answers for the second example: - $[1, 4]$ - $[2, 5]$ - $[3, 6]$ All valid answers for the third example: - $[1]$ - $[2]$ - $[3]$ - $[4]$ All valid answers for the fourth example: - $[1, 2...
0
[ { "input": "7\n3 3 4 7 5 6 8", "output": "4\n2 3 5 6 " }, { "input": "6\n1 3 5 2 4 6", "output": "2\n1 4 " }, { "input": "4\n10 9 8 7", "output": "1\n1 " }, { "input": "9\n6 7 8 3 4 5 9 10 11", "output": "6\n1 2 3 7 8 9 " }, { "input": "1\n1337", "output": "1\...
1,698,337,981
7,081
PyPy 3-64
WRONG_ANSWER
TESTS
4
124
20,787,200
n = int(input()) a = {} num = list(map(int,input().split())) for i in range(n): x = num[i] if x not in a: if (x+1) not in a: a[x+1] = [i+1] else: tmp = a[x] a[x+1] = tmp a[x+1].append(i+1) del a[x] mx = 0 for elem in a: mx = max(mx, le...
Title: Consecutive Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer array of length $n$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words t...
```python n = int(input()) a = {} num = list(map(int,input().split())) for i in range(n): x = num[i] if x not in a: if (x+1) not in a: a[x+1] = [i+1] else: tmp = a[x] a[x+1] = tmp a[x+1].append(i+1) del a[x] mx = 0 for elem in a: mx = ...
0
548
A
Mike and Fax
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ...
The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000). The second line contains integer *k* (1<=≤<=*k*<=≤<=1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
[ "saba\n2\n", "saddastavvat\n2\n" ]
[ "NO\n", "YES\n" ]
Palindrome is a string reading the same forward and backward. In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
500
[ { "input": "saba\n2", "output": "NO" }, { "input": "saddastavvat\n2", "output": "YES" }, { "input": "aaaaaaaaaa\n3", "output": "NO" }, { "input": "aaaaaa\n3", "output": "YES" }, { "input": "abaacca\n2", "output": "NO" }, { "input": "a\n1", "output"...
1,432,659,454
1,354
Python 3
RUNTIME_ERROR
PRETESTS
0
139
7,372,800
from tkinter import * p = [300,400,"green"] line = [20,5] """ def move(self): canvas.create_line(p[0],p[1],p[0],p[1] - line[0],width=line[1],fill=p[2]) p[1] -= line[0] """ def Up(self): canvas.create_line(p[0],p[1],p[0],p[1] - line[0],width=line[1],fill=p[2]) p[1] -= line[0] def Down(s...
Title: Mike and Fax Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure ...
```python from tkinter import * p = [300,400,"green"] line = [20,5] """ def move(self): canvas.create_line(p[0],p[1],p[0],p[1] - line[0],width=line[1],fill=p[2]) p[1] -= line[0] """ def Up(self): canvas.create_line(p[0],p[1],p[0],p[1] - line[0],width=line[1],fill=p[2]) p[1] -= line[0] ...
-1
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ...
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481...
1,693,303,353
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
inpt = input() .split(" ") heights= input().split(" ") i=0 for i in range(int(inpt[0])): if int(heights[i])>int(inpt[1]): i+=2 else : i+=1 print(f"the width is :{i}")
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers...
```python inpt = input() .split(" ") heights= input().split(" ") i=0 for i in range(int(inpt[0])): if int(heights[i])>int(inpt[1]): i+=2 else : i+=1 print(f"the width is :{i}") ```
0
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "...
1,622,256,830
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
word = input() ans = 0 current = 'a' for x in word: way1 = abs(ord(x) - 26 - ord(current)) way2 = abs(ord(x) - ord(current)) ans += min(way1, way2) current = x print(ans)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devis...
```python word = input() ans = 0 current = 'a' for x in word: way1 = abs(ord(x) - 26 - ord(current)) way2 = abs(ord(x) - ord(current)) ans += min(way1, way2) current = x print(ans) ```
0
4
D
Mysterious Present
PROGRAMMING
1,700
[ "dp", "sortings" ]
D. Mysterious Present
1
64
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes *A*<==<={*a*1,<=<=*a*2,<=<=...,<=<=*a**n*}, where the width and the height of the *i*-th envelope is strictly higher than the...
The first line contains integers *n*, *w*, *h* (1<=<=≤<=*n*<=≤<=5000, 1<=≤<=*w*,<=<=*h*<=<=≤<=106) — amount of envelopes Peter has, the card width and height respectively. Then there follow *n* lines, each of them contains two integer numbers *w**i* and *h**i* — width and height of the *i*-th envelope (1<=≤<=*w**i*,<=<...
In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, pr...
[ "2 1 1\n2 2\n2 2\n", "3 3 3\n5 4\n12 11\n9 8\n" ]
[ "1\n1 \n", "3\n1 3 2 \n" ]
none
0
[ { "input": "2 1 1\n2 2\n2 2", "output": "1\n1 " }, { "input": "3 3 3\n5 4\n12 11\n9 8", "output": "3\n1 3 2 " }, { "input": "5 10 10\n22 23\n17 19\n13 17\n8 12\n2 6", "output": "3\n3 2 1 " }, { "input": "5 13 13\n4 4\n10 10\n7 7\n1 1\n13 13", "output": "0" }, { "i...
1,689,018,967
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
62
0
import sys input = lambda: sys.stdin.readline().rstrip() from collections import Counter,defaultdict N,W,H = map(int, input().split()) A = [] for _ in range(N): w,h = map(int, input().split()) A.append((w,h)) A.sort() dp = defaultdict(list) for i,(w,h) in enumerate(A): if w<=W or h<=H:continu...
Title: Mysterious Present Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes *A*<==<={*a*1,<=<=*a*2,<=<...
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import Counter,defaultdict N,W,H = map(int, input().split()) A = [] for _ in range(N): w,h = map(int, input().split()) A.append((w,h)) A.sort() dp = defaultdict(list) for i,(w,h) in enumerate(A): if w<=W or h<...
0
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,665,299,760
2,147,483,647
Python 3
OK
TESTS
41
108
0
a = int(input()) if a % 2 == 0: print(a//2) else: a = a-3 print(a//2+1) print("3", end=" ") for i in range(a//2): print("2", end=" ")
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. ...
```python a = int(input()) if a % 2 == 0: print(a//2) else: a = a-3 print(a//2+1) print("3", end=" ") for i in range(a//2): print("2", end=" ") ```
3
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,683,449,258
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
import sys input = sys.stdin.readline # from collections import Counter a,b = [int(a) for a in input().split()] def gcd(a, b): if b == 0: return a return gcd(b, a % b) if a==b: print(a) elif a>b: print(gcd(a,b)) else: print(gcd(b,a))
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 import sys input = sys.stdin.readline # from collections import Counter a,b = [int(a) for a in input().split()] def gcd(a, b): if b == 0: return a return gcd(b, a % b) if a==b: print(a) elif a>b: print(gcd(a,b)) else: print(gcd(b,a)) ```
0
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ...
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "i...
1,693,229,805
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
a,b,c,d,m = map(int, input().split(" ")) count = 0 for i in range(1, m+1): if (i%a==0) or (i%b==0) or (i%c==0) or (i%d==0): count +=1 print(count)
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entert...
```python a,b,c,d,m = map(int, input().split(" ")) count = 0 for i in range(1, m+1): if (i%a==0) or (i%b==0) or (i%c==0) or (i%d==0): count +=1 print(count) ```
-1
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "outp...
1,628,668,985
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
6,656,000
n=input() x=set(n) x="".join(x) print(len(n)-len(x))
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di...
```python n=input() x=set(n) x="".join(x) print(len(n)-len(x)) ```
0
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,690,559,235
2,147,483,647
Python 3
OK
TESTS
71
92
0
# your code goes here def main(): no_of_stops = int(input()) minimum_capacity = 0 no_of_people_on_train = 0 for i in range(1, no_of_stops + 1): no_of_exits, no_of_entries = map(int, input().split()) no_of_people_on_train += (no_of_entries - no_of_exits) minimum_capaci...
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 # your code goes here def main(): no_of_stops = int(input()) minimum_capacity = 0 no_of_people_on_train = 0 for i in range(1, no_of_stops + 1): no_of_exits, no_of_entries = map(int, input().split()) no_of_people_on_train += (no_of_entries - no_of_exits) mini...
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,699,615,060
2,147,483,647
Python 3
OK
TESTS
21
92
0
s = input() l = [] for i in s: if i.isdigit(): l.append(i) l.sort() for i in range(len(l)): print(l[i], end="") if i != len(l) - 1: print("+", end="")
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 s = input() l = [] for i in s: if i.isdigit(): l.append(i) l.sort() for i in range(len(l)): print(l[i], end="") if i != len(l) - 1: print("+", end="") ```
3
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" },...
1,698,833,404
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
a=input() b=list(a) c=len(a) count=0 d=str("qwertyuiopasdfghjklzxcvbnm") l=list(d) for i in range(26): ce=b.count(d[i]) count+=ce-1 c-=count if c%2==0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though...
```python a=input() b=list(a) c=len(a) count=0 d=str("qwertyuiopasdfghjklzxcvbnm") l=list(d) for i in range(26): ce=b.count(d[i]) count+=ce-1 c-=count if c%2==0: print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
0
525
B
Pasha and String
PROGRAMMING
1,400
[ "constructive algorithms", "greedy", "math", "strings" ]
null
null
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string. Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ...
The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters. The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) —  the number of days when Pasha changed his string. The third line contains *m* space-separated elements *a**i* (1<=≤<...
In the first line of the output print what Pasha's string *s* will look like after *m* days.
[ "abcdef\n1\n2\n", "vwxyz\n2\n2 2\n", "abcdef\n3\n1 2 3\n" ]
[ "aedcbf\n", "vwxyz\n", "fbdcea\n" ]
none
750
[ { "input": "abcdef\n1\n2", "output": "aedcbf" }, { "input": "vwxyz\n2\n2 2", "output": "vwxyz" }, { "input": "abcdef\n3\n1 2 3", "output": "fbdcea" }, { "input": "jc\n5\n1 1 1 1 1", "output": "cj" }, { "input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3", "out...
1,427,389,219
1,819
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
6
2,000
7,577,600
gift=input() n=int(input()) L=[int(x) for x in input().split()] slen=len(gift) for i in L: i-=1 gift=gift[:i:]+gift[i:slen-i:][::-1]+gift[slen-i::] print(gift)
Title: Pasha and String Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ...
```python gift=input() n=int(input()) L=[int(x) for x in input().split()] slen=len(gift) for i in L: i-=1 gift=gift[:i:]+gift[i:slen-i:][::-1]+gift[slen-i::] print(gift) ```
0