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
526
C
Om Nom and Candies
PROGRAMMING
2,000
[ "brute force", "greedy", "math" ]
null
null
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? One day, when he came to his friend Evan, Om Nom didn't find him at home but h...
The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109).
Print a single integer — the maximum number of joy units that Om Nom can get.
[ "10 3 5 2 3\n" ]
[ "16\n" ]
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
1,250
[ { "input": "10 3 5 2 3", "output": "16" }, { "input": "5 3 1 6 7", "output": "0" }, { "input": "982068341 55 57 106 109", "output": "513558662" }, { "input": "930064129 32726326 25428197 83013449 64501049", "output": "363523396" }, { "input": "927155987 21197 1599...
1,689,167,495
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689167495.5827782")# 1689167495.582819
Title: Om Nom and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task i...
```python print("_RANDOM_GUESS_1689167495.5827782")# 1689167495.582819 ```
0
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,632,507,312
2,147,483,647
Python 3
OK
TESTS
43
77
6,758,400
count = 0 string = input() for i, char in enumerate(string): if char == 'A': count += string[:i].count('Q') * string[i:].count('Q') print(count)
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 count = 0 string = input() for i, char in enumerate(string): if char == 'A': count += string[:i].count('Q') * string[i:].count('Q') print(count) ```
3
342
C
Cupboard and Balloons
PROGRAMMING
1,900
[ "geometry" ]
null
null
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is *r*, that is, it looks like a rectangle with base *r* and height *h*<=+<=*r* from the sides. The figure be...
The single line contains two integers *r*,<=*h* (1<=≤<=*r*,<=*h*<=≤<=107).
Print a single integer — the maximum number of balloons Xenia can put in the cupboard.
[ "1 1\n", "1 2\n", "2 1\n" ]
[ "3\n", "5\n", "2\n" ]
none
1,500
[ { "input": "1 1", "output": "3" }, { "input": "1 2", "output": "5" }, { "input": "2 1", "output": "2" }, { "input": "2 2", "output": "3" }, { "input": "2 3", "output": "4" }, { "input": "4 1", "output": "1" }, { "input": "5 1", "output"...
1,553,083,001
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
248
0
r, h=map(int,input().split()) if h// r : print((h//r)*2 +1) else: print(2)
Title: Cupboard and Balloons Time Limit: None seconds Memory Limit: None megabytes Problem Description: A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is...
```python r, h=map(int,input().split()) if h// r : print((h//r)*2 +1) else: print(2) ```
0
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integer...
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { ...
1,659,220,033
2,147,483,647
Python 3
OK
TESTS
34
92
0
n = [int(x) for x in input().split()] s = input().split() count = 0 for i in range(0, n[0]): count2 = 0 for j in range(0, len(s[i])): if s[i][j] == "4" or s[i][j] == "7": count2 += 1 if count2 <= n[1]: count += 1 print(count)
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits...
```python n = [int(x) for x in input().split()] s = input().split() count = 0 for i in range(0, n[0]): count2 = 0 for j in range(0, len(s[i])): if s[i][j] == "4" or s[i][j] == "7": count2 += 1 if count2 <= n[1]: count += 1 print(count) ```
3
0
none
none
none
0
[ "none" ]
null
null
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of lines. Next *n* lines contain commands. A command consists of a character that represents the operation ("&amp;", "|" or "^" for AND, OR or XOR respectively), and the constant *x**i* 0<=≤<=*x**i*<=≤<=1023.
Output an integer *k* (0<=≤<=*k*<=≤<=5) — the length of your program. Next *k* lines must contain commands in the same format as in the input.
[ "3\n| 3\n^ 2\n| 1\n", "3\n&amp; 1\n&amp; 3\n&amp; 5\n", "3\n^ 1\n^ 2\n^ 3\n" ]
[ "2\n| 3\n^ 2\n", "1\n&amp; 1\n", "0\n" ]
You can read about bitwise operations in [https://en.wikipedia.org/wiki/Bitwise_operation](https://en.wikipedia.org/wiki/Bitwise_operation). Second sample: Let *x* be an input of the Petya's program. It's output is ((*x*&amp;1)&amp;3)&amp;5 = *x*&amp;(1&amp;3&amp;5) = *x*&amp;1. So these two programs always give the ...
0
[ { "input": "3\n| 3\n^ 2\n| 1", "output": "2\n| 3\n^ 2" }, { "input": "3\n& 1\n& 3\n& 5", "output": "1\n& 1" }, { "input": "3\n^ 1\n^ 2\n^ 3", "output": "0" }, { "input": "2\n| 999\n^ 689", "output": "2\n| 999\n^ 689" }, { "input": "3\n& 242\n^ 506\n^ 522", "ou...
1,522,688,212
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
7,065,600
n = int(input()) zero = 0 ones = 1023 for _ in range(n): op, num = input().split() num = int(num) if op == '&': zero &= num ones &= num elif op == '|': zero |= num ones |= num else: zero ^= num ones ^= num and_bits = 0 ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise opera...
```python n = int(input()) zero = 0 ones = 1023 for _ in range(n): op, num = input().split() num = int(num) if op == '&': zero &= num ones &= num elif op == '|': zero |= num ones |= num else: zero ^= num ones ^= num and...
0
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the h...
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th...
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "inp...
1,693,270,148
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
x = input() p = [] y = x.split(" ") for i in y: p.append(int(i)) x = input() L = [] y = x.split(" ") for i in y: L.append(int(i)) L = [1,2,6,1,1,7,1] n = p[0] k = p[1] if n == k: print(sum(L)) else: s = 0 for i in range(k): s = s+L[i] ind = 1 minc = s f...
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ...
```python x = input() p = [] y = x.split(" ") for i in y: p.append(int(i)) x = input() L = [] y = x.split(" ") for i in y: L.append(int(i)) L = [1,2,6,1,1,7,1] n = p[0] k = p[1] if n == k: print(sum(L)) else: s = 0 for i in range(k): s = s+L[i] ind = 1 minc ...
0
999
E
Reachability from the Capital
PROGRAMMING
2,000
[ "dfs and similar", "graphs", "greedy" ]
null
null
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way.
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$. The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_...
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
[ "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n", "5 4 5\n1 2\n2 3\n3 4\n4 1\n" ]
[ "3\n", "1\n" ]
The first example is illustrated by the following: For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$. The second example is illustrated by the following: In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the ci...
0
[ { "input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "output": "3" }, { "input": "5 4 5\n1 2\n2 3\n3 4\n4 1", "output": "1" }, { "input": "5000 0 2956", "output": "4999" }, { "input": "2 0 2", "output": "1" }, { "input": "2 1 1\n1 2", "output": "0"...
1,643,256,519
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
1,060
9,625,600
""" -*- coding: utf-8 -*- Created on Wed Jan 26 14:30:20 2022 @author: Tausif Khan Arnob """ R = lambda:map(int, input().split()) n, m, s = R() graph = [[] for _ in range(n)] for _ in range(m): x, y = R() graph[x - 1].append(y - 1) # print('Graph:') # print(*graph, sep = '\n') re...
Title: Reachability from the Capital Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities r...
```python """ -*- coding: utf-8 -*- Created on Wed Jan 26 14:30:20 2022 @author: Tausif Khan Arnob """ R = lambda:map(int, input().split()) n, m, s = R() graph = [[] for _ in range(n)] for _ in range(m): x, y = R() graph[x - 1].append(y - 1) # print('Graph:') # print(*graph, sep = '...
0
711
A
Bus to Udayland
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied. ZS and Chris a...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus. Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t...
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ...
[ "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n", "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n", "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n" ]
[ "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n", "NO\n", "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n" ]
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair. O+|+X XO|XX OX|OO XX|OX OO|OO OO|XX
500
[ { "input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX" }, { "input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO" }, { "input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO" ...
1,668,841,535
2,147,483,647
PyPy 3-64
OK
TESTS
71
109
3,481,600
f = 1 ans = [] for i in range(int(input())): a = input() if 'OO' in a and f: ans.append(a.replace('OO','++',1)) f = 0 else: ans.append(a) if f: print('NO') else: print('YES') print(*ans,sep='\n')
Title: Bus to Udayland Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai...
```python f = 1 ans = [] for i in range(int(input())): a = input() if 'OO' in a and f: ans.append(a.replace('OO','++',1)) f = 0 else: ans.append(a) if f: print('NO') else: print('YES') print(*ans,sep='\n') ```
3
994
B
Knights of a Polygonal Table
PROGRAMMING
1,400
[ "greedy", "implementation", "sortings" ]
null
null
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo...
The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement. The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct. The third line contains $n...
Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights.
[ "4 2\n4 5 9 7\n1 2 11 33\n", "5 1\n1 2 3 4 5\n1 2 3 4 5\n", "1 0\n2\n3\n" ]
[ "1 3 46 36 ", "1 3 5 7 9 ", "3 " ]
Consider the first example. - The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o...
1,000
[ { "input": "4 2\n4 5 9 7\n1 2 11 33", "output": "1 3 46 36 " }, { "input": "5 1\n1 2 3 4 5\n1 2 3 4 5", "output": "1 3 5 7 9 " }, { "input": "1 0\n2\n3", "output": "3 " }, { "input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9", "output": "0 3 10 16 14 17 18 " }, { "input"...
1,673,933,367
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
102,400
from functools import reduce n , k = [*map(int,input().split())] arr = [*map(int,input().split())] crr = [*map(int,input().split())] brr = sorted([[arr [i], crr [i] , i] for i in range (n)], key = lambda p: p [0]) pref = 0 ans = [0] * n for i in range(n): pref += brr[i][1] if i > k: pref -= ...
Title: Knights of a Polygonal Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ...
```python from functools import reduce n , k = [*map(int,input().split())] arr = [*map(int,input().split())] crr = [*map(int,input().split())] brr = sorted([[arr [i], crr [i] , i] for i in range (n)], key = lambda p: p [0]) pref = 0 ans = [0] * n for i in range(n): pref += brr[i][1] if i > k: ...
0
358
B
Dima and Text Messages
PROGRAMMING
1,500
[ "brute force", "strings" ]
null
null
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got...
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
[ "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n" ]
[ "yes\n", "no\n" ]
Please note that Dima got a good old kick in the pants for the second sample from the statement.
1,000
[ { "input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes" }, { "input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3", "output": "yes" }, { "input": "4\na\n...
1,668,112,351
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
""" https://codeforces.com/problemset/problem/358/B """ tests = int(input()) texts = [] for _ in range(tests + 1): texts.append(input()) def trouve_i3(text): if (v:=text.find('<'))>-1 and text.find('3')>v: return True return False a = texts[-1] res = [] i = 0 possible = True #trouve les mots for c...
Title: Dima and Text Messages Time Limit: None seconds Memory Limit: None megabytes Problem Description: Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today t...
```python """ https://codeforces.com/problemset/problem/358/B """ tests = int(input()) texts = [] for _ in range(tests + 1): texts.append(input()) def trouve_i3(text): if (v:=text.find('<'))>-1 and text.find('3')>v: return True return False a = texts[-1] res = [] i = 0 possible = True #trouve les ...
0
990
G
GCD Counting
PROGRAMMING
2,400
[ "divide and conquer", "dp", "dsu", "number theory", "trees" ]
null
null
You are given a tree consisting of $n$ vertices. A number is written on each vertex; the number on vertex $i$ is equal to $a_i$. Let's denote the function $g(x, y)$ as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex $x$ to vertex $y$ (including these two vert...
The first line contains one integer $n$ — the number of vertices $(1 \le n \le 2 \cdot 10^5)$. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le 2 \cdot 10^5)$ — the numbers written on vertices. Then $n - 1$ lines follow, each containing two integers $x$ and $y$ $(1 \le x, y \le n, x \ne ...
For every integer $i$ from $1$ to $2 \cdot 10^5$ do the following: if there is no pair $(x, y)$ such that $x \le y$ and $g(x, y) = i$, don't output anything. Otherwise output two integers: $i$ and the number of aforementioned pairs. You have to consider the values of $i$ in ascending order. See the examples for better...
[ "3\n1 2 3\n1 2\n2 3\n", "6\n1 2 4 8 16 32\n1 6\n6 3\n3 4\n4 2\n6 5\n", "4\n9 16 144 6\n1 3\n2 3\n4 3\n" ]
[ "1 4\n2 1\n3 1\n", "1 6\n2 5\n4 6\n8 1\n16 2\n32 1\n", "1 1\n2 1\n3 1\n6 2\n9 2\n16 2\n144 1\n" ]
none
0
[ { "input": "3\n1 2 3\n1 2\n2 3", "output": "1 4\n2 1\n3 1" }, { "input": "6\n1 2 4 8 16 32\n1 6\n6 3\n3 4\n4 2\n6 5", "output": "1 6\n2 5\n4 6\n8 1\n16 2\n32 1" }, { "input": "4\n9 16 144 6\n1 3\n2 3\n4 3", "output": "1 1\n2 1\n3 1\n6 2\n9 2\n16 2\n144 1" }, { "input": "3\n1 ...
1,634,928,884
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
4
4,500
72,908,800
from collections import deque import sys input = sys.stdin.buffer.readline def divisor(i): s = [] for j in range(1, int(i ** (1 / 2)) + 1): if i % j == 0: s.append(i // j) s.append(j) return sorted(set(s), reverse = True) def bfs(s, d, y): q = deque() ...
Title: GCD Counting Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tree consisting of $n$ vertices. A number is written on each vertex; the number on vertex $i$ is equal to $a_i$. Let's denote the function $g(x, y)$ as the greatest common divisor of the numbers written on...
```python from collections import deque import sys input = sys.stdin.buffer.readline def divisor(i): s = [] for j in range(1, int(i ** (1 / 2)) + 1): if i % j == 0: s.append(i // j) s.append(j) return sorted(set(s), reverse = True) def bfs(s, d, y): q = deq...
0
746
A
Compote
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — ...
The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has...
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
[ "2\n5\n7\n", "4\n7\n13\n", "2\n3\n2\n" ]
[ "7\n", "21\n", "0\n" ]
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
500
[ { "input": "2\n5\n7", "output": "7" }, { "input": "4\n7\n13", "output": "21" }, { "input": "2\n3\n2", "output": "0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n4", "output": "7" }, { "input": "1000\n1000\n1000", "output": "1750" }...
1,655,917,511
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
a,b,c = map(int, input().split()) a //= 1 b //= 2 c //= 4 m = min(a,b,c) print(m * 7)
Title: Compote Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa...
```python a,b,c = map(int, input().split()) a //= 1 b //= 2 c //= 4 m = min(a,b,c) print(m * 7) ```
-1
479
C
Exams
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a st...
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i...
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
[ "3\n5 2\n3 1\n4 2\n", "3\n6 1\n5 2\n4 3\n" ]
[ "2\n", "6\n" ]
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark ...
1,500
[ { "input": "3\n5 2\n3 1\n4 2", "output": "2" }, { "input": "3\n6 1\n5 2\n4 3", "output": "6" }, { "input": "1\n1000000000 999999999", "output": "999999999" }, { "input": "1\n2 1", "output": "1" }, { "input": "2\n3 2\n3 2", "output": "2" }, { "input": "...
1,696,859,162
2,147,483,647
PyPy 3-64
OK
TESTS
53
155
5,734,400
n = int(input()) exams = [] for i in range(n): exams.append(list(map(int, input().split()))) # print(exams) exams.sort() start = exams[0][1] # print(exams) for s,e in exams: # print(vals) if e >= start: start = e else: start = s # print(vals) print(start)
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Beside...
```python n = int(input()) exams = [] for i in range(n): exams.append(list(map(int, input().split()))) # print(exams) exams.sort() start = exams[0][1] # print(exams) for s,e in exams: # print(vals) if e >= start: start = e else: start = s # print(vals) print(...
3
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul...
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter t...
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input":...
1,659,997,452
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
x=input() y=input() z=input() theList=['','','','',''] error=1 Xsplit=list(x) if Xsplit[1] == '>': theList[1]=Xsplit[0] theList[3] = Xsplit[2] elif Xsplit[1] == '<': theList[1]=Xsplit[2] theList[3] = Xsplit[0] Ysplit=list(y) if Ysplit[1] == '<': if Ysplit[2] in Xsplit: loc...
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ...
```python x=input() y=input() z=input() theList=['','','','',''] error=1 Xsplit=list(x) if Xsplit[1] == '>': theList[1]=Xsplit[0] theList[3] = Xsplit[2] elif Xsplit[1] == '<': theList[1]=Xsplit[2] theList[3] = Xsplit[0] Ysplit=list(y) if Ysplit[1] == '<': if Ysplit[2] in Xsplit: ...
-1
761
A
Dasha and Stairs
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ...
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
[ "2 3\n", "3 1\n" ]
[ "YES\n", "NO\n" ]
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
500
[ { "input": "2 3", "output": "YES" }, { "input": "3 1", "output": "NO" }, { "input": "5 4", "output": "YES" }, { "input": "9 9", "output": "YES" }, { "input": "85 95", "output": "NO" }, { "input": "0 1", "output": "YES" }, { "input": "89 25"...
1,486,239,522
2,147,483,647
Python 3
OK
TESTS
21
62
4,608,000
n,m=map(int, input().split()) if n==0 and m==0: print('NO') elif abs(n-m)<=1: print('YES') else: print('NO')
Title: Dasha and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so...
```python n,m=map(int, input().split()) if n==0 and m==0: print('NO') elif abs(n-m)<=1: print('YES') else: print('NO') ```
3
766
B
Mahmoud and a Triangle
PROGRAMMING
1,000
[ "constructive algorithms", "geometry", "greedy", "math", "number theory", "sortings" ]
null
null
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments...
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
[ "5\n1 5 3 2 4\n", "3\n4 1 2\n" ]
[ "YES\n", "NO\n" ]
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
1,000
[ { "input": "5\n1 5 3 2 4", "output": "YES" }, { "input": "3\n4 1 2", "output": "NO" }, { "input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576", "output": "NO" },...
1,699,153,433
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
77
0
n = int(input()) a = list(map(int, input().split())) a.sort() l = a[0] r = a[1] flag = True for c in range(2, n): m = a[c] if l + r > m and l + m > r and m + r > l: print("YES") flag = False break if flag: print("NO")
Title: Mahmoud and a Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he ca...
```python n = int(input()) a = list(map(int, input().split())) a.sort() l = a[0] r = a[1] flag = True for c in range(2, n): m = a[c] if l + r > m and l + m > r and m + r > l: print("YES") flag = False break if flag: print("NO") ```
0
962
D
Merge Equals
PROGRAMMING
1,600
[ "data structures", "implementation" ]
null
null
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two...
The first line contains a single integer $n$ ($2 \le n \le 150\,000$) — the number of elements in the array. The second line contains a sequence from $n$ elements $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{9}$) — the elements of the array.
In the first line print an integer $k$ — the number of elements in the array after all the performed operations. In the second line print $k$ integers — the elements of the array after all the performed operations.
[ "7\n3 4 1 2 2 1 1\n", "5\n1 1 3 1 1\n", "5\n10 40 20 50 30\n" ]
[ "4\n3 8 2 1 \n", "2\n3 4 \n", "5\n10 40 20 50 30 \n" ]
The first two examples were considered in the statement. In the third example all integers in the given array are distinct, so it will not change.
0
[ { "input": "7\n3 4 1 2 2 1 1", "output": "4\n3 8 2 1 " }, { "input": "5\n1 1 3 1 1", "output": "2\n3 4 " }, { "input": "5\n10 40 20 50 30", "output": "5\n10 40 20 50 30 " }, { "input": "100\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 1...
1,567,155,559
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
264
11,571,200
n = int(input()) A = list(map(int, input().split())) inds = {} counter = {} topop = set() i = 0 c = 0 for __ in range(10 ** 6): if i not in topop: if A[i] in inds and inds[A[i]] not in topop: topop.add(inds[A[i]]) A[i] *= 2 c += 1 inds[A[i]] = i i += 1 if ...
Title: Merge Equals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first...
```python n = int(input()) A = list(map(int, input().split())) inds = {} counter = {} topop = set() i = 0 c = 0 for __ in range(10 ** 6): if i not in topop: if A[i] in inds and inds[A[i]] not in topop: topop.add(inds[A[i]]) A[i] *= 2 c += 1 inds[A[i]] = i i +=...
0
1,000
B
Light It Up
PROGRAMMING
1,500
[ "greedy" ]
null
null
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate...
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off. Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 &lt; a_1 &lt; a_2 &lt; \dots &lt; a_n &lt; M$) — initially installed progra...
Print the only integer — maximum possible total time when the lamp is lit.
[ "3 10\n4 6 7\n", "2 12\n1 10\n", "2 7\n3 4\n" ]
[ "8\n", "9\n", "6\n" ]
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place. In the second example, there is only one optimal so...
0
[ { "input": "3 10\n4 6 7", "output": "8" }, { "input": "2 12\n1 10", "output": "9" }, { "input": "2 7\n3 4", "output": "6" }, { "input": "1 2\n1", "output": "1" }, { "input": "5 10\n1 3 5 6 8", "output": "6" }, { "input": "7 1000000000\n1 10001 10011 20...
1,635,214,742
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
186
13,004,800
n,M = map(int,input().split()) k = list(map(int,input().split())) k.append(0) k.append(M) k.sort() r = [] l_odd = [] l_even = [] for i in range(1,len(k),2): s = k[i] - k[i-1] l_odd.append(s) for i in range(2,len(k),2): s = k[i] - k[i-1] l_even.append(s) l1 = sum(l_odd) l2 = ...
Title: Light It Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y...
```python n,M = map(int,input().split()) k = list(map(int,input().split())) k.append(0) k.append(M) k.sort() r = [] l_odd = [] l_even = [] for i in range(1,len(k),2): s = k[i] - k[i-1] l_odd.append(s) for i in range(2,len(k),2): s = k[i] - k[i-1] l_even.append(s) l1 = sum(l_o...
0
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 58697...
1,697,276,531
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
s1,s2,s3,s4=map(int,input().split()) s=str(s1)+str(s2)+str(s3)+str(s4) s=set(s) l=len(s) print(4-l)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ...
```python s1,s2,s3,s4=map(int,input().split()) s=str(s1)+str(s2)+str(s3)+str(s4) s=set(s) l=len(s) print(4-l) ```
0
90
A
Cableway
PROGRAMMING
1,000
[ "greedy", "math" ]
A. Cableway
2
256
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway. A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them ...
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=100). It is guaranteed that *r*<=+<=*g*<=+<=*b*<=&gt;<=0, it means that the group consists of at least one student.
Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain.
[ "1 3 2\n", "3 2 1\n" ]
[ "34", "33" ]
Let's analyze the first sample. At the moment of time 0 a red cablecar comes and one student from the *r* group get on it and ascends to the top at the moment of time 30. At the moment of time 1 a green cablecar arrives and two students from the *g* group get on it; they get to the top at the moment of time 31. At t...
500
[ { "input": "1 3 2", "output": "34" }, { "input": "3 2 1", "output": "33" }, { "input": "3 5 2", "output": "37" }, { "input": "10 10 10", "output": "44" }, { "input": "29 7 24", "output": "72" }, { "input": "28 94 13", "output": "169" }, { "...
1,583,955,751
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
216
307,200
r, g, b = map(int, input().split()) print(30 + max(r, g + 1, b + 2))
Title: Cableway Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway. A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cabl...
```python r, g, b = map(int, input().split()) print(30 + max(r, g + 1, b + 2)) ```
0
12
A
Super Agent
PROGRAMMING
800
[ "implementation" ]
A. Super Agent
2
256
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage...
Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
[ "XX.\n...\n.XX\n", "X.X\nX..\n...\n" ]
[ "YES\n", "NO\n" ]
If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry
0
[ { "input": "XX.\n...\n.XX", "output": "YES" }, { "input": ".X.\n.X.\n.X.", "output": "YES" }, { "input": "XXX\nXXX\nXXX", "output": "YES" }, { "input": "XXX\nX.X\nXXX", "output": "YES" }, { "input": "X..\n.X.\n..X", "output": "YES" }, { "input": "...\n...
1,618,048,774
2,147,483,647
Python 3
OK
TESTS
40
124
0
# -*- coding: utf-8 -*- """ Created on Tue Mar 30 19:32:51 2021 @author: nehas """ r1=input() r2=input() r3=input() if(r1[0]==r3[2] and r1[1]==r3[1] and r1[2]==r3[0] and r2[0]==r2[2]): print("YES") else: print("NO")
Title: Super Agent Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin...
```python # -*- coding: utf-8 -*- """ Created on Tue Mar 30 19:32:51 2021 @author: nehas """ r1=input() r2=input() r3=input() if(r1[0]==r3[2] and r1[1]==r3[1] and r1[2]==r3[0] and r2[0]==r2[2]): print("YES") else: print("NO") ```
3.969
709
A
Juicer
PROGRAMMING
900
[ "implementation" ]
null
null
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ...
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line co...
Print one integer — the number of times Kolya will have to empty the waste section.
[ "2 7 10\n5 6\n", "1 5 10\n7\n", "3 10 10\n5 7 7\n", "1 1 1\n1\n" ]
[ "1\n", "0\n", "1\n", "0\n" ]
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
500
[ { "input": "2 7 10\n5 6", "output": "1" }, { "input": "1 5 10\n7", "output": "0" }, { "input": "3 10 10\n5 7 7", "output": "1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 951637 951638\n44069 951637", "output": "1" }, { "input": "50 100 12...
1,687,613,448
2,147,483,647
PyPy 3-64
OK
TESTS
58
92
11,673,600
n,b,d = map(int,input().split()) ai = [int(x) for x in input().split()] empty = section = 0 for a in ai: if a <= b: section += a if section > d: section = 0 empty += 1 print(empty)
Title: Juicer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b...
```python n,b,d = map(int,input().split()) ai = [int(x) for x in input().split()] empty = section = 0 for a in ai: if a <= b: section += a if section > d: section = 0 empty += 1 print(empty) ```
3
287
A
IQ Test
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the...
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
[ "####\n.#..\n####\n....\n", "####\n....\n####\n....\n" ]
[ "YES\n", "NO\n" ]
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
500
[ { "input": "###.\n...#\n###.\n...#", "output": "NO" }, { "input": ".##.\n#..#\n.##.\n#..#", "output": "NO" }, { "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO" }, { "input": "##..\n..##\n##..\n..##", "output": "NO" }, { "input": "#.#.\n#.#.\n.#.#\n.#.#", "ou...
1,574,534,745
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
124
0
def rev(s): s1 = '' for i in s: if i=="#": s1+="." else: s1+="#" return s1 l1 = [] for _ in range(4): l1.append(input()) for i in range(1,4): if l1[i-1]==rev(l1[i]): pass else: print("YES") break else: print("N...
Title: IQ Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o...
```python def rev(s): s1 = '' for i in s: if i=="#": s1+="." else: s1+="#" return s1 l1 = [] for _ in range(4): l1.append(input()) for i in range(1,4): if l1[i-1]==rev(l1[i]): pass else: print("YES") break else: ...
0
33
A
What is for dinner?
PROGRAMMING
1,200
[ "greedy", "implementation" ]
A. What is for dinner?
2
256
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where bel...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
[ "4 3 18\n2 3\n1 2\n3 6\n2 3\n", "2 2 13\n1 13\n2 12\n" ]
[ "11\n", "13\n" ]
none
500
[ { "input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11" }, { "input": "2 2 13\n1 13\n2 12", "output": "13" }, { "input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3", "output": "8" }, { "input": "1 1 0\n1 3", "output": "0" }, { "input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 1...
1,553,374,315
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
216
0
inp=input().split(" ") n=int(inp[0]) m=inp[1] k=int(inp[2]) blich=set() res=0 for i in range(n): blich.add(tuple(input().split(" "))) for x in blich: res += int(x[1]) print(k) if res>k else print(res)
Title: What is for dinner? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that...
```python inp=input().split(" ") n=int(inp[0]) m=inp[1] k=int(inp[2]) blich=set() res=0 for i in range(n): blich.add(tuple(input().split(" "))) for x in blich: res += int(x[1]) print(k) if res>k else print(res) ```
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,685,978,378
2,147,483,647
Python 3
OK
TESTS
71
92
0
c=0 l=0 for i in range(int(input())): q,w=map(int,input().split()) c=c-q+w if l<c: l=c print(l)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ...
```python c=0 l=0 for i in range(int(input())): q,w=map(int,input().split()) c=c-q+w if l<c: l=c print(l) ```
3
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i...
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" ...
1,653,583,131
2,147,483,647
Python 3
OK
TESTS
50
46
0
n,m=map(int,input().split()) list1=[] for i in range(n): l=list(map(str,input().split())) list1.append(l) c=0 for i in list1: for j in i: if j=='C' or j=='M' or j=='Y': c=1 break if c==1: break if c==1: print("#Color") else: print("#Black&W...
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python n,m=map(int,input().split()) list1=[] for i in range(n): l=list(map(str,input().split())) list1.append(l) c=0 for i in list1: for j in i: if j=='C' or j=='M' or j=='Y': c=1 break if c==1: break if c==1: print("#Color") else: print...
3
721
B
Passwords
PROGRAMMING
1,100
[ "implementation", "math", "sortings", "strings" ]
null
null
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of ...
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
[ "5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n", "4 100\n11\n22\n1\n2\n22\n" ]
[ "1 15\n", "3 4\n" ]
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente...
1,000
[ { "input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15" }, { "input": "4 100\n11\n22\n1\n2\n22", "output": "3 4" }, { "input": "1 1\na1\na1", "output": "1 1" }, { "input": "1 100\na1\na1", "output": "1 1" }, { "input": "2 1\nabc\nAbc\nAbc", "output": ...
1,592,862,156
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
140
20,172,800
import math def fact(n): ans = 1 for i in range(2, n+1): ans*= i return ans def comb(n, c): return fact(n)//(fact(n-c)*c) n,k = map(int, input().split()) mini = 0 maxi = 0 pas = [] for i in range(n): pas.append(str(input())) pas = sorted(pas, key =lambda x:len(x)) cor = str(...
Title: Passwords Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords...
```python import math def fact(n): ans = 1 for i in range(2, n+1): ans*= i return ans def comb(n, c): return fact(n)//(fact(n-c)*c) n,k = map(int, input().split()) mini = 0 maxi = 0 pas = [] for i in range(n): pas.append(str(input())) pas = sorted(pas, key =lambda x:len(x)) ...
0
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuska...
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a r...
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,665,621,234
2,147,483,647
Python 3
OK
TESTS
3
60
0
t = int(input()) for i in range(t): def angle(a): if 360%(180-a)==0: return'YES' else: return'NO' a = int(input()) print(angle(a))
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can...
```python t = int(input()) for i in range(t): def angle(a): if 360%(180-a)==0: return'YES' else: return'NO' a = int(input()) print(angle(a)) ```
3
916
C
Jamie and Interesting Graph
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "shortest paths" ]
null
null
Jamie has recently found undirected weighted graphs with the following properties very interesting: - The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The su...
First line of input contains 2 integers *n*, *m*  — the required number of vertices and edges.
In the first line output 2 integers *sp*, *mstw* (1<=≤<=*sp*,<=*mstw*<=≤<=1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree. In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1<=≤<=*u*,<=*v*<=≤<=*n*,<=1<=≤<=*w*<=≤<=109) d...
[ "4 4\n", "5 4\n" ]
[ "7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4\n", "7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4\n" ]
The graph of sample 1: <img class="tex-graphics" src="https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png" style="max-width: 100.0%;max-height: 100.0%;"/> Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*). Definition of terms used in the problem statement: A shor...
1,500
[ { "input": "4 4", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000" }, { "input": "5 4", "output": "100003 100003\n1 2 100000\n2 3 1\n3 4 1\n4 5 1" }, { "input": "2 1", "output": "100003 100003\n1 2 100003" }, { "input": "10 19", "output": "100003 100003...
1,518,521,050
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
46
19,968,000
n, m = map(int, input().split()) p = 700001 for i in range(n - 2): print(i + 1, i + 2, 1) print(n - 1, n, p - n + 2) m -= (n - 1) for i in range(n): for j in range(i + 2, n): if m == 0: exit() m -= 1 print(i + 1, j + 1, 100000000)
Title: Jamie and Interesting Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie has recently found undirected weighted graphs with the following properties very interesting: - The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integer...
```python n, m = map(int, input().split()) p = 700001 for i in range(n - 2): print(i + 1, i + 2, 1) print(n - 1, n, p - n + 2) m -= (n - 1) for i in range(n): for j in range(i + 2, n): if m == 0: exit() m -= 1 print(i + 1, j + 1, 100000000) ```
0
150
A
Win or Freeze
PROGRAMMING
1,400
[ "games", "math", "number theory" ]
null
null
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer *q*. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of cir...
The first line contains the only integer *q* (1<=≤<=*q*<=≤<=1013). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.
[ "6\n", "30\n", "1\n" ]
[ "2\n", "1\n6\n", "1\n0\n" ]
Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the ...
500
[ { "input": "6", "output": "2" }, { "input": "30", "output": "1\n6" }, { "input": "1", "output": "1\n0" }, { "input": "2", "output": "1\n0" }, { "input": "3", "output": "1\n0" }, { "input": "5", "output": "1\n0" }, { "input": "445538663413",...
1,686,853,034
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
n = int(input()) k = n factors = [] i = 2 while i*i <= k : if k%i == 0 : factors.append(i) while k%i == 0 : k //= i i += 1 if k != 1 : factors.append(k) if len(factors) == 1 : print(1,0,sep='\n') exit() for i in factors : if i*i < n and n%(i*i) == 0 : ...
Title: Win or Freeze Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer *q*. During a move a player should write any integer num...
```python n = int(input()) k = n factors = [] i = 2 while i*i <= k : if k%i == 0 : factors.append(i) while k%i == 0 : k //= i i += 1 if k != 1 : factors.append(k) if len(factors) == 1 : print(1,0,sep='\n') exit() for i in factors : if i*i < n and n%(i*...
0
412
E
E-mail Addresses
PROGRAMMING
1,900
[ "implementation" ]
null
null
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day. Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume ...
The first and the only line contains the sequence of characters *s*1*s*2... *s**n* (1<=≤<=*n*<=≤<=106) — the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'.
Print in a single line the number of substrings that are valid e-mail addresses.
[ "[email protected]\n", "[email protected]@[email protected]\n", "[email protected]\n", ".asd123__..@\n" ]
[ "18\n", "8\n", "1\n", "0\n" ]
In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com. In the second test case note that the e-mail [[email protected]](/cdn-cgi/l/email-protection) is considered twice in the answer. Note that in this ...
2,500
[ { "input": "gerald.agapov1991@gmail.com", "output": "18" }, { "input": "x@x.x@x.x_e_@r1.com", "output": "8" }, { "input": "a___@1.r", "output": "1" }, { "input": ".asd123__..@", "output": "0" }, { "input": "@", "output": "0" }, { "input": ".", "out...
1,411,030,571
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
30
1,000
4,300,800
s = input() # находим собаку # находим адреса слева # умножаем на длину д.зоны dogs = [] numbers = 0 dogp = 0 for i in range(len(s)): if s[i] == '@': dogs.append(i) #print(dogs) lastdog = 0 while dogp < len(dogs): curgood = 0 # check leftside for i in range(dogs[dogp]-1, -1, -1): i...
Title: E-mail Addresses Time Limit: None seconds Memory Limit: None megabytes Problem Description: One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day. Today, the online news thundered with terrible information. The R...
```python s = input() # находим собаку # находим адреса слева # умножаем на длину д.зоны dogs = [] numbers = 0 dogp = 0 for i in range(len(s)): if s[i] == '@': dogs.append(i) #print(dogs) lastdog = 0 while dogp < len(dogs): curgood = 0 # check leftside for i in range(dogs[dogp]-1, -1, -1):...
0
569
A
Music
PROGRAMMING
1,500
[ "implementation", "math" ]
null
null
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite ...
The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105).
Print a single integer — the number of times the song will be restarted.
[ "5 2 2\n", "5 4 7\n", "6 2 3\n" ]
[ "2\n", "1\n", "1\n" ]
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test,...
500
[ { "input": "5 2 2", "output": "2" }, { "input": "5 4 7", "output": "1" }, { "input": "6 2 3", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "2 1 3", "output": "1" }, { "input": "2 1 10000", "output": "1" }, { "input": "12...
1,449,384,890
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
62
0
# print ("Input T, S, and q on one line") nums = input().split() T = int(nums[0]) S = int(nums[1]) q = int(nums[2]) answer = 1 check = S * q while (check < T): T = T - check answer += 1 print (answer)
Title: Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the...
```python # print ("Input T, S, and q on one line") nums = input().split() T = int(nums[0]) S = int(nums[1]) q = int(nums[2]) answer = 1 check = S * q while (check < T): T = T - check answer += 1 print (answer) ```
0
697
A
Pineapple Incident
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc. Barney woke up in the morn...
The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output.
[ "3 10 4\n", "3 10 3\n", "3 8 51\n", "3 8 52\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n" ]
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3. In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and ...
500
[ { "input": "3 10 4", "output": "NO" }, { "input": "3 10 3", "output": "YES" }, { "input": "3 8 51", "output": "YES" }, { "input": "3 8 52", "output": "YES" }, { "input": "456947336 740144 45", "output": "NO" }, { "input": "33 232603 599417964", "ou...
1,468,687,906
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#def f(t, s, x): return x == t or x >= t + s and (x - t) % s <= 1 t, s, x = map(int, raw_input().split()) print "YES" if f(t, s, x) else "NO"
Title: Pineapple Incident Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times...
```python #def f(t, s, x): return x == t or x >= t + s and (x - t) % s <= 1 t, s, x = map(int, raw_input().split()) print "YES" if f(t, s, x) else "NO" ```
-1
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea...
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n...
1,698,439,871
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
#define _CRT_SECURE_NO_DEPRECATE #define _SECURE_SCL 0 #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <map> #include <set> #include <string> #include <utility> #include <vector> #include <iostream> #include <queue> #include <deque> #include <stac...
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W...
```python #define _CRT_SECURE_NO_DEPRECATE #define _SECURE_SCL 0 #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <map> #include <set> #include <string> #include <utility> #include <vector> #include <iostream> #include <queue> #include <deque> #inc...
-1
703
A
Mishka and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined....
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ...
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
[ "3\n3 5\n2 1\n4 2\n", "2\n6 1\n1 6\n", "3\n1 5\n3 3\n2 2\n" ]
[ "Mishka", "Friendship is magic!^^", "Chris" ]
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there...
500
[ { "input": "3\n3 5\n2 1\n4 2", "output": "Mishka" }, { "input": "2\n6 1\n1 6", "output": "Friendship is magic!^^" }, { "input": "3\n1 5\n3 3\n2 2", "output": "Chris" }, { "input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1", "output": "Mishka" }, { "input": "8\n2 4\n1 4\n1 ...
1,691,396,111
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
62
0
n=int(input()) for i in range(n): a,b=input().split() a=int(a) b=int(b) if a>b: print("Mishka") elif b>a: print("Chris") else: print("Friendship is magic!^^")
Title: Mishka and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st...
```python n=int(input()) for i in range(n): a,b=input().split() a=int(a) b=int(b) if a>b: print("Mishka") elif b>a: print("Chris") else: print("Friendship is magic!^^") ```
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,644,758,245
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
62
0
def solve(s): map = {} map['.'] = '0' map['-.'] = '1' map['--'] = '2' temp = '' ans = '' for c in s: if len(temp) < 2: temp += c else: if temp in map: ans+= (map[temp]) temp = c else: ans+= (m...
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 def solve(s): map = {} map['.'] = '0' map['-.'] = '1' map['--'] = '2' temp = '' ans = '' for c in s: if len(temp) < 2: temp += c else: if temp in map: ans+= (map[temp]) temp = c else: ...
0
401
A
Vanya and Cards
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time p...
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a...
Print a single number — the answer to the problem.
[ "3 2\n-1 1 2\n", "2 3\n-2 -2\n" ]
[ "1\n", "2\n" ]
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
500
[ { "input": "3 2\n-1 1 2", "output": "1" }, { "input": "2 3\n-2 -2", "output": "2" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "2 2\n-1 -1", "output": "1" }, { "input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2", "output": "4" }, { "...
1,697,226,027
2,147,483,647
PyPy 3-64
OK
TESTS
47
77
0
n, x = [int(i) for i in input().split()] k = [int(i) for i in input().split()] s = sum(k) c = 0 if s == 0: print(0) exit() if s > 0: while s > 0: s -= x c += 1 else: while s < 0: s += x c += 1 print(c)
Title: Vanya and Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each...
```python n, x = [int(i) for i in input().split()] k = [int(i) for i in input().split()] s = sum(k) c = 0 if s == 0: print(0) exit() if s > 0: while s > 0: s -= x c += 1 else: while s < 0: s += x c += 1 print(c) ```
3
688
B
Lovely Palindromes
PROGRAMMING
1,000
[ "constructive algorithms", "math" ]
null
null
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
Print the *n*-th even-length palindrome number.
[ "1\n", "10\n" ]
[ "11\n", "1001\n" ]
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
1,000
[ { "input": "1", "output": "11" }, { "input": "10", "output": "1001" }, { "input": "11", "output": "1111" }, { "input": "12", "output": "1221" }, { "input": "100", "output": "100001" }, { "input": "1321", "output": "13211231" }, { "input": "...
1,644,378,523
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
10,035,200
from sys import stdin, stdout n = int(stdin.readline()) output = "" while(n!=0): x = n%10 output = str(x) + output + str(x) n//=10 stdout.write(output+"\n")
Title: Lovely Palindromes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is tr...
```python from sys import stdin, stdout n = int(stdin.readline()) output = "" while(n!=0): x = n%10 output = str(x) + output + str(x) n//=10 stdout.write(output+"\n") ```
0
396
C
On Changing Tree
PROGRAMMING
0
[ "data structures", "graphs", "trees" ]
null
null
You are given a rooted tree consisting of *n* vertices numbered from 1 to *n*. The root of the tree is a vertex number 1. Initially all vertices contain number 0. Then come *q* queries, each query has one of the two types: - The format of the query: 1 *v* *x* *k*. In response to the query, you need to add to the num...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of vertices in the tree. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=... *p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is the number of the vertex that is the parent of vertex *i* in the tree. The third line contains integer *q* (1<=...
For each query of the second type print on a single line the number written in the vertex from the query. Print the number modulo 1000000007 (109<=+<=7).
[ "3\n1 1\n3\n1 1 2 1\n2 1\n2 2\n" ]
[ "2\n1\n" ]
You can read about a rooted tree here: http://en.wikipedia.org/wiki/Tree_(graph_theory).
1,500
[ { "input": "3\n1 1\n3\n1 1 2 1\n2 1\n2 2", "output": "2\n1" }, { "input": "10\n1 2 3 4 4 3 3 6 7\n10\n1 6 13 98\n1 7 17 66\n1 5 32 39\n1 1 9 5\n1 7 27 11\n1 1 24 79\n1 5 87 86\n2 2\n1 5 9 38\n2 5", "output": "999999956\n999999832" }, { "input": "1\n\n1\n2 1", "output": "0" } ]
1,559,330,579
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
265
21,299,200
from collections import deque I = lambda : map(int,input().split()) n = int(input()) mod = pow(10,9)+7 parent = [ 0 for i in range (300001)] ht = [ 0 for i in range (300001)] gr = [ [] for i in range (300001)] visited = [ 0 for i in range (300001)] node = [ 0 for i in range (300001)] li = list(I()) fo...
Title: On Changing Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rooted tree consisting of *n* vertices numbered from 1 to *n*. The root of the tree is a vertex number 1. Initially all vertices contain number 0. Then come *q* queries, each query has one of the two t...
```python from collections import deque I = lambda : map(int,input().split()) n = int(input()) mod = pow(10,9)+7 parent = [ 0 for i in range (300001)] ht = [ 0 for i in range (300001)] gr = [ [] for i in range (300001)] visited = [ 0 for i in range (300001)] node = [ 0 for i in range (300001)] li = lis...
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,699,203,160
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
x= int(input()) big_moves= x/5 small_moves= 1 if big_moves is 5: print(1) else: print(int(big_moves)+ small_moves)
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()) big_moves= x/5 small_moves= 1 if big_moves is 5: print(1) else: print(int(big_moves)+ small_moves) ```
0
591
B
Rebranding
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descr...
Print the new name of the corporation.
[ "6 1\npolice\np m\n", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n" ]
[ "molice\n", "cdcbcdcfcdc\n" ]
In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.co...
1,000
[ { "input": "6 1\npolice\np m", "output": "molice" }, { "input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b", "output": "cdcbcdcfcdc" }, { "input": "1 1\nf\nz h", "output": "f" }, { "input": "1 1\na\na b", "output": "b" }, { "input": "10 10\nlellelleel\ne l\n...
1,662,380,930
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
76,697,600
# Problem Link: https://codeforces.com/problemset/problem/591/B # Problem Status: # --------------------------- SEPARATOR --------------------------- def TheAmazingFunction(Title: str, Arr: list): Table = [] Ans = "" for T in range(97, 97+26): Table.append(chr(T)) for U in Arr: ...
Title: Rebranding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand ...
```python # Problem Link: https://codeforces.com/problemset/problem/591/B # Problem Status: # --------------------------- SEPARATOR --------------------------- def TheAmazingFunction(Title: str, Arr: list): Table = [] Ans = "" for T in range(97, 97+26): Table.append(chr(T)) for U ...
0
358
A
Dima and Continuous Line
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate.
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
[ "4\n0 10 5 15\n", "4\n0 15 5 10\n" ]
[ "yes\n", "no\n" ]
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
500
[ { "input": "4\n0 10 5 15", "output": "yes" }, { "input": "4\n0 15 5 10", "output": "no" }, { "input": "5\n0 1000 2000 3000 1500", "output": "yes" }, { "input": "5\n-724093 710736 -383722 -359011 439613", "output": "no" }, { "input": "50\n384672 661179 -775591 -989...
1,602,149,419
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
124
0
length = input() points = [int(i) for i in input().split()] minimum = min(points) maximum = max(points) minimum_indices = [i for i, x in enumerate(points) if x==minimum ] maximum_indices = [i for i, x in enumerate(points) if x==maximum] for max in maximum_indices: found = False for min in...
Title: Dima and Continuous Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher g...
```python length = input() points = [int(i) for i in input().split()] minimum = min(points) maximum = max(points) minimum_indices = [i for i, x in enumerate(points) if x==minimum ] maximum_indices = [i for i, x in enumerate(points) if x==maximum] for max in maximum_indices: found = False ...
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,667,940,997
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
124
15,667,200
n=int(input()) room= str(input()) kr=[] rl=[] buy=0 for i in room: rl.append(i) if len(room)==(2*n-2): for j in range(len(room)): if j%2==0: if rl[j+1].lower() in kr: pass else: if rl[j]==rl[j+1].lower(): pass else: ...
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 n=int(input()) room= str(input()) kr=[] rl=[] buy=0 for i in room: rl.append(i) if len(room)==(2*n-2): for j in range(len(room)): if j%2==0: if rl[j+1].lower() in kr: pass else: if rl[j]==rl[j+1].lower(): pass ...
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,884,039
2,147,483,647
Python 3
OK
TESTS
18
92
0
n, m = map(int, input().split(" ")) p = list(map(int, input().split(" "))) p.sort() d = p[len(p)-1] for i in range((m-n)+1): d = min(d, p[(i + n)-1] - p[i]) print(d)
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a...
```python n, m = map(int, input().split(" ")) p = list(map(int, input().split(" "))) p.sort() d = p[len(p)-1] for i in range((m-n)+1): d = min(d, p[(i + n)-1] - p[i]) print(d) ```
3
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is ...
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m...
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", ...
1,647,094,806
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
1,000
921,600
s = input() t = input() if (s[-1]!=t[-1] or s=="" or t==""): print(len(s) + len(t)) elif s==t: print(0) else: i = -1 while s[i:]==t[i:]: i -= 1 i += 1 print(len(s[:i]) + len(t[:i]))
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ...
```python s = input() t = input() if (s[-1]!=t[-1] or s=="" or t==""): print(len(s) + len(t)) elif s==t: print(0) else: i = -1 while s[i:]==t[i:]: i -= 1 i += 1 print(len(s[:i]) + len(t[:i])) ```
0
729
B
Spotlights
PROGRAMMING
1,200
[ "dp", "implementation" ]
null
null
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t...
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ...
Print one integer — the number of good positions for placing the spotlight.
[ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ]
[ "9\n", "20\n" ]
In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and...
1,000
[ { "input": "2 4\n0 1 0 0\n1 0 1 0", "output": "9" }, { "input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "output": "20" }, { "input": "1 5\n1 1 0 0 0", "output": "3" }, { "input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "3 ...
1,673,618,108
2,147,483,647
PyPy 3-64
OK
TESTS
72
374
74,342,400
s = list(map(int, input().split())) n,m = s[0],s[1] spisok = [] for i in range(n): p = list(map(int, input().split())) spisok.append(p) s1 = [] s2 = [] s3 = [] s4 = [] k1 = 0 k2 = 0 k3 = 0 k4 = 0 for i in range(n): for j in range(m): if spisok[i][j] == 0: k1 += 1 if spisok[i][j] == 1: s1...
Title: Spotlights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to pl...
```python s = list(map(int, input().split())) n,m = s[0],s[1] spisok = [] for i in range(n): p = list(map(int, input().split())) spisok.append(p) s1 = [] s2 = [] s3 = [] s4 = [] k1 = 0 k2 = 0 k3 = 0 k4 = 0 for i in range(n): for j in range(m): if spisok[i][j] == 0: k1 += 1 if spisok[i][j] ==...
3
719
A
Vitya in the Countryside
PROGRAMMING
1,100
[ "implementation" ]
null
null
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records. It's guaranteed that the input data is consistent.
If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly ...
[ "5\n3 4 5 6 7\n", "7\n12 13 14 15 14 13 12\n", "1\n8\n" ]
[ "UP\n", "DOWN\n", "-1\n" ]
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus t...
500
[ { "input": "5\n3 4 5 6 7", "output": "UP" }, { "input": "7\n12 13 14 15 14 13 12", "output": "DOWN" }, { "input": "1\n8", "output": "-1" }, { "input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10", "out...
1,474,927,558
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
77
0
n=int(input()) ch=input() l=[] l=ch.split() if (l[n-1]=='15'): print('DOWN') else : if (l[n-1]=='0'): print('UP') else : if (n > 1): if ((l[n-1] < l[n-2])): print('DOWN') else: print ('UP') else: ...
Title: Vitya in the Countryside Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the momen...
```python n=int(input()) ch=input() l=[] l=ch.split() if (l[n-1]=='15'): print('DOWN') else : if (l[n-1]=='0'): print('UP') else : if (n > 1): if ((l[n-1] < l[n-2])): print('DOWN') else: print ('UP') else: ...
0
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,679,390,158
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
122
0
n = str(input()) c = 0 for i in range(len(n)-1): if n[i+1] == n[i]: c += 1 if c == 7: break else: c = 0 print('YES' if c == 7 else 'NO')
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A...
```python n = str(input()) c = 0 for i in range(len(n)-1): if n[i+1] == n[i]: c += 1 if c == 7: break else: c = 0 print('YES' if c == 7 else 'NO') ```
0
982
B
Bus of Characters
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation" ]
null
null
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always choose...
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus. The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct. The t...
Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input.
[ "2\n3 1\n0011\n", "6\n10 8 9 11 13 5\n010010011101\n" ]
[ "2 1 1 2 \n", "6 6 2 3 3 1 4 4 1 2 5 5 \n" ]
In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat w...
1,000
[ { "input": "2\n3 1\n0011", "output": "2 1 1 2 " }, { "input": "6\n10 8 9 11 13 5\n010010011101", "output": "6 6 2 3 3 1 4 4 1 2 5 5 " }, { "input": "1\n1\n01", "output": "1 1 " }, { "input": "1\n1000000\n01", "output": "1 1 " }, { "input": "2\n1 1000000\n0011", ...
1,664,189,607
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
33,587,200
def main(): n = int(input()) s = [*map(int, input().split())] for i in range(len(s)): s[i] = (s[i], i + 1) s.sort(reverse=True) x = input() stek = [] for i in x: if i == '0': print(s[-1][1], end=' ') stek += [s[-1][1]] s = s[:-1...
Title: Bus of Characters Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$...
```python def main(): n = int(input()) s = [*map(int, input().split())] for i in range(len(s)): s[i] = (s[i], i + 1) s.sort(reverse=True) x = input() stek = [] for i in x: if i == '0': print(s[-1][1], end=' ') stek += [s[-1][1]] ...
0
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco...
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, an...
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,535,635,969
2,147,483,647
PyPy 3
OK
TESTS
40
140
0
a = int(input()) b = int(input()) acount = 0 bcount = 0 aturn = True total = 0 if (a < b): t = a a = b b = t while (a!=b): if (aturn): a -= 1 acount += 1 total += acount else: b += 1 bcount += 1 total += bcount aturn = not aturn print(total)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in...
```python a = int(input()) b = int(input()) acount = 0 bcount = 0 aturn = True total = 0 if (a < b): t = a a = b b = t while (a!=b): if (aturn): a -= 1 acount += 1 total += acount else: b += 1 bcount += 1 total += bcount aturn = not aturn prin...
3
518
A
Vitaly and Strings
PROGRAMMING
1,600
[ "constructive algorithms", "strings" ]
null
null
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli...
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string. The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters. It is guaranteed that the lengths of strings *s* and *t* are the same and str...
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them.
[ "a\nc\n", "aaa\nzzz\n", "abcdefg\nabcdefh\n" ]
[ "b\n", "kkk\n", "No such string\n" ]
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ...
500
[ { "input": "a\nc", "output": "b" }, { "input": "aaa\nzzz", "output": "kkk" }, { "input": "abcdefg\nabcdefh", "output": "No such string" }, { "input": "abcdefg\nabcfefg", "output": "abcdefh" }, { "input": "frt\nfru", "output": "No such string" }, { "inp...
1,543,793,383
2,147,483,647
PyPy 3
OK
TESTS
51
170
0
from operator import itemgetter #int(input()) #map(int,input().split()) #[list(map(int,input().split())) for i in range(q)] #print("YES" * ans + "NO" * (1-ans)) s = input() s2 = input() alth = "abcdefghijklmnopqrstuvwxyz" n = len(s) s3 = [0] * n for i in range(n-1,-1,-1): if s[i] == "z": s3[i] =...
Title: Vitaly and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provi...
```python from operator import itemgetter #int(input()) #map(int,input().split()) #[list(map(int,input().split())) for i in range(q)] #print("YES" * ans + "NO" * (1-ans)) s = input() s2 = input() alth = "abcdefghijklmnopqrstuvwxyz" n = len(s) s3 = [0] * n for i in range(n-1,-1,-1): if s[i] == "z": ...
3
937
B
Vile Grasshoppers
PROGRAMMING
1,400
[ "brute force", "math", "number theory" ]
null
null
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grassh...
The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109).
Output the number of the highest suitable branch. If there are none, print -1 instead.
[ "3 6\n", "3 4\n" ]
[ "5\n", "-1\n" ]
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5. It immediately follows that there are no valid branches in second sample case.
1,000
[ { "input": "3 6", "output": "5" }, { "input": "3 4", "output": "-1" }, { "input": "2 2", "output": "-1" }, { "input": "5 50", "output": "49" }, { "input": "944192806 944193066", "output": "944192807" }, { "input": "1000000000 1000000000", "output":...
1,584,454,852
4,852
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
0
p, y = map(int, input().split()) ans = -1 for i in range(y, 2 - 1, -1): can = True for j in range(2, p + 1): can &= i % j != 0 if can: ans = i break print(ans)
Title: Vile Grasshoppers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (mor...
```python p, y = map(int, input().split()) ans = -1 for i in range(y, 2 - 1, -1): can = True for j in range(2, p + 1): can &= i % j != 0 if can: ans = i break print(ans) ```
0
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,520,961,415
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
5,632,000
def sumDigits(x): sumD = 0 for c in x: sumD += int(c) return sumD xs = input() xi = int(xs) sumD = sumDigits(xs) lst = [] for i in range(1, xi - sumD): if i + sumDigits(str(i)) == xi: lst.append(i) if not lst: print(0) exit() for x in lst: print(x)
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 def sumDigits(x): sumD = 0 for c in x: sumD += int(c) return sumD xs = input() xi = int(xs) sumD = sumDigits(xs) lst = [] for i in range(1, xi - sumD): if i + sumDigits(str(i)) == xi: lst.append(i) if not lst: print(0) exit() for x in lst: print(x) ```
0
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul...
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, {...
1,695,573,886
2,147,483,647
Python 3
OK
TESTS
29
46
0
x = int(input()) y = int(input()) z = int(input()) print(max(x*y*z,max((x+y)*z,max(x+y+z,x*(y+z)))))
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ...
```python x = int(input()) y = int(input()) z = int(input()) print(max(x*y*z,max((x+y)*z,max(x+y+z,x*(y+z))))) ```
3
961
B
Lecture Sleep
PROGRAMMING
1,200
[ "data structures", "dp", "implementation", "two pointers" ]
null
null
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ...
The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake. The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore...
Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
[ "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n" ]
[ "16\n" ]
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
0
[ { "input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0", "output": "16" }, { "input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0", "output": "30000" }, { "input": "3 3\n10 10 10\n1 1 0", "output": "30" }, { "input": "1 1\n423\n0", "output": "423" }, { "input": "6 6\n1 3 5 2 5 4...
1,644,944,004
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
155
11,264,000
n,k=map(int,input().split()) a=list(map(int,input().split())) l=list(map(int,input().split())) res=0 for i in range(len(l)): if l[i]==1: res+=a[i] a[i]=0 prefixsum=[0 for i in range(n)] for i in range(1,n): a[i]+=a[i-1] for i in range(k,n): prefixsum[i]=a[i]-a[i-k] maxsum=0 for...
Title: Lecture Sleep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for al...
```python n,k=map(int,input().split()) a=list(map(int,input().split())) l=list(map(int,input().split())) res=0 for i in range(len(l)): if l[i]==1: res+=a[i] a[i]=0 prefixsum=[0 for i in range(n)] for i in range(1,n): a[i]+=a[i-1] for i in range(k,n): prefixsum[i]=a[i]-a[i-k] max...
0
9
B
Running Student
PROGRAMMING
1,200
[ "brute force", "geometry", "implementation" ]
B. Running Student
1
64
And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*. Poor Student knows the following: - during one run the minibus makes ...
The first line contains three integer numbers: 2<=≤<=*n*<=≤<=100, 1<=≤<=*v**b*,<=*v**s*<=≤<=1000. The second line contains *n* non-negative integers in ascending order: coordinates *x**i* of the bus stop with index *i*. It is guaranteed that *x*1 equals to zero, and *x**n*<=≤<=105. The third line contains the coordinat...
In the only line output the answer to the problem — index of the optimum bus stop.
[ "4 5 2\n0 2 4 6\n4 1\n", "2 1 1\n0 100000\n100000 100000\n" ]
[ "3", "2" ]
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
0
[ { "input": "4 5 2\n0 2 4 6\n4 1", "output": "3" }, { "input": "2 1 1\n0 100000\n100000 100000", "output": "2" }, { "input": "6 5 1\n0 1 2 3 4 5\n0 0", "output": "2" }, { "input": "4 100 10\n0 118 121 178\n220 220", "output": "4" }, { "input": "4 3 3\n0 6 8 10\n7 -...
1,646,064,696
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
62
0
v1 = [] v2 = [] v3 = [] aux_real = 999999999999992 n, vb, vs = map(int, input().split()) x = list(map(int, input().split())) x_uni, y_uni = map(int, input().split()) for i in range (n): aux = x[i] / vb v1.append(aux) for j in range (n): aux1 = (x_uni - x[j]) ** 2 aux2 = y_uni ** 2 aux2 = aux1 + ...
Title: Running Student Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direct...
```python v1 = [] v2 = [] v3 = [] aux_real = 999999999999992 n, vb, vs = map(int, input().split()) x = list(map(int, input().split())) x_uni, y_uni = map(int, input().split()) for i in range (n): aux = x[i] / vb v1.append(aux) for j in range (n): aux1 = (x_uni - x[j]) ** 2 aux2 = y_uni ** 2 aux2...
0
794
A
Bank Robbery
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f...
The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=&lt;<=*a*<=&lt;<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively. The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the numbe...
Output a single integer: the maximum number of banknotes Oleg can take.
[ "5 3 7\n8\n4 7 5 5 3 6 2 8\n", "6 5 7\n5\n1 5 7 92 3\n" ]
[ "4\n", "0\n" ]
In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se...
500
[ { "input": "5 3 7\n8\n4 7 5 5 3 6 2 8", "output": "4" }, { "input": "6 5 7\n5\n1 5 7 92 3", "output": "0" }, { "input": "3 2 4\n1\n3", "output": "1" }, { "input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6", "output": "8" }, { "input": "7 3 10\n5\n3 3 3 3 3", "output...
1,666,438,629
2,147,483,647
Python 3
OK
TESTS
46
109
7,372,800
A = list(input().split()) for i in range(len(A)): A[i]=int(A[i]) a=A[0] b=A[1] c=A[2] n = int(input()) B = list(input().split()) for i in range(len(B)): B[i]=int(B[i]) count = 0 for i in B: if i>b and i<c: count+=1 print(count)
Title: Bank Robbery Time Limit: None seconds Memory Limit: None megabytes Problem Description: A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and...
```python A = list(input().split()) for i in range(len(A)): A[i]=int(A[i]) a=A[0] b=A[1] c=A[2] n = int(input()) B = list(input().split()) for i in range(len(B)): B[i]=int(B[i]) count = 0 for i in B: if i>b and i<c: count+=1 print(count) ```
3
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,...
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "i...
1,553,622,352
2,147,483,647
Python 3
OK
TESTS
32
748
307,200
# import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("outp.out",'w') n,m,z=map(int,input().split()) a=[i for i in range(n,z+1,n)] b=[j for j in range(m,z+1,m)] c=0 for x in a: if x in b: c+=1 print(c)
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com...
```python # import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("outp.out",'w') n,m,z=map(int,input().split()) a=[i for i in range(n,z+1,n)] b=[j for j in range(m,z+1,m)] c=0 for x in a: if x in b: c+=1 print(c) ```
3
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output...
1,598,517,263
2,147,483,647
PyPy 3
OK
TESTS
51
1,246
7,884,800
import sys input = sys.stdin.readline def inp(): return int(input()) def minp(): return map(int,input().split()) def inpsl(): return list(input().split()) def write(s): sys.stdout.write(s+" ") def main(): n = inp() cnt = 0 while(n>9): n = sum([int(i) for i in str(n)...
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 input = sys.stdin.readline def inp(): return int(input()) def minp(): return map(int,input().split()) def inpsl(): return list(input().split()) def write(s): sys.stdout.write(s+" ") def main(): n = inp() cnt = 0 while(n>9): n = sum([int(i) for i...
3.674312
797
A
k-Factorization
PROGRAMMING
1,100
[ "implementation", "math", "number theory" ]
null
null
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them.
[ "100000 2\n", "100000 20\n", "1024 5\n" ]
[ "2 50000 \n", "-1\n", "2 64 2 2 2 \n" ]
none
0
[ { "input": "100000 2", "output": "2 50000 " }, { "input": "100000 20", "output": "-1" }, { "input": "1024 5", "output": "2 64 2 2 2 " }, { "input": "100000 10", "output": "2 2 2 2 2 5 5 5 5 5 " }, { "input": "99999 3", "output": "3 813 41 " }, { "input...
1,654,950,297
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
31
0
from math import sqrt n, k = [int(x) for x in input().split()] n1 = n counter = 0 divisors = [] for i in range(2, int(sqrt(n)) + 1): while n % i == 0: n //= i counter += 1 divisors.append(i) if k > counter: print(-1) else: mult = 1 for i in range(k - 1): ...
Title: k-Factorization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. Input Specification: The first line contains two int...
```python from math import sqrt n, k = [int(x) for x in input().split()] n1 = n counter = 0 divisors = [] for i in range(2, int(sqrt(n)) + 1): while n % i == 0: n //= i counter += 1 divisors.append(i) if k > counter: print(-1) else: mult = 1 for i in range(k - 1):...
0
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,694,718,194
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
a,b,c = map(int,input().split()) g = 0 r = 0 while g != c: g += 1 r += g * a print(r - b)
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,b,c = map(int,input().split()) g = 0 r = 0 while g != c: g += 1 r += g * a print(r - b) ```
0
744
B
Hongcow's Game
PROGRAMMING
1,900
[ "bitmasks", "divide and conquer", "interactive" ]
null
null
This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden *n* by *n* matrix *M*. Let *M**i*,<=*j* denote the entry *i*-th row and *j*-th column of the matrix....
The first line of input will contain a single integer *n* (2<=≤<=*n*<=≤<=1,<=000).
To print the final answer, print out the string -1 on its own line. Then, the next line should contain *n* integers. The *i*-th integer should be the minimum value of the *i*-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer!
[ "3\n0 0 0\n2 7 0\n0 0 4\n3 0 8\n0 5 4", "2\n0 0\n0 0" ]
[ "3\n1 2 3\n1\n3\n2\n1 2\n1\n2\n1\n1\n-1\n2 5 4\n", "1\n2\n1\n1\n-1\n0 0" ]
In the first sample, Hongcow has the hidden matrix Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
1,250
[]
1,482,673,361
2,147,483,647
Python 3
OK
TESTS
63
265
6,451,200
import math,sys,re,itertools,pprint,collections,copy rs,ri,rai,raf=input,lambda:int(input()),lambda:list(map(int, input().split())),lambda:list(map(float, input().split())) pai=lambda x: print(" ".join(map(str, x))) n = ri() line_min = [float("inf") for _ in range(n)] requests = [] def init_requests(): ...
Title: Hongcow's Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden ...
```python import math,sys,re,itertools,pprint,collections,copy rs,ri,rai,raf=input,lambda:int(input()),lambda:list(map(int, input().split())),lambda:list(map(float, input().split())) pai=lambda x: print(" ".join(map(str, x))) n = ri() line_min = [float("inf") for _ in range(n)] requests = [] def init_reques...
3
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "in...
1,651,644,775
2,147,483,647
Python 3
OK
TESTS
58
77
409,600
#!/usr/bin/env python import math import sys import itertools import fractions if __name__ == '__main__': wtf = sys.stdin.read() wtf = wtf.strip().split('\n') S = wtf[0] f = '' FNT = 'heidi' z = FNT for s in S: if len(f) == 5: if f == FNT: ...
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ...
```python #!/usr/bin/env python import math import sys import itertools import fractions if __name__ == '__main__': wtf = sys.stdin.read() wtf = wtf.strip().split('\n') S = wtf[0] f = '' FNT = 'heidi' z = FNT for s in S: if len(f) == 5: if f == FNT: ...
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,584,558,927
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
156
0
n=int(input()) m=[] for i in range(n): l=list(map(int, input().split())) m.append(l) sum=0 for i in range(3): for j in range(n): sum+=m[j][i] print(sum) if(sum==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()) m=[] for i in range(n): l=list(map(int, input().split())) m.append(l) sum=0 for i in range(3): for j in range(n): sum+=m[j][i] print(sum) if(sum==0): print("YES") else: print("NO") ```
0
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is ...
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m...
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", ...
1,633,169,745
2,147,483,647
Python 3
OK
TESTS
28
140
7,782,400
a = input() b = input() n = 0 a1 = len(a) b1 = len(b) while a1 != 0 and b1 != 0 and a[a1-1] == b[b1-1]: a1 -= 1 b1 -= 1 print(a1 + b1) # Sat Oct 02 2021 13:15:45 GMT+0300 (Москва, стандартное время)
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ...
```python a = input() b = input() n = 0 a1 = len(a) b1 = len(b) while a1 != 0 and b1 != 0 and a[a1-1] == b[b1-1]: a1 -= 1 b1 -= 1 print(a1 + b1) # Sat Oct 02 2021 13:15:45 GMT+0300 (Москва, стандартно...
3
38
H
The Great Marathon
PROGRAMMING
2,400
[ "dp" ]
H. The Great Marathon
4
256
On the Berland Dependence Day it was decided to organize a great marathon. Berland consists of *n* cities, some of which are linked by two-way roads. Each road has a certain length. The cities are numbered from 1 to *n*. It is known that one can get from any city to any other one by the roads. *n* runners take part in...
The first input line contains given integers *n* and *m* (3<=≤<=*n*<=≤<=50, *n*<=-<=1<=≤<=*m*<=≤<=1000), where *n* is the number of Berland towns and *m* is the number of roads. Next in *m* lines road descriptions are given as groups of three integers *v*, *u*, *c*, which are the numbers of linked towns and its length...
Print the single number — the number of ways to distribute the medals. It is guaranteed that the number fits in the standard 64-bit signed data type.
[ "3 2\n1 2 1\n2 3 1\n1 1 1 1\n", "4 5\n1 2 2\n2 3 1\n3 4 2\n4 1 2\n1 3 3\n1 2 1 1\n", "3 3\n1 2 2\n2 3 1\n3 1 2\n1 1 1 1\n" ]
[ "3\n", "19\n", "4\n" ]
none
0
[]
1,693,303,470
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1693303470.5344942")# 1693303470.53451
Title: The Great Marathon Time Limit: 4 seconds Memory Limit: 256 megabytes Problem Description: On the Berland Dependence Day it was decided to organize a great marathon. Berland consists of *n* cities, some of which are linked by two-way roads. Each road has a certain length. The cities are numbered from 1 to *n*....
```python print("_RANDOM_GUESS_1693303470.5344942")# 1693303470.53451 ```
0
226
A
Flying Saucer Segments
PROGRAMMING
1,400
[ "math" ]
null
null
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the...
The first line contains two space-separated integers: *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the number of aliens on the saucer and the number, modulo which you should print the answer, correspondingly.
Print a single number — the answer to the problem modulo *m*.
[ "1 10\n", "3 8\n" ]
[ "2\n", "2\n" ]
In the first sample the only crew member moves from segment 3 to segment 2, and then from segment 2 to segment 1 without any problems. Thus, the whole moving will take two minutes. To briefly describe the movements in the second sample we will use value <img align="middle" class="tex-formula" src="https://espresso.cod...
500
[ { "input": "1 10", "output": "2" }, { "input": "3 8", "output": "2" }, { "input": "8 12", "output": "8" }, { "input": "4 84", "output": "80" }, { "input": "9 95", "output": "17" }, { "input": "331358794 820674098", "output": "2619146" }, { ...
1,501,047,068
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a = b++
Title: Flying Saucer Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, c...
```python a = b++ ```
-1
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate...
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence...
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15...
1,696,584,739
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
#codeforce test n ,k= input().split(' ') k = int(k) n = int(n) arr = [] arr = input().split(' ') while arr[k-1] == arr[k] and k < n-1 and arr[k-1] != 0: k +=1 while arr[k-1] == 0 : k -=1 print(k+1)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* p...
```python #codeforce test n ,k= input().split(' ') k = int(k) n = int(n) arr = [] arr = input().split(' ') while arr[k-1] == arr[k] and k < n-1 and arr[k-1] != 0: k +=1 while arr[k-1] == 0 : k -=1 print(k+1) ```
0
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,664,543,379
2,147,483,647
Python 3
OK
TESTS
29
46
0
n=int(input()) cell=input() b=0 place=cell.find("0") if place==(-1): print(n) else: print(place+1)
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()) cell=input() b=0 place=cell.find("0") if place==(-1): print(n) else: print(place+1) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,662,217,494
2,147,483,647
Python 3
OK
TESTS
30
92
0
s=input() l=[x for x in s if 97<=ord(x)<=122] u=[x for x in s if 65<=ord(x)<=90] m=len(l) n=len(u) if m==n: print(s.lower()) elif m>n: print(s.lower()) else: print(s.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s=input() l=[x for x in s if 97<=ord(x)<=122] u=[x for x in s if 65<=ord(x)<=90] m=len(l) n=len(u) if m==n: print(s.lower()) elif m>n: print(s.lower()) else: print(s.upper()) ```
3.977
129
B
Students and Shoelaces
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f...
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*...
Print the single number — the number of groups of students that will be kicked out from the club.
[ "3 3\n1 2\n2 3\n3 1\n", "6 3\n1 2\n2 3\n3 4\n", "6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone. In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ...
1,000
[ { "input": "3 3\n1 2\n2 3\n3 1", "output": "0" }, { "input": "6 3\n1 2\n2 3\n3 4", "output": "2" }, { "input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4", "output": "1" }, { "input": "100 0", "output": "0" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "0" }, ...
1,610,271,929
2,147,483,647
Python 3
OK
TESTS
70
154
307,200
s,l = [int(x) for x in input().split()] group = {} for i in range(1,s+1): group[i] = [] for i in range(1, l+1): num,num2 = [int(x) for x in input().split()] group[num].append(num2) group[num2].append(num) grp = 0 while 1: visited = [] check = False for i in range(1, s + 1): if len(group[i]) == 1 and i not in v...
Title: Students and Shoelaces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica...
```python s,l = [int(x) for x in input().split()] group = {} for i in range(1,s+1): group[i] = [] for i in range(1, l+1): num,num2 = [int(x) for x in input().split()] group[num].append(num2) group[num2].append(num) grp = 0 while 1: visited = [] check = False for i in range(1, s + 1): if len(group[i]) == 1 and ...
3
797
C
Minimal string
PROGRAMMING
1,700
[ "data structures", "greedy", "strings" ]
null
null
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves: - Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u*...
First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters.
Print resulting string *u*.
[ "cab\n", "acdb\n" ]
[ "abc\n", "abdc\n" ]
none
0
[ { "input": "cab", "output": "abc" }, { "input": "acdb", "output": "abdc" }, { "input": "a", "output": "a" }, { "input": "ab", "output": "ab" }, { "input": "ba", "output": "ab" }, { "input": "dijee", "output": "deeji" }, { "input": "bhrmc", ...
1,584,980,803
2,147,483,647
Python 3
OK
TESTS
189
561
1,843,200
def fnz(l): for i in range(len(l)): if l[i] != 0: return i return i alphabets = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] count_alph = [0]*26 s = input() t = [] u = [] for i in s: count_alph[alphabets.index(i)] +=...
Title: Minimal string Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves: - Extract the first char...
```python def fnz(l): for i in range(len(l)): if l[i] != 0: return i return i alphabets = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] count_alph = [0]*26 s = input() t = [] u = [] for i in s: count_alph[alphabets.in...
3
222
D
Olympiad
PROGRAMMING
1,900
[ "binary search", "greedy", "sortings", "two pointers" ]
null
null
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least *x* points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances....
The first line contains two space-separated integers *n*,<=*x* (1<=≤<=*n*<=≤<=105; 0<=≤<=*x*<=≤<=2·105) — the number of Olympiad participants and the minimum number of points Vasya earned. The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the participants' point...
Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.
[ "5 2\n1 1 1 1 1\n1 1 1 1 1\n", "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4\n" ]
[ "1 5\n", "1 5\n" ]
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place. In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the ...
2,000
[ { "input": "5 2\n1 1 1 1 1\n1 1 1 1 1", "output": "1 5" }, { "input": "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4", "output": "1 5" }, { "input": "1 100\n56\n44", "output": "1 1" }, { "input": "5 1\n1 2 3 4 5\n1 2 3 4 5", "output": "1 5" }, { "input": "5 5\n2 2 2 2 2\n3 3 3 3 ...
1,690,495,770
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
print("_RANDOM_GUESS_1690495770.1686215")# 1690495770.1686435
Title: Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least *x* points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but th...
```python print("_RANDOM_GUESS_1690495770.1686215")# 1690495770.1686435 ```
0
430
B
Balls Game
PROGRAMMING
1,400
[ "brute force", "two pointers" ]
null
null
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at...
The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*. It is guaranteed th...
Print a single integer — the maximum number of balls Iahub can destroy.
[ "6 2 2\n1 1 2 2 1 1\n", "1 1 1\n1\n" ]
[ "6\n", "0\n" ]
none
1,000
[ { "input": "6 2 2\n1 1 2 2 1 1", "output": "6" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 2 1\n2 1 2 2 1 2 2 1 1 2", "output": "5" }, { "input": "50 2 1\n1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 1 1 2", "...
1,599,965,703
2,147,483,647
PyPy 3
OK
TESTS
18
170
1,433,600
#! /usr/bin/python3 def remove_contiguous(arr): left = 0 right = 1 while(right < len(arr)): while(right < len(arr) and arr[left] == arr[right]): right += 1 if (right - left >= 3): del arr[left:right] modified = True return arr left = right right += 1 return arr n, k, x = map(int, input().str...
Title: Balls Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more conti...
```python #! /usr/bin/python3 def remove_contiguous(arr): left = 0 right = 1 while(right < len(arr)): while(right < len(arr) and arr[left] == arr[right]): right += 1 if (right - left >= 3): del arr[left:right] modified = True return arr left = right right += 1 return arr n, k, x = map(int, i...
3
0
none
none
none
0
[ "none" ]
null
null
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation. A set ρ of pairs (*a*,<=*b*) of elem...
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=4000).
In a single line print the answer to the problem modulo 109<=+<=7.
[ "1\n", "2\n", "3\n" ]
[ "1\n", "3\n", "10\n" ]
If *n* = 1 there is only one such relation — an empty one, i.e. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8891a227c918474e5d76377d4644cd7cc01e1ffd.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In other words, for a single element *x* of set *A* the following is hold: <img alig...
0
[ { "input": "1", "output": "1" }, { "input": "2", "output": "3" }, { "input": "3", "output": "10" }, { "input": "4", "output": "37" }, { "input": "5", "output": "151" }, { "input": "6", "output": "674" }, { "input": "7", "output": "3263"...
1,439,230,232
6,032
Python 3
WRONG_ANSWER
PRETESTS
3
62
10,752,000
factorials = [1] tmp=1 for i in range(1,4001): tmp = tmp * i factorials.append(tmp) ans = 1 n = int(input()) for i in range(1,n): ans = ans + factorials[n]//factorials[i] print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equ...
```python factorials = [1] tmp=1 for i in range(1,4001): tmp = tmp * i factorials.append(tmp) ans = 1 n = int(input()) for i in range(1,n): ans = ans + factorials[n]//factorials[i] print(ans) ```
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,697,009,607
2,147,483,647
PyPy 3-64
OK
TESTS
62
77
0
def solve(): a,b = list(map(int,input().split())) res = 0 while a <= b: a*=3 b*=2 res+=1 return res print(solve())
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 def solve(): a,b = list(map(int,input().split())) res = 0 while a <= b: a*=3 b*=2 res+=1 return res print(solve()) ```
3
808
B
Average Sleep Time
PROGRAMMING
1,300
[ "data structures", "implementation", "math" ]
null
null
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp k...
The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point.
[ "3 2\n3 4 7\n", "1 1\n10\n", "8 2\n1 2 4 100000 123 456 789 1\n" ]
[ "9.0000000000\n", "10.0000000000\n", "28964.2857142857\n" ]
In the third example there are *n* - *k* + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
0
[ { "input": "3 2\n3 4 7", "output": "9.0000000000" }, { "input": "1 1\n10", "output": "10.0000000000" }, { "input": "8 2\n1 2 4 100000 123 456 789 1", "output": "28964.2857142857" }, { "input": "1 1\n1", "output": "1.0000000000" }, { "input": "1 1\n100000", "ou...
1,495,222,938
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
import sys line = sys.stdin.readline().split(" ") n = int(line[0]) k = int(line[1]) s = 0 days = sys.stdin.readline().split(" ") kCount = 1 kReverseCount = k v = [] for i in range (n): v.append(int(days[i])) v1 = v[0:k-1] if n-k > k: v2 = v[k:n-k] else: v2 = v[n-k:k] v3 = v[(n-k+1):n] sum1 = 0 sum2 = ...
Title: Average Sleep Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days! When Polycarp went to a doctor with his problem, the doctor asked him about his s...
```python import sys line = sys.stdin.readline().split(" ") n = int(line[0]) k = int(line[1]) s = 0 days = sys.stdin.readline().split(" ") kCount = 1 kReverseCount = k v = [] for i in range (n): v.append(int(days[i])) v1 = v[0:k-1] if n-k > k: v2 = v[k:n-k] else: v2 = v[n-k:k] v3 = v[(n-k+1):n] sum1 =...
0
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ...
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output"...
1,635,965,452
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
122
28,364,800
def solve(): n = int(input()) tempList = [] tempList += map(int, input().split(' ')) pairI, pairJ = 0, 0 min = max(tempList) for i in range(0, len(tempList)): for j in range(i+1,len(tempList)): if min > abs(tempList[i] - tempList[j]): min = abs(temp...
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So...
```python def solve(): n = int(input()) tempList = [] tempList += map(int, input().split(' ')) pairI, pairJ = 0, 0 min = max(tempList) for i in range(0, len(tempList)): for j in range(i+1,len(tempList)): if min > abs(tempList[i] - tempList[j]): min ...
0
392
A
Blocked Points
PROGRAMMING
0
[ "math" ]
null
null
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points *A* and *B* on the plane are 4-connected if and only if: - the Euclidean distance between *A* and *B* is one unit and neither *A* nor *B* is blocked; - or there is ...
The first line contains an integer *n* (0<=≤<=*n*<=≤<=4·107).
Print a single integer — the minimum number of points that should be blocked.
[ "1\n", "2\n", "3\n" ]
[ "4\n", "8\n", "16\n" ]
none
500
[ { "input": "1", "output": "4" }, { "input": "2", "output": "8" }, { "input": "3", "output": "16" }, { "input": "4", "output": "20" }, { "input": "0", "output": "1" }, { "input": "30426905", "output": "172120564" }, { "input": "38450759", ...
1,395,451,694
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
307,200
import math import fileinput for line in fileinput.input(): n = int(line) def countPoints(n): if n==0: return 1 elif n==1: return 4 else: X = math.floor(math.sqrt(2)/2*n) return 8*X print(countpoints(n))
Title: Blocked Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points *A* and *B* on the plane are 4-connected if and only if: - the Eu...
```python import math import fileinput for line in fileinput.input(): n = int(line) def countPoints(n): if n==0: return 1 elif n==1: return 4 else: X = math.floor(math.sqrt(2)/2*n) return 8*X print(countpoints(n)) ```
-1
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }...
1,696,361,962
2,147,483,647
Python 3
OK
TESTS
15
46
0
k,n,w=list(map(int,input().split())) c=0 for i in range(1,w+1): c+=i*k a=c-n if a>0: print(a) else: print("0")
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He h...
```python k,n,w=list(map(int,input().split())) c=0 for i in range(1,w+1): c+=i*k a=c-n if a>0: print(a) else: print("0") ```
3
818
A
Diplomas and Certificates
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ...
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
0
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1",...
1,498,750,117
1,417
Python 3
OK
TESTS
44
77
5,529,600
n, k = input().split() n, k = int(n), int(k) lo, hi = 0, n // (k + 1) while lo < hi: mid = (lo + hi + 1) // 2 if mid * (k + 1) > n // 2: hi = mid - 1 else: lo = mid print(lo, lo * k, n - lo * (k + 1))
Title: Diplomas and Certificates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with...
```python n, k = input().split() n, k = int(n), int(k) lo, hi = 0, n // (k + 1) while lo < hi: mid = (lo + hi + 1) // 2 if mid * (k + 1) > n // 2: hi = mid - 1 else: lo = mid print(lo, lo * k, n - lo * (k + 1)) ```
3
169
A
Chores
PROGRAMMING
800
[ "sortings" ]
null
null
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexit...
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ...
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
[ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ]
[ "3\n", "0\n" ]
In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
500
[ { "input": "5 2 3\n6 2 3 100 1", "output": "3" }, { "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0" }, { "input": "2 1 1\n10 2", "output": "8" }, { "input": "2 1 1\n7 7", "output": "0" }, { "input": "2 1 1\n1 1000000000", "output": "999999999" }, { "inp...
1,697,781,105
2,147,483,647
PyPy 3
OK
TESTS
29
93
1,228,800
from sys import stdin, stdout n, a, b = map(int, stdin.readline().split()) H = list(map(int, stdin.readline().split())) H.sort() hardest_for_vasya = H[b-1] easiest_for_petya = H[b] ans = easiest_for_petya - hardest_for_vasya stdout.write(str(ans)) if ans > 0 else stdout.write(str(ans))
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th...
```python from sys import stdin, stdout n, a, b = map(int, stdin.readline().split()) H = list(map(int, stdin.readline().split())) H.sort() hardest_for_vasya = H[b-1] easiest_for_petya = H[b] ans = easiest_for_petya - hardest_for_vasya stdout.write(str(ans)) if ans > 0 else stdout.write(str(ans)) ```
3
977
E
Cyclic Components
PROGRAMMING
1,500
[ "dfs and similar", "dsu", "graphs" ]
null
null
You are given an undirected graph consisting of $n$ vertices and $m$ edges. Your task is to find the number of connected components which are cycles. Here are some definitions of graph theory. An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of verti...
The first line contains two integer numbers $n$ and $m$ ($1 \le n \le 2 \cdot 10^5$, $0 \le m \le 2 \cdot 10^5$) — number of vertices and edges. The following $m$ lines contains edges: edge $i$ is given as a pair of vertices $v_i$, $u_i$ ($1 \le v_i, u_i \le n$, $u_i \ne v_i$). There is no multiple edges in the given ...
Print one integer — the number of connected components which are also cycles.
[ "5 4\n1 2\n3 4\n5 4\n3 5\n", "17 15\n1 8\n1 12\n5 11\n11 9\n9 15\n15 5\n4 13\n3 13\n4 3\n10 16\n7 10\n16 7\n14 3\n14 4\n17 6\n" ]
[ "1\n", "2\n" ]
In the first example only component $[3, 4, 5]$ is also a cycle. The illustration above corresponds to the second example.
0
[ { "input": "5 4\n1 2\n3 4\n5 4\n3 5", "output": "1" }, { "input": "17 15\n1 8\n1 12\n5 11\n11 9\n9 15\n15 5\n4 13\n3 13\n4 3\n10 16\n7 10\n16 7\n14 3\n14 4\n17 6", "output": "2" }, { "input": "4 4\n1 2\n2 3\n1 3\n1 4", "output": "0" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 1\n3 5...
1,698,385,717
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
def cyclic_components(graph): visited = set() components = [] def dfs(node): visited.add(node) component.append(node) for neighbor in graph[node]: if neighbor not in visited: dfs(neighbor) elif neighbor in component: # We have found a cycle. components.append(comp...
Title: Cyclic Components Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an undirected graph consisting of $n$ vertices and $m$ edges. Your task is to find the number of connected components which are cycles. Here are some definitions of graph theory. An undirected graph co...
```python def cyclic_components(graph): visited = set() components = [] def dfs(node): visited.add(node) component.append(node) for neighbor in graph[node]: if neighbor not in visited: dfs(neighbor) elif neighbor in component: # We have found a cycle. components.a...
0
825
D
Suitable Replacement
PROGRAMMING
1,500
[ "binary search", "greedy", "implementation" ]
null
null
You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters. Suitability of string *s* is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all...
The first line contains string *s* (1<=≤<=|*s*|<=≤<=106). The second line contains string *t* (1<=≤<=|*t*|<=≤<=106).
Print string *s* with '?' replaced with small Latin letters in such a way that suitability of that string is maximal. If there are multiple strings with maximal suitability then print any of them.
[ "?aa?\nab\n", "??b?\nza\n", "abcd\nabacaba\n" ]
[ "baab\n", "azbz\n", "abcd\n" ]
In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2. In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them. In the third exam...
0
[ { "input": "?aa?\nab", "output": "baab" }, { "input": "??b?\nza", "output": "azbz" }, { "input": "abcd\nabacaba", "output": "abcd" }, { "input": "mqwstphetbfrsyxuzdww\nrutseqtsbh", "output": "mqwstphetbfrsyxuzdww" }, { "input": "????????????????????\nxwkxsxlrre", ...
1,500,411,569
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
5,017,600
from collections import Counter # s = input() # t = input() s = 'aa??aa' * 1000 t = 'babc' new_s = '' c = Counter(s) while True: for i in t: if c[i] and c[i] > 0: c[i] -= 1 elif c['?'] and c['?'] > 0: c['?'] -= 1 new_s += i else: ...
Title: Suitable Replacement Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters. Suitability of string *s* is calculated by following metric: Any two letters can be swapped po...
```python from collections import Counter # s = input() # t = input() s = 'aa??aa' * 1000 t = 'babc' new_s = '' c = Counter(s) while True: for i in t: if c[i] and c[i] > 0: c[i] -= 1 elif c['?'] and c['?'] > 0: c['?'] -= 1 new_s += i else...
0
701
A
Cards
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards ...
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print...
[ "6\n1 5 7 4 4 3\n", "4\n10 10 10 10\n" ]
[ "1 3\n6 2\n4 5\n", "1 2\n3 4\n" ]
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
500
[ { "input": "6\n1 5 7 4 4 3", "output": "1 3\n6 2\n4 5" }, { "input": "4\n10 10 10 10", "output": "1 4\n2 3" }, { "input": "100\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 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 2 2 2 2 2 2 2 2 2 ...
1,588,684,237
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
32
155
2,150,400
n=int(input()) l=list(map(int,input().split())) a=[] d={} for i in range(n): for j in range(i+1,n): s=sum([l[i],l[j]]) a.append([s,i+1,j+1]) if s in d: d[s]+=1 else: d[s]=1 a.sort() k=max(d,key=d.get) b=[] for i in a: if(i[0]==k):...
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p...
```python n=int(input()) l=list(map(int,input().split())) a=[] d={} for i in range(n): for j in range(i+1,n): s=sum([l[i],l[j]]) a.append([s,i+1,j+1]) if s in d: d[s]+=1 else: d[s]=1 a.sort() k=max(d,key=d.get) b=[] for i in a: if...
0
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,618,503,049
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
# collaborated with no one vowels = ["a", "e", "i", "o", "u", "y"] counter = 0 userInput = input() for letter in userInput: if letter.isdigit(): if int(letter) % 2 == 0: counter += 1 elif letter in vowels: counter += 1 print(counter)
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 # collaborated with no one vowels = ["a", "e", "i", "o", "u", "y"] counter = 0 userInput = input() for letter in userInput: if letter.isdigit(): if int(letter) % 2 == 0: counter += 1 elif letter in vowels: counter += 1 print(counter) ...
0
13
A
Numbers
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Numbers
1
64
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all c...
Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000).
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
[ "5\n", "3\n" ]
[ "7/3\n", "2/1\n" ]
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
0
[ { "input": "5", "output": "7/3" }, { "input": "3", "output": "2/1" }, { "input": "1000", "output": "90132/499" }, { "input": "927", "output": "155449/925" }, { "input": "260", "output": "6265/129" }, { "input": "131", "output": "3370/129" }, { ...
1,608,039,012
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
1,228,800
def f(n, k): s = 0 while n > 0: s += n % k n = int(n / k) return s n = int(input()) s = 0 for j in range(2, n): s += f(n, j) print(end = str(s) + '/' + str(n - 2))
Title: Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of su...
```python def f(n, k): s = 0 while n > 0: s += n % k n = int(n / k) return s n = int(input()) s = 0 for j in range(2, n): s += f(n, j) print(end = str(s) + '/' + str(n - 2)) ```
0
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,696,594,960
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n = int(input()) mas = sorted(list(map(int, input().split())))[::-1] ser = 0 dima = 0 for i in range(n): if i%2==0: ser+=mas[i] else: dima+=mas[i] print(ser, dima)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python n = int(input()) mas = sorted(list(map(int, input().split())))[::-1] ser = 0 dima = 0 for i in range(n): if i%2==0: ser+=mas[i] else: dima+=mas[i] print(ser, dima) ```
0
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", ...
1,590,996,775
2,147,483,647
PyPy 3
OK
TESTS
79
218
13,004,800
n=(int)(input()) l=list(map(int,input().split())) c=0 for i in range(n): if l[i]==0: c+=1 if c>1: c=1 print(len(set(l))-c)
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second ...
```python n=(int)(input()) l=list(map(int,input().split())) c=0 for i in range(n): if l[i]==0: c+=1 if c>1: c=1 print(len(set(l))-c) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,599,916,667
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
122
0
strz = "PranAv" sm_cnt, cap_cnt = 0, 0 for i in range(len(strz)): if strz[i].islower(): sm_cnt += 1 elif strz[i].isupper(): cap_cnt += 1 if sm_cnt >= cap_cnt: print(strz.lower()) else: print(strz.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python strz = "PranAv" sm_cnt, cap_cnt = 0, 0 for i in range(len(strz)): if strz[i].islower(): sm_cnt += 1 elif strz[i].isupper(): cap_cnt += 1 if sm_cnt >= cap_cnt: print(strz.lower()) else: print(strz.upper()) ```
0
999
E
Reachability from the Capital
PROGRAMMING
2,000
[ "dfs and similar", "graphs", "greedy" ]
null
null
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way.
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$. The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_...
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
[ "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n", "5 4 5\n1 2\n2 3\n3 4\n4 1\n" ]
[ "3\n", "1\n" ]
The first example is illustrated by the following: For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$. The second example is illustrated by the following: In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the ci...
0
[ { "input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "output": "3" }, { "input": "5 4 5\n1 2\n2 3\n3 4\n4 1", "output": "1" }, { "input": "5000 0 2956", "output": "4999" }, { "input": "2 0 2", "output": "1" }, { "input": "2 1 1\n1 2", "output": "0"...
1,635,549,996
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
30
171
38,809,600
def bfs(g, node, unseen): start = [node] unseen.remove(node) while len(start) > 0: next_s = [] for x in start: for y in g[x][0]: if y in unseen: next_s.append(y) unseen.remove(y) start = next_s retu...
Title: Reachability from the Capital Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities r...
```python def bfs(g, node, unseen): start = [node] unseen.remove(node) while len(start) > 0: next_s = [] for x in start: for y in g[x][0]: if y in unseen: next_s.append(y) unseen.remove(y) start = next_s ...
-1
598
D
Igor In the Museum
PROGRAMMING
1,700
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i...
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that ...
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
[ "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n", "4 4 1\n****\n*..*\n*.**\n****\n3 2\n" ]
[ "6\n4\n10\n", "8\n" ]
none
0
[ { "input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3", "output": "6\n4\n10" }, { "input": "4 4 1\n****\n*..*\n*.**\n****\n3 2", "output": "8" }, { "input": "3 3 1\n***\n*.*\n***\n2 2", "output": "4" }, { "input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\...
1,644,068,182
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
51,200,000
n,m,p=[int(e)for e in input().split()] h=[list(input())for i in range(n)] s=[] for i in range(p): s.append([int(e)for e in input().split()]) w=[] k=0 def go(y,x): global n,m,h,w,k w+=[[y,x]] if x+1<m and h[y][x+1]=='*': k+=1 if x-1>=0 and h[y][x-1]=='*': k+=1 ...
Title: Igor In the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.'...
```python n,m,p=[int(e)for e in input().split()] h=[list(input())for i in range(n)] s=[] for i in range(p): s.append([int(e)for e in input().split()]) w=[] k=0 def go(y,x): global n,m,h,w,k w+=[[y,x]] if x+1<m and h[y][x+1]=='*': k+=1 if x-1>=0 and h[y][x-1]=='*': ...
0
115
A
Party
PROGRAMMING
900
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immedi...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate...
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
500
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": ...
1,677,739,164
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
print(len(set([int(input()) for _ in range(int(input()))])))
Title: Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an...
```python print(len(set([int(input()) for _ in range(int(input()))]))) ```
0
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,689,607,029
2,147,483,647
Python 3
OK
TESTS
30
187
0
n = int(input()) check = {'Tetrahedron': 4,'Cube':6,'Octahedron':8,'Dodecahedron':12,'Icosahedron':20} res = 0 for i in range(n): res += check[input()] print(res)
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python n = int(input()) check = {'Tetrahedron': 4,'Cube':6,'Octahedron':8,'Dodecahedron':12,'Icosahedron':20} res = 0 for i in range(n): res += check[input()] print(res) ```
3
821
B
Okabe and Banana Trees
PROGRAMMING
1,300
[ "brute force", "math" ]
null
null
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor ...
The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000).
Print the maximum number of bananas Okabe can get from the trees he cuts.
[ "1 5\n", "2 3\n" ]
[ "30\n", "25\n" ]
The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.
1,000
[ { "input": "1 5", "output": "30" }, { "input": "2 3", "output": "25" }, { "input": "4 6", "output": "459" }, { "input": "6 3", "output": "171" }, { "input": "1 1", "output": "1" }, { "input": "10 1", "output": "55" }, { "input": "20 10", ...
1,498,408,157
6,857
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
7
2,000
4,608,000
## 2 m, b = list(map(int, input().split())) ans = 0 for x in range(m*b + 1): y = int(float(b) - x/m) suma = int(x*(x+1)/2); sumb = int(y*(y+1)/2) ans = max(ans, (y+1)*suma+(x+1)*sumb) print(ans)
Title: Okabe and Banana Trees Time Limit: None seconds Memory Limit: None megabytes Problem Description: Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers a...
```python ## 2 m, b = list(map(int, input().split())) ans = 0 for x in range(m*b + 1): y = int(float(b) - x/m) suma = int(x*(x+1)/2); sumb = int(y*(y+1)/2) ans = max(ans, (y+1)*suma+(x+1)*sumb) print(ans) ```
0
25
B
Phone numbers
PROGRAMMING
1,100
[ "implementation" ]
B. Phone numbers
2
256
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three...
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups.
Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.
[ "6\n549871\n", "7\n1198733\n" ]
[ "54-98-71", "11-987-33\n" ]
none
0
[ { "input": "6\n549871", "output": "54-98-71" }, { "input": "7\n1198733", "output": "119-87-33" }, { "input": "2\n74", "output": "74" }, { "input": "2\n33", "output": "33" }, { "input": "3\n074", "output": "074" }, { "input": "3\n081", "output": "08...
1,505,568,412
2,147,483,647
Python 3
OK
TESTS
20
124
0
n = int(input()) s = input() for i in range(n): print(s[i], end = '') if (i + 1) % 2 == 0: if n % 2 == 0 and i != n - 1: print('-', end = '') if n % 2 != 0 and i != n - 2: print('-', end = '')
Title: Phone numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33....
```python n = int(input()) s = input() for i in range(n): print(s[i], end = '') if (i + 1) % 2 == 0: if n % 2 == 0 and i != n - 1: print('-', end = '') if n % 2 != 0 and i != n - 2: print('-', end = '') ```
3.969
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t...
Print *m* integers — the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5...
1,698,520,114
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
9,523,200
s = input() Pref = [0] for i in range(1, len(s)): Pref.append(Pref[-1] + (s[i] == s[i - 1])) m = int(input()) for _ in range(m): l, r = map(int, input().split()) l -= 1 r -= 1 print(Pref[r] - Pref[l]) # Sat Oct 28 2023 22:08:33 GMT+0300 (Moscow Standard Time)
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ...
```python s = input() Pref = [0] for i in range(1, len(s)): Pref.append(Pref[-1] + (s[i] == s[i - 1])) m = int(input()) for _ in range(m): l, r = map(int, input().split()) l -= 1 r -= 1 print(Pref[r] - Pref[l]) # Sat Oct 28 2023 22:08:33 GMT+0300 (Moscow Standard Time) ```
0
1,003
A
Polycarp's Pockets
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i...
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
[ "6\n1 2 4 3 3 2\n", "1\n100\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "6\n1 2 4 3 3 2", "output": "2" }, { "input": "1\n100", "output": "1" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
1,618,927,959
2,147,483,647
Python 3
OK
TESTS
37
77
0
n=int(input()) x=[int(w) for w in input().split()] a=0 m=[] for i in set(x): m.append(x.count(i)) print(max(m))
Title: Polycarp's Pockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Po...
```python n=int(input()) x=[int(w) for w in input().split()] a=0 m=[] for i in set(x): m.append(x.count(i)) print(max(m)) ```
3
887
A
Div. 64
PROGRAMMING
1,000
[ "implementation" ]
null
null
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi...
In the only line given a non-empty binary string *s* with length up to 100.
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
[ "100010001\n", "100\n" ]
[ "yes", "no" ]
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system. You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system)
500
[ { "input": "100010001", "output": "yes" }, { "input": "100", "output": "no" }, { "input": "0000001000000", "output": "yes" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "no" }, { "in...
1,510,166,361
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
0
ch=input() t=False s=0 f=False for x in ch: f= f or x=='0' if not f: break for x in range(len(ch)): if ch[x]=='1': i=x+1 for j in range(i,len(ch)): if ch[j]=='0': s+=1 if s>=6: t=True ...
Title: Div. 64 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig...
```python ch=input() t=False s=0 f=False for x in ch: f= f or x=='0' if not f: break for x in range(len(ch)): if ch[x]=='1': i=x+1 for j in range(i,len(ch)): if ch[j]=='0': s+=1 if s>=6: t=Tru...
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,684,168,204
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
124
0
a=input() h=['H','Q','9','+'] flag=0 for i in a: if i in h: print("YES") flag=1 break if(flag==0): 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 a=input() h=['H','Q','9','+'] flag=0 for i in a: if i in h: print("YES") flag=1 break if(flag==0): print("NO") ```
0