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
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string...
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11)...
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output"...
1,641,050,423
2,147,483,647
PyPy 3-64
OK
TESTS
43
124
1,228,800
s = input() ans = 0 for i in range(len(s)): temp = s.find('bear', i) if temp >= 0: ans += len(s) - temp - 3 print(ans)
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j...
```python s = input() ans = 0 for i in range(len(s)): temp = s.find('bear', i) if temp >= 0: ans += len(s) - temp - 3 print(ans) ```
3
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,691,179,633
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
x=input() s=set(x) print(len(s))
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python x=input() s=set(x) print(len(s)) ```
0
35
A
Shell Game
PROGRAMMING
1,000
[ "implementation" ]
A. Shell Game
2
64
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so ...
The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered...
In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles.
[ "1\n1 2\n2 1\n2 1\n", "1\n2 1\n3 1\n1 3\n" ]
[ "2\n", "2\n" ]
none
500
[ { "input": "1\n1 2\n2 1\n2 1", "output": "2" }, { "input": "1\n2 1\n3 1\n1 3", "output": "2" }, { "input": "3\n3 1\n2 1\n1 2", "output": "1" }, { "input": "1\n1 3\n1 2\n2 3", "output": "2" }, { "input": "3\n3 2\n3 1\n3 1", "output": "2" }, { "input": "...
1,535,926,544
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
0
import sys sys.stdin=open('input.txt', 'r') sys.stdout=open('output.txt', 'w') x = input a = [0] * 4 a[x] = 1 for i in range(3): x, y = map(int, input().split()) a[x], a[y] = a[y], a[x] for i in range(3): if a[i] == 1: print(i)
Title: Shell Game Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly put...
```python import sys sys.stdin=open('input.txt', 'r') sys.stdout=open('output.txt', 'w') x = input a = [0] * 4 a[x] = 1 for i in range(3): x, y = map(int, input().split()) a[x], a[y] = a[y], a[x] for i in range(3): if a[i] == 1: print(i) ```
-1
550
C
Divisibility by Eight
PROGRAMMING
1,500
[ "brute force", "dp", "math" ]
null
null
You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a no...
The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits.
Print "NO" (without quotes), if there is no such way to remove some digits from number *n*. Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8. If there are multiple possible answers, you may print any ...
[ "3454\n", "10\n", "111111\n" ]
[ "YES\n344\n", "YES\n0\n", "NO\n" ]
none
1,000
[ { "input": "3454", "output": "YES\n344" }, { "input": "10", "output": "YES\n0" }, { "input": "111111", "output": "NO" }, { "input": "8996988892", "output": "YES\n8" }, { "input": "5555555555", "output": "NO" }, { "input": "1", "output": "NO" }, ...
1,671,741,187
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
def f(): a = int(input()) a_str = str(a) b = '' d = [] for i in range(len(a_str)): for j in range(len(a_str)): if i != j: b += a_str[j] if int(b) % 8 == 0 and len(b) >= 1 and not b.startswith('0') and int(b) > 0: return f'Yes\n{b}' ...
Title: Divisibility by Eight Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of t...
```python def f(): a = int(input()) a_str = str(a) b = '' d = [] for i in range(len(a_str)): for j in range(len(a_str)): if i != j: b += a_str[j] if int(b) % 8 == 0 and len(b) >= 1 and not b.startswith('0') and int(b) > 0: return f'Ye...
0
147
A
Punctuation
PROGRAMMING
1,300
[ "implementation", "strings" ]
null
null
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters. Your task is to add spaces to the text by the following rules: - if there is no punctuation mark between two word...
The input data contains of a single non-empty line — the text whose length is no more than 10000 characters.
Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter.
[ "galileo galilei was an italian physicist ,mathematician,astronomer\n", "galileo was born in pisa\n" ]
[ "galileo galilei was an italian physicist, mathematician, astronomer\n", "galileo was born in pisa\n" ]
none
500
[ { "input": "galileo galilei was an italian physicist ,mathematician,astronomer", "output": "galileo galilei was an italian physicist, mathematician, astronomer" }, { "input": "galileo was born in pisa", "output": "galileo was born in pisa" }, { "input": "jkhksdfhsdfsf", "outpu...
1,684,241,831
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
124
0
a=input() for i in range(len(a)): if a[i]==',': print(a[i],end=' ') if a[i]!=' ' and a[i]!=',': print(a[i],end='') if a[i]==' ' and a[i+1]!=',': if a[i+1]!=' ': print(a[i],end='') i+=1;
Title: Punctuation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters. Your task is to ad...
```python a=input() for i in range(len(a)): if a[i]==',': print(a[i],end=' ') if a[i]!=' ' and a[i]!=',': print(a[i],end='') if a[i]==' ' and a[i+1]!=',': if a[i+1]!=' ': print(a[i],end='') i+=1; ```
0
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", ...
1,661,017,547
2,147,483,647
Python 3
OK
TESTS
54
46
0
if __name__ == '__main__': k = int(input()) squares = input().split('W') aux = [] for b in squares: if b != '': aux.append(len(b)) if aux: print(len(aux)) print(*aux) else: print(0)
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the...
```python if __name__ == '__main__': k = int(input()) squares = input().split('W') aux = [] for b in squares: if b != '': aux.append(len(b)) if aux: print(len(aux)) print(*aux) else: print(0) ```
3
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,693,932,480
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
Nums = input().split() Min = Nums[0] if Nums[1] < Min: Min = Nums[1] if Nums[2] < Min: Min = Nums[2] print(Min)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python Nums = input().split() Min = Nums[0] if Nums[1] < Min: Min = Nums[1] if Nums[2] < Min: Min = Nums[2] print(Min) ```
0
604
A
Uncowed Forces
PROGRAMMING
1,000
[ "implementation" ]
null
null
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a...
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted. The second line contains five space-separated integers *w*1, *w*2, *w*3, ...
Print a single integer, the value of Kevin's final score.
[ "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "119 119 119 119 119\n0 0 0 0 0\n10 0\n" ]
[ "4900\n", "4930\n" ]
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving pro...
500
[ { "input": "20 40 60 80 100\n0 1 2 3 4\n1 0", "output": "4900" }, { "input": "119 119 119 119 119\n0 0 0 0 0\n10 0", "output": "4930" }, { "input": "3 6 13 38 60\n6 10 10 3 8\n9 9", "output": "5088" }, { "input": "21 44 11 68 75\n6 2 4 8 4\n2 8", "output": "4522" }, {...
1,512,297,375
975
Python 3
OK
TESTS
57
62
5,529,600
a=[] b=[] a=list(map(int,input().split())) b=list(map(int,input().split())) n,m=map(int,input().split()) sum=500 ans=0 for i in range(5): ans+=max((0.3*sum),(1-a[i]/250)*sum-50*b[i]); sum+=500; ans+=100*n; ans-=50*m; print(int(ans))
Title: Uncowed Forces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challengin...
```python a=[] b=[] a=list(map(int,input().split())) b=list(map(int,input().split())) n,m=map(int,input().split()) sum=500 ans=0 for i in range(5): ans+=max((0.3*sum),(1-a[i]/250)*sum-50*b[i]); sum+=500; ans+=100*n; ans-=50*m; print(int(ans)) ```
3
656
F
Ace It!
PROGRAMMING
1,900
[ "*special" ]
null
null
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). Output a single integer.
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer.
[ "A221033\n", "A223635\n", "A232726\n" ]
[ "21\n", "22\n", "23\n" ]
none
0
[ { "input": "A221033", "output": "21" }, { "input": "A223635", "output": "22" }, { "input": "A232726", "output": "23" }, { "input": "A102210", "output": "25" }, { "input": "A231010", "output": "26" }, { "input": "A222222", "output": "13" }, { ...
1,642,070,468
2,147,483,647
Python 3
OK
TESTS
33
46
0
a=str(input()) s=0 for i in range(len(a)): if a[i]=='A': s+=1 elif a[i]=='1': s+=10 else: s+=int(a[i]) print(s)
Title: Ace It! Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). Output a single integer. Input Specificat...
```python a=str(input()) s=0 for i in range(len(a)): if a[i]=='A': s+=1 elif a[i]=='1': s+=10 else: s+=int(a[i]) print(s) ```
3
349
A
Cinema Line
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
[ "4\n25 25 50 50\n", "2\n25 100\n", "4\n50 50 25 25\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "4\n25 25 50 50", "output": "YES" }, { "input": "2\n25 100", "output": "NO" }, { "input": "4\n50 50 25 25", "output": "NO" }, { "input": "3\n25 50 100", "output": "NO" }, { "input": "10\n25 25 25 25 25 25 25 25 25 25", "output": "YES" }, { "...
1,660,320,467
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
15
154
13,312,000
n=int(input()) sum=0 flag=-1 a=list(map(int,input().split())) if a[0]!=25: print("NO") exit() else: for i in range(0,n-1): sum=sum+a[i] no=sum-a[i+1] if(no<0): flag=0 break; else: flag=1; if flag==1: print("YES") i...
Title: Cinema Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin...
```python n=int(input()) sum=0 flag=-1 a=list(map(int,input().split())) if a[0]!=25: print("NO") exit() else: for i in range(0,n-1): sum=sum+a[i] no=sum-a[i+1] if(no<0): flag=0 break; else: flag=1; if flag==1: print...
0
574
B
Bear and Three Musketeers
PROGRAMMING
1,500
[ "brute force", "dfs and similar", "graphs", "hashing" ]
null
null
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose thre...
The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**...
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
[ "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n", "7 4\n2 1\n3 6\n5 1\n1 7\n" ]
[ "2\n", "-1\n" ]
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti...
1,000
[ { "input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "output": "2" }, { "input": "7 4\n2 1\n3 6\n5 1\n1 7", "output": "-1" }, { "input": "5 0", "output": "-1" }, { "input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4", "output": "5" }, { ...
1,569,882,810
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import math n,m=map(int, input().split()) rede=[] for _ in range(n): rede.append([False]*n) somas=[0]*n ans=math.inf for __ in range(m): a,b=map(int,input().split()) rede[a-1][b-1]=True rede[b-1][a-1]=True somas[a-1]+=1 somas[b-1]+=1 for i in range(n): for j in range(i+1,n): if rede[i][j]: ...
Title: Bear and Three Musketeers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br...
```python import math n,m=map(int, input().split()) rede=[] for _ in range(n): rede.append([False]*n) somas=[0]*n ans=math.inf for __ in range(m): a,b=map(int,input().split()) rede[a-1][b-1]=True rede[b-1][a-1]=True somas[a-1]+=1 somas[b-1]+=1 for i in range(n): for j in range(i+1,n): if rede[i...
-1
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "outpu...
1,679,398,344
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n = int(input()) vals = [0,2,4,6,1,3,5] d4 = vals[n % 7] d7, r7 = divmod(n - 4*d4, 7) if r7 != 0 or n == 0: print(-1) exit() s = "4" * d4 + "7" * d7 print(s)
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n = int(input()) vals = [0,2,4,6,1,3,5] d4 = vals[n % 7] d7, r7 = divmod(n - 4*d4, 7) if r7 != 0 or n == 0: print(-1) exit() s = "4" * d4 + "7" * d7 print(s) ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,568,906,800
2,147,483,647
PyPy 3
OK
TESTS
102
202
0
m=input() n=input() s='' for x in range(len(m)): if m[x]!=n[x]: s+='1' else: s+='0' print(s)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python m=input() n=input() s='' for x in range(len(m)): if m[x]!=n[x]: s+='1' else: s+='0' print(s) ```
3.9495
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,655,559,745
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
import sys input = sys.stdin.readline def in_int(): return(int(input())) def in_list(): return(list(map(int,input().split()))) def in_string(): s = input() return(list(s[:len(s) - 1])) def in_space(): return(map(int,input().split())) n = in_int() inputs = [] for i in range(n):...
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 import sys input = sys.stdin.readline def in_int(): return(int(input())) def in_list(): return(list(map(int,input().split()))) def in_string(): s = input() return(list(s[:len(s) - 1])) def in_space(): return(map(int,input().split())) n = in_int() inputs = [] for i in...
0
32
A
Reconnaissance
PROGRAMMING
800
[ "brute force" ]
A. Reconnaissance
2
256
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som...
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1...
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
[ "5 10\n10 20 50 60 65\n", "5 1\n55 30 29 31 55\n" ]
[ "6\n", "6\n" ]
none
500
[ { "input": "5 10\n10 20 50 60 65", "output": "6" }, { "input": "5 1\n55 30 29 31 55", "output": "6" }, { "input": "6 10\n4 6 4 1 9 3", "output": "30" }, { "input": "7 100\n19 1694 261 162 1 234 513", "output": "8" }, { "input": "8 42\n37 53 74 187 568 22 5 65", ...
1,692,194,024
2,147,483,647
Python 3
OK
TESTS
32
404
0
j=lambda:map(int,input().split()) n,d=j();a=[*j()] print(sum(abs(x-y)<=d for x in a for y in a)-n)
Title: Reconnaissance Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h...
```python j=lambda:map(int,input().split()) n,d=j();a=[*j()] print(sum(abs(x-y)<=d for x in a for y in a)-n) ```
3.899
612
A
The Text Splitting
PROGRAMMING
1,300
[ "brute force", "implementation", "strings" ]
null
null
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string *s* to the st...
The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100). The second line contains the string *s* consists of lowercase and uppercase latin letters and digits.
If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1". Otherwise in the first line print integer *k* — the number of strings in partition of *s*. Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The...
[ "5 2 3\nHello\n", "10 9 5\nCodeforces\n", "6 4 5\nPrivet\n", "8 1 1\nabacabac\n" ]
[ "2\nHe\nllo\n", "2\nCodef\norces\n", "-1\n", "8\na\nb\na\nc\na\nb\na\nc\n" ]
none
0
[ { "input": "5 2 3\nHello", "output": "2\nHe\nllo" }, { "input": "10 9 5\nCodeforces", "output": "2\nCodef\norces" }, { "input": "6 4 5\nPrivet", "output": "-1" }, { "input": "8 1 1\nabacabac", "output": "8\na\nb\na\nc\na\nb\na\nc" }, { "input": "1 1 1\n1", "ou...
1,601,054,529
429
PyPy 3
OK
TESTS
72
233
1,331,200
n, p, q = map(int, input().split()) s = list(input()) f = 0 for i in range(101): if f: break for j in range(101): if p * i + q * j == n: ans = [] l, r = 0, 0 for _ in range(i): r += p ans.append(s[l : r]) ...
Title: The Text Splitting Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "H...
```python n, p, q = map(int, input().split()) s = list(input()) f = 0 for i in range(101): if f: break for j in range(101): if p * i + q * j == n: ans = [] l, r = 0, 0 for _ in range(i): r += p ans.append(s[l : r]) ...
3
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,670,339,847
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
61
0
from math import ceil inp = input().split() a = int(inp[0]) b = int(inp[1]) c = int(inp[2]) s = 0 s += ceil(a/c) s += ceil (b/c) print(s)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python from math import ceil inp = input().split() a = int(inp[0]) b = int(inp[1]) c = int(inp[2]) s = 0 s += ceil(a/c) s += ceil (b/c) print(s) ```
0
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,624,377,981
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
# 1 ''' n, m = map(int, input().split()) q = float('inf') # + бесконечность for i in range(n): a, b = map(int, input().split()) if a / b * m < q: q = a / b * m print(q) ''' # 2 n, b, d = map(int, input().split()) a = [int(i) for i in input().split()] q = 0 w = 0 for i in a: if i ...
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 # 1 ''' n, m = map(int, input().split()) q = float('inf') # + бесконечность for i in range(n): a, b = map(int, input().split()) if a / b * m < q: q = a / b * m print(q) ''' # 2 n, b, d = map(int, input().split()) a = [int(i) for i in input().split()] q = 0 w = 0 for i in a: ...
0
656
A
Da Vinci Powers
PROGRAMMING
1,900
[ "*special" ]
null
null
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output a single integer.
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
[ "3\n", "10\n" ]
[ "8\n", "1024\n" ]
none
0
[ { "input": "3", "output": "8" }, { "input": "10", "output": "1024" }, { "input": "35", "output": "33940307968" }, { "input": "0", "output": "1" }, { "input": "1", "output": "2" }, { "input": "2", "output": "4" }, { "input": "4", "output...
1,489,084,568
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
4,608,000
# Da Vinci Powers a=int(input('')) print(2**a)
Title: Da Vinci Powers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output a single integer. Input Specification: The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output Specification: Output a single integer. De...
```python # Da Vinci Powers a=int(input('')) print(2**a) ```
0
810
A
Straight <<A>>
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, wh...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
[ "2 10\n8 9\n", "3 5\n4 4 4\n" ]
[ "4", "3" ]
Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc...
500
[ { "input": "2 10\n8 9", "output": "4" }, { "input": "3 5\n4 4 4", "output": "3" }, { "input": "3 10\n10 8 9", "output": "3" }, { "input": "2 23\n21 23", "output": "2" }, { "input": "5 10\n5 10 10 9 10", "output": "7" }, { "input": "12 50\n18 10 26 22 2...
1,521,375,990
2,147,483,647
Python 3
OK
TESTS
106
78
7,065,600
IL = lambda: list(map(int, input().split())) I = lambda: int(input()) n, k = IL() a = IL() print(max(sum([k-i for i in a])*2-n, 0))
Title: Straight <<A>> Time Limit: None seconds Memory Limit: None megabytes Problem Description: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. ...
```python IL = lambda: list(map(int, input().split())) I = lambda: int(input()) n, k = IL() a = IL() print(max(sum([k-i for i in a])*2-n, 0)) ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,622,542,926
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
0
s=input() o="" cl=0 for i in range(len(s)): if(i+1<len(s) and s[i]!=s[i+1]): if(s[i]=='l'): cl+=1 o+=s[i] o+=s[len(s)-1] #print(o) if(o.__contains__("helo")): print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python s=input() o="" cl=0 for i in range(len(s)): if(i+1<len(s) and s[i]!=s[i+1]): if(s[i]=='l'): cl+=1 o+=s[i] o+=s[len(s)-1] #print(o) if(o.__contains__("helo")): print("YES") else: print("NO") ```
0
6
B
President's Office
PROGRAMMING
1,100
[ "implementation" ]
B. President's Office
2
64
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ...
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ...
Print the only number — the amount of President's deputies.
[ "3 4 R\nG.B.\n.RR.\nTTT.\n", "3 3 Z\n...\n.H.\n..Z\n" ]
[ "2\n", "0\n" ]
none
0
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.", "output": "2" }, { "input": "3 3 Z\n...\n.H.\n..Z", "output": "0" }, { "input": "1 1 C\nC", "output": "0" }, { "input": "2 2 W\nKW\nKW", "output": "1" }, { "input": "1 10 H\n....DDHHHH", "output": "1" }, { "input":...
1,625,335,292
2,147,483,647
Python 3
OK
TESTS
32
77
0
n,m,col=input().split() matrix=[] n,m=int(n),int(m) for i in range(n): matrix.append(list(input())) def check_square_for_dep(colour_of_square,president,deps): if colour_of_square!='.' and colour_of_square!=president: deps.append(colour_of_square) def get_dep(x,y,mat,c,n,m): deps...
Title: President's Office Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ...
```python n,m,col=input().split() matrix=[] n,m=int(n),int(m) for i in range(n): matrix.append(list(input())) def check_square_for_dep(colour_of_square,president,deps): if colour_of_square!='.' and colour_of_square!=president: deps.append(colour_of_square) def get_dep(x,y,mat,c,n,m):...
3.98075
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,682,057,012
2,147,483,647
Python 3
OK
TESTS
34
92
0
n = int(input()) scores = {} for i in range(n): team = input().strip() if team in scores: scores[team] += 1 else: scores[team] = 1 winning_team = max(scores, key=scores.get) print(winning_team)
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python n = int(input()) scores = {} for i in range(n): team = input().strip() if team in scores: scores[team] += 1 else: scores[team] = 1 winning_team = max(scores, key=scores.get) print(winning_team) ```
3.977
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow...
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output...
1,699,593,145
2,147,483,647
Python 3
OK
TESTS
25
62
0
n, s = map(int, input().split()) if s <= (n+1)//2: print(s*2-1) else: print((s-(n+1)//2)*2)
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ...
```python n, s = map(int, input().split()) if s <= (n+1)//2: print(s*2-1) else: print((s-(n+1)//2)*2) ```
3
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st...
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "...
1,697,534,839
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
0
import math def prime(p): is_prime = True for j in range(2, int(math.sqrt(p)) + 1): if p % j == 0: is_prime = False return is_prime n = int(input()) numbers = list(map(int,input().split())) for i in range(n): x = 2 while x**2 < numbers[i]: x += 1 wh...
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an ar...
```python import math def prime(p): is_prime = True for j in range(2, int(math.sqrt(p)) + 1): if p % j == 0: is_prime = False return is_prime n = int(input()) numbers = list(map(int,input().split())) for i in range(n): x = 2 while x**2 < numbers[i]: x += 1 ...
0
776
B
Sherlock and his girlfriend
PROGRAMMING
1,200
[ "constructive algorithms", "number theory" ]
null
null
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1. Watson gave Sherlock a challenge to color these jewelry pie...
The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces.
The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints. The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price. ...
[ "3\n", "4\n" ]
[ "2\n1 1 2 ", "2\n2 1 1 2\n" ]
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively. In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
1,000
[ { "input": "3", "output": "2\n1 1 2 " }, { "input": "4", "output": "2\n1 1 2 1 " }, { "input": "17", "output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 " }, { "input": "25", "output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 " }, { "input": "85", "ou...
1,556,707,914
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
307,200
from sys import stdout, stdin import math r = lambda: int(input()) ra = lambda: [*map(int, input().split())] raw = lambda: [*stdin.readline()] out = lambda a: stdout.write("".join(a)) def s(a): if a<=1: return False else: for i in range(2, int(math.sqrt(a))+1): if a%i==0: ...
Title: Sherlock and his girlfriend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ...
```python from sys import stdout, stdin import math r = lambda: int(input()) ra = lambda: [*map(int, input().split())] raw = lambda: [*stdin.readline()] out = lambda a: stdout.write("".join(a)) def s(a): if a<=1: return False else: for i in range(2, int(math.sqrt(a))+1): if a%i==...
0
959
A
Mahmoud and Ehab and the even-odd game
PROGRAMMING
800
[ "games", "math" ]
null
null
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab'...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game.
Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.
[ "1\n", "2\n" ]
[ "Ehab", "Mahmoud" ]
In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mah...
500
[ { "input": "1", "output": "Ehab" }, { "input": "2", "output": "Mahmoud" }, { "input": "10000", "output": "Mahmoud" }, { "input": "33333", "output": "Ehab" }, { "input": "5", "output": "Ehab" }, { "input": "1000000000", "output": "Mahmoud" }, { ...
1,668,485,988
2,147,483,647
Python 3
OK
TESTS
20
46
0
l=["Mahmoud","Ehab"] print(l[int(input())%2])
Title: Mahmoud and Ehab and the even-odd game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a*...
```python l=["Mahmoud","Ehab"] print(l[int(input())%2]) ```
3
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of int...
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10"...
1,685,329,101
2,147,483,647
Python 3
OK
TESTS
54
92
0
n,m=map(int,input().split()) x=0 for a in range(50): for b in range(50): if a**2+b==n and a+b**2==m: x+=1 print(x)
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi...
```python n,m=map(int,input().split()) x=0 for a in range(50): for b in range(50): if a**2+b==n and a+b**2==m: x+=1 print(x) ```
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }...
1,694,928,678
2,147,483,647
PyPy 3-64
OK
TESTS
15
46
0
#import re a, b, c = list(map(int, input().split())) i = c*(c+1)//2 if a*i>b: print(a*i-b) 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 #import re a, b, c = list(map(int, input().split())) i = c*(c+1)//2 if a*i>b: print(a*i-b) else: print(0) ```
3
300
C
Beautiful Numbers
PROGRAMMING
1,800
[ "brute force", "combinatorics" ]
null
null
Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite dig...
The first line contains three integers: *a*, *b*, *n* (1<=≤<=*a*<=&lt;<=*b*<=≤<=9,<=1<=≤<=*n*<=≤<=106).
Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
[ "1 3 3\n", "2 3 10\n" ]
[ "1\n", "165\n" ]
none
2,000
[ { "input": "1 3 3", "output": "1" }, { "input": "2 3 10", "output": "165" }, { "input": "6 8 14215", "output": "651581472" }, { "input": "4 9 104671", "output": "329390901" }, { "input": "6 7 78755", "output": "0" }, { "input": "1 8 265", "output":...
1,676,383,443
2,147,483,647
PyPy 3-64
MEMORY_LIMIT_EXCEEDED
TESTS
2
498
268,390,400
a, b, n = map(int, input().split()) C = [[0] * (n+1) for i in range(n+1)] C[0][0] = 0 C[1][0] = 1 C[1][1] = 1 for i in range(2, n+1): for j in range(n+1): C[i][j] = (C[i-1][j] + C[i-1][j-1]) % (10 ** 9 + 7) #for i in C: # print(i) ans = 0 def check(k, a, b): while k > 0: if k % 1...
Title: Beautiful Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number ex...
```python a, b, n = map(int, input().split()) C = [[0] * (n+1) for i in range(n+1)] C[0][0] = 0 C[1][0] = 1 C[1][1] = 1 for i in range(2, n+1): for j in range(n+1): C[i][j] = (C[i-1][j] + C[i-1][j-1]) % (10 ** 9 + 7) #for i in C: # print(i) ans = 0 def check(k, a, b): while k > 0: ...
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,679,706,301
2,147,483,647
Python 3
OK
TESTS
48
46
0
a, b, c = map(int, input().split()) min = min(a, min(b,c)) max = max(a, max(b,c)) print(max-min)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python a, b, c = map(int, input().split()) min = min(a, min(b,c)) max = max(a, max(b,c)) print(max-min) ```
3
786
A
Berzerk
PROGRAMMING
2,000
[ "dfs and similar", "dp", "games" ]
null
null
Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there are *n* objects numbered from 1 to *n* arranged in a circle (in clockwise order). Object number 1 is a black hole and the...
The first line of input contains a single integer *n* (2<=≤<=*n*<=≤<=7000) — number of objects in game. The second line contains integer *k*1 followed by *k*1 distinct integers *s*1,<=1,<=*s*1,<=2,<=...,<=*s*1,<=*k*1 — Rick's set. The third line contains integer *k*2 followed by *k*2 distinct integers *s*2,<=1,<=*s*2...
In the first line print *n*<=-<=1 words separated by spaces where *i*-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number *i*<=+<=1 he wins, "Lose" if he loses and "Loop" if the game will never end. Similarly, in the second line print *n*<=-<=1 words...
[ "5\n2 3 2\n3 1 2 3\n", "8\n4 6 2 3 4\n2 3 6\n" ]
[ "Lose Win Win Loop\nLoop Win Win Win\n", "Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose\n" ]
none
750
[ { "input": "5\n2 3 2\n3 1 2 3", "output": "Lose Win Win Loop\nLoop Win Win Win" }, { "input": "8\n4 6 2 3 4\n2 3 6", "output": "Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose" }, { "input": "10\n3 4 7 5\n2 8 5", "output": "Win Win Win Win Win Win Win Loop Win\nLose Win...
1,696,691,845
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
n = int(input()) rick_k, rick_set = map(int, input().split()) rick_moves = list(map(int, input().split())) morty_k, morty_set = map(int, input().split()) morty_moves = list(map(int, input().split())) rick_win = ["Loop"] * (n - 1) morty_win = ["Loop"] * (n - 1) def can_win(player_set, player_moves, opponent_w...
Title: Berzerk Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there are *n* objects numbered fro...
```python n = int(input()) rick_k, rick_set = map(int, input().split()) rick_moves = list(map(int, input().split())) morty_k, morty_set = map(int, input().split()) morty_moves = list(map(int, input().split())) rick_win = ["Loop"] * (n - 1) morty_win = ["Loop"] * (n - 1) def can_win(player_set, player_moves, ...
-1
81
A
Plug-in
PROGRAMMING
1,400
[ "implementation" ]
A. Plug-in
1
256
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy...
The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters.
Print the given string after it is processed. It is guaranteed that the result will contain at least one character.
[ "hhoowaaaareyyoouu\n", "reallazy\n", "abacabaabacabaa\n" ]
[ "wre", "rezy", "a" ]
none
500
[ { "input": "hhoowaaaareyyoouu", "output": "wre" }, { "input": "reallazy", "output": "rezy" }, { "input": "abacabaabacabaa", "output": "a" }, { "input": "xraccabccbry", "output": "xy" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b"...
1,424,113,708
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
1,024,000
x=input() i=0 while True: if i==len(x): break if x[i] in x[(i+1):]: k=x[i] x=x[:i]+x[i+1:] z=x.index(k) x=x[:z]+x[z+1:] i-=1 else: print(x[i],end="") i+=1
Title: Plug-in Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed...
```python x=input() i=0 while True: if i==len(x): break if x[i] in x[(i+1):]: k=x[i] x=x[:i]+x[i+1:] z=x.index(k) x=x[:z]+x[z+1:] i-=1 else: print(x[i],end="") i+=1 ```
0
377
A
Maze
PROGRAMMING
1,600
[ "dfs and similar" ]
null
null
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a...
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines co...
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of t...
[ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n" ]
[ "#.X#\nX.#.\n#...\n", "#XXX\n#X#.\nX#..\n...#\n.#.#\n" ]
none
500
[ { "input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#" }, { "input": "3 3 2\n#.#\n...\n#.#", "output": "#X#\nX..\n#.#" }, { "input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...
1,698,711,412
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
n, m, k = tuple(int(x) for x in input().split()) grid = [] adjacency_list = [[set() for i in range(m)] for j in range(n)] directions = [[0,1],[0,-1],[1,0],[-1,0]] for i in range(n): row = [] temp = input() for j in range(m): row.append(temp[j]) grid.append(row) for i in range(n): for j in ra...
Title: Maze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze w...
```python n, m, k = tuple(int(x) for x in input().split()) grid = [] adjacency_list = [[set() for i in range(m)] for j in range(n)] directions = [[0,1],[0,-1],[1,0],[-1,0]] for i in range(n): row = [] temp = input() for j in range(m): row.append(temp[j]) grid.append(row) for i in range(n): f...
0
702
C
Cellular Network
PROGRAMMING
1,500
[ "binary search", "implementation", "two pointers" ]
null
null
You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than ...
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number...
Print minimal *r* so that each city will be covered by cellular network.
[ "3 2\n-2 2 4\n-3 0\n", "5 3\n1 5 10 14 17\n4 11 15\n" ]
[ "4\n", "3\n" ]
none
0
[ { "input": "3 2\n-2 2 4\n-3 0", "output": "4" }, { "input": "5 3\n1 5 10 14 17\n4 11 15", "output": "3" }, { "input": "1 1\n-1000000000\n1000000000", "output": "2000000000" }, { "input": "1 1\n1000000000\n-1000000000", "output": "2000000000" }, { "input": "10 10\n...
1,681,516,878
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
# https://codeforces.com/contest/702/problem/C import bisect import sys def input(): return sys.stdin.readline().strip() def intput(): return map(int, input().split()) ''' binary search on closest tower for each city ''' # def solve(city,towers): # # loop through each city and find the nearest to...
Title: Cellular Network Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — ...
```python # https://codeforces.com/contest/702/problem/C import bisect import sys def input(): return sys.stdin.readline().strip() def intput(): return map(int, input().split()) ''' binary search on closest tower for each city ''' # def solve(city,towers): # # loop through each city and find the ...
0
992
B
Nastya Studies Informatics
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well. We define a pair of integers (*a*,<=*b*) good, if *GCD*(*a*,<=*b*)<==<=*x* and *LCM*(*a*,<=*b*)<==<=*y*, where *GCD*(*a*,...
The only line contains four integers *l*,<=*r*,<=*x*,<=*y* (1<=≤<=*l*<=≤<=*r*<=≤<=109, 1<=≤<=*x*<=≤<=*y*<=≤<=109).
In the only line print the only integer — the answer for the problem.
[ "1 2 1 2\n", "1 12 1 12\n", "50 100 3 30\n" ]
[ "2\n", "4\n", "0\n" ]
In the first example there are two suitable good pairs of integers (*a*, *b*): (1, 2) and (2, 1). In the second example there are four suitable good pairs of integers (*a*, *b*): (1, 12), (12, 1), (3, 4) and (4, 3). In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the...
1,000
[ { "input": "1 2 1 2", "output": "2" }, { "input": "1 12 1 12", "output": "4" }, { "input": "50 100 3 30", "output": "0" }, { "input": "1 1000000000 1 1000000000", "output": "4" }, { "input": "1 1000000000 158260522 200224287", "output": "0" }, { "input...
1,603,252,305
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
140
1,228,800
import math def function(l, r, x, y): div_y=[] total=0 for i in range(1, math.floor(math.sqrt(y))+1): if y%i==0: d1=i d2=int(y/i) if d1>=l and d2<=r: if math.gcd(d1, d2)==1: if d1==d2: total+=1...
Title: Nastya Studies Informatics Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well. We define...
```python import math def function(l, r, x, y): div_y=[] total=0 for i in range(1, math.floor(math.sqrt(y))+1): if y%i==0: d1=i d2=int(y/i) if d1>=l and d2<=r: if math.gcd(d1, d2)==1: if d1==d2: ...
0
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, ...
1,688,388,779
2,147,483,647
Python 3
OK
TESTS
33
46
0
x = int(input()) print(Z := 8 + x % 2, x - Z)
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statemen...
```python x = int(input()) print(Z := 8 + x % 2, x - Z) ```
3
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ...
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five l...
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { ...
1,597,312,928
2,147,483,647
Python 3
OK
TESTS
79
109
307,200
left, right, ambi=map(int, input().split()) if left!=right: if left<right: l=left+ambi if l>right: d=left-right right+=d ambi-=d print(2*(left+(ambi//2))) else: print(2*l) else: r=right+ambi if r>left: d=right-left left+=d ambi-=d print(2*(right+(ambi//2))) e...
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand....
```python left, right, ambi=map(int, input().split()) if left!=right: if left<right: l=left+ambi if l>right: d=left-right right+=d ambi-=d print(2*(left+(ambi//2))) else: print(2*l) else: r=right+ambi if r>left: d=right-left left+=d ambi-=d print(2*(right+(ambi/...
3
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" },...
1,698,354,135
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
def chat_or_ignore(gebruikersnaam): vowels = 'aeiouAEIOU' vowels_list = [klinker for klinker in gebruikersnaam if klinker in vowels] vowels_list = list(set(vowels_list)) return "CHAT WITH HER!" if len(vowels_list)%2 == 0 else "IGNORE HIM!" print(chat_or_ignore(input()))
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though...
```python def chat_or_ignore(gebruikersnaam): vowels = 'aeiouAEIOU' vowels_list = [klinker for klinker in gebruikersnaam if klinker in vowels] vowels_list = list(set(vowels_list)) return "CHAT WITH HER!" if len(vowels_list)%2 == 0 else "IGNORE HIM!" print(chat_or_ignore(input())) ```
0
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people....
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51...
1,553,197,424
2,147,483,647
Python 3
OK
TESTS
18
109
0
k,n,s,p = map(int,input().split()) if n % s == 0: sheetPerPerson = n // s else: sheetPerPerson = n // s + 1 total = sheetPerPerson * k if total % p == 0: print(total // p) else:print(total // p + 1)
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p...
```python k,n,s,p = map(int,input().split()) if n % s == 0: sheetPerPerson = n // s else: sheetPerPerson = n // s + 1 total = sheetPerPerson * k if total % p == 0: print(total // p) else:print(total // p + 1) ```
3
172
B
Pseudorandom Sequence Period
PROGRAMMING
1,200
[ "*special", "implementation", "number theory" ]
null
null
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for *i*<=≥<=1). Here *a*, *b*, *m* are constants, fixed for the given realization of the pseudorandom numbers generator, *r*0 is the so-called *randseed* (t...
The single line of the input contains four integers *a*, *b*, *m* and *r*0 (1<=≤<=*m*<=≤<=105,<=0<=≤<=*a*,<=*b*<=≤<=1000,<=0<=≤<=*r*0<=&lt;<=*m*), separated by single spaces.
Print a single integer — the period of the sequence.
[ "2 6 12 11\n", "2 3 5 1\n", "3 6 81 9\n" ]
[ "2\n", "4\n", "1\n" ]
The first sample is described above. In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ... In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ...
1,000
[ { "input": "2 6 12 11", "output": "2" }, { "input": "2 3 5 1", "output": "4" }, { "input": "3 6 81 9", "output": "1" }, { "input": "10 11 12 3", "output": "3" }, { "input": "4 4 5 4", "output": "2" }, { "input": "0 1 6 5", "output": "1" }, { ...
1,623,831,695
2,147,483,647
Python 3
OK
TESTS
56
218
5,324,800
a,b,m,r=map(int,input().split()) l,s=[],set() while r not in s: s.add(r) l.append(r) r=(a*r + b)%m print(len(l)-l.index(r))
Title: Pseudorandom Sequence Period Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for *i*<=≥<=1). Here *a*, *b*, *m* are con...
```python a,b,m,r=map(int,input().split()) l,s=[],set() while r not in s: s.add(r) l.append(r) r=(a*r + b)%m print(len(l)-l.index(r)) ```
3
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", ...
1,692,902,585
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
30
0
""" @auther:Abdallah_Gaber """ n= int(input()) sum_all = n*(n+1) / 2 n = int(n/2) sum_even = (n)*(n+1) sum_odd =(sum_all - sum_even) #print(sum_all) #print(sum_even) #print(sum_odd) print(int(sum_even - sum_odd))
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line...
```python """ @auther:Abdallah_Gaber """ n= int(input()) sum_all = n*(n+1) / 2 n = int(n/2) sum_even = (n)*(n+1) sum_odd =(sum_all - sum_even) #print(sum_all) #print(sum_even) #print(sum_odd) print(int(sum_even - sum_odd)) ```
0
0
none
none
none
0
[ "none" ]
null
null
One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph *G* with the following properties: - *G* has exactly *n* vertices, numbe...
The first line of the input contains two integers *n* and *m*  — the number of vertices and edges in the graph found by Petya, respectively. Each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*) — the edges of the graph *G*. It is guaranteed, that there ...
In the first line print "Yes" (without the quotes), if the string *s* Petya is interested in really exists and "No" (without the quotes) otherwise. If the string *s* exists, then print it on the second line of the output. The length of *s* must be exactly *n*, it must consist of only letters "a", "b" and "c" only, and...
[ "2 1\n1 2\n", "4 3\n1 2\n1 3\n1 4\n" ]
[ "Yes\naa\n", "No\n" ]
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to a...
0
[ { "input": "2 1\n1 2", "output": "Yes\naa" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "No" }, { "input": "4 4\n1 2\n1 3\n1 4\n3 4", "output": "Yes\nbacc" }, { "input": "1 0", "output": "Yes\na" }, { "input": "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5...
1,454,786,643
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
1,126,400
from queue import Queue def YES(): print("Yes"), print("".join(ans)), exit(0) def NO(): print("No"), exit(0) def setall(pos, chr): q = Queue() q.put(pos) while not q.empty(): cur = q.get() if ans[cur] == '-': ans[cur] = chr for t in...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by com...
```python from queue import Queue def YES(): print("Yes"), print("".join(ans)), exit(0) def NO(): print("No"), exit(0) def setall(pos, chr): q = Queue() q.put(pos) while not q.empty(): cur = q.get() if ans[cur] == '-': ans[cur] = chr ...
0
859
A
Declined Finalists
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ...
The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Print the minimum possible number of contestants that declined the invitation to compete onsite.
[ "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n", "5\n16 23 8 15 4\n", "3\n14 15 92\n" ]
[ "3\n", "0\n", "67\n" ]
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.
500
[ { "input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28", "output": "3" }, { "input": "5\n16 23 8 15 4", "output": "0" }, { "input": "3\n14 15 92", "output": "67" }, { "input": "1\n1000000", "output": "999975" }, { "input": "25\n1000000 ...
1,587,147,056
2,147,483,647
Python 3
OK
TESTS
25
124
0
n=int(input()) r=list(map(int,input().split())) m=max(r) if m<=25: print("0") exit() else: print(m-25)
Title: Declined Finalists Time Limit: None seconds Memory Limit: None megabytes Problem Description: This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t...
```python n=int(input()) r=list(map(int,input().split())) m=max(r) if m<=25: print("0") exit() else: print(m-25) ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,622,989,159
2,147,483,647
Python 3
OK
TESTS
40
109
0
s = iter(input()) print(["NO", "YES"][all(c in s for c in 'hello')])
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python s = iter(input()) print(["NO", "YES"][all(c in s for c in 'hello')]) ```
3.9455
6
B
President's Office
PROGRAMMING
1,100
[ "implementation" ]
B. President's Office
2
64
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ...
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ...
Print the only number — the amount of President's deputies.
[ "3 4 R\nG.B.\n.RR.\nTTT.\n", "3 3 Z\n...\n.H.\n..Z\n" ]
[ "2\n", "0\n" ]
none
0
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.", "output": "2" }, { "input": "3 3 Z\n...\n.H.\n..Z", "output": "0" }, { "input": "1 1 C\nC", "output": "0" }, { "input": "2 2 W\nKW\nKW", "output": "1" }, { "input": "1 10 H\n....DDHHHH", "output": "1" }, { "input":...
1,663,836,178
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
1
62
2,764,800
n,m,c=input().split() cmp=[input()for i in range(int(n))] for aa in cmp: if aa.count(c)>0: y=cmp.index(aa) x_1=aa.index(c);x_2=x_1+(aa.count(c)) if y!=0: w=cmp[y-1][x_1:x_2] if y!=len(cmp): s=cmp[y+1][x_1:x_2] if x_1!=0: a=cmp[y][x_1-1] if x_2!=int(m): d=cmp[y][x_2] tot...
Title: President's Office Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ...
```python n,m,c=input().split() cmp=[input()for i in range(int(n))] for aa in cmp: if aa.count(c)>0: y=cmp.index(aa) x_1=aa.index(c);x_2=x_1+(aa.count(c)) if y!=0: w=cmp[y-1][x_1:x_2] if y!=len(cmp): s=cmp[y+1][x_1:x_2] if x_1!=0: a=cmp[y][x_1-1] if x_2!=int(m): d=cmp[y]...
-1
934
B
A Prosperous Lot
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside. Big Banban is hesitating over the amount ...
The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops.
Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018.
[ "2\n", "6\n" ]
[ "462", "8080" ]
none
1,000
[ { "input": "2", "output": "8" }, { "input": "6", "output": "888" }, { "input": "3", "output": "86" }, { "input": "4", "output": "88" }, { "input": "5", "output": "886" }, { "input": "1000000", "output": "-1" }, { "input": "1", "output":...
1,618,937,674
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
10,854,400
int_k = int(input()) if(int_k%2 == 1): k = "4" int_k -= 1 else: k = "" while int_k > 0 : k += "8" int_k -= 2 print(int(k))
Title: A Prosperous Lot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a...
```python int_k = int(input()) if(int_k%2 == 1): k = "4" int_k -= 1 else: k = "" while int_k > 0 : k += "8" int_k -= 2 print(int(k)) ```
0
892
A
Greed
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans. The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<...
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).
[ "2\n3 5\n3 6\n", "3\n6 8 9\n6 10 12\n", "5\n0 0 5 0 0\n1 1 8 10 5\n", "4\n4 1 0 3\n5 2 2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n" ]
In the first sample, there are already 2 cans, so the answer is "YES".
500
[ { "input": "2\n3 5\n3 6", "output": "YES" }, { "input": "3\n6 8 9\n6 10 12", "output": "NO" }, { "input": "5\n0 0 5 0 0\n1 1 8 10 5", "output": "YES" }, { "input": "4\n4 1 0 3\n5 2 2 3", "output": "YES" }, { "input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9...
1,511,474,630
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
62
0
YES = 'YES' NO = 'NO' def is_can_be_poured_out_in(can_count: int, cola_by_cans, cans_volumes): if can_count < 3: return YES left_volume = sum(cola_by_cans[0:2]) max1_v, max2_v = cans_volumes[0], cans_volumes[1] for left_cola, volume in zip(cola_by_cans[2:], cans_volumes[2:]): ...
Title: Greed Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he c...
```python YES = 'YES' NO = 'NO' def is_can_be_poured_out_in(can_count: int, cola_by_cans, cans_volumes): if can_count < 3: return YES left_volume = sum(cola_by_cans[0:2]) max1_v, max2_v = cans_volumes[0], cans_volumes[1] for left_cola, volume in zip(cola_by_cans[2:], cans_volumes[...
-1
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,697,787,949
2,147,483,647
Python 3
OK
TESTS
71
92
0
n=int(input()) s=0 r=[] for i in range(n): m=[int(j) for j in input().split()] s+=m[1]-m[0] r.append(s) r.sort() print(r[-1])
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 n=int(input()) s=0 r=[] for i in range(n): m=[int(j) for j in input().split()] s+=m[1]-m[0] r.append(s) r.sort() print(r[-1]) ```
3
833
A
The Meaningless Game
PROGRAMMING
1,700
[ "math", "number theory" ]
null
null
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is...
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower).
[ "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n" ]
[ "Yes\nYes\nYes\nNo\nNo\nYes\n" ]
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
500
[ { "input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "output": "Yes\nYes\nYes\nNo\nNo\nYes" }, { "input": "3\n1 1\n8 27\n1000 1331", "output": "Yes\nNo\nNo" }, { "input": "1\n12004 18012002", "output": "Yes" }, { "input": "1\n3331 11095561", "output": "Yes...
1,564,948,562
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
140
0
import math n = int(input()) for i in range(n): x, y = map(int, input().split()) cubed = int(round((x * y)**(1.0/3.0))) if cubed**3 == x * y: print('Yes') else: print('No')
Title: The Meaningless Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Th...
```python import math n = int(input()) for i in range(n): x, y = map(int, input().split()) cubed = int(round((x * y)**(1.0/3.0))) if cubed**3 == x * y: print('Yes') else: print('No') ```
0
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,592,618,297
2,147,483,647
PyPy 3
OK
TESTS
19
310
0
s = input() t = input() pos = 1 for i in t: if s[pos-1] == i: pos+=1 print(pos)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python s = input() t = input() pos = 1 for i in t: if s[pos-1] == i: pos+=1 print(pos) ```
3
35
D
Animals
PROGRAMMING
1,700
[ "dp", "greedy" ]
D. Animals
2
64
Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once. Drav...
The first input line contains integers *n* and *X* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*X*<=≤<=104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers *c**i* (1<=≤<=*c**i*<=≤<=300). Numbers in the second line are divided by a space.
Output the only number — the maximum possible amount of animals on the farm by the end of the *n*-th day given that the food was enough for everybody.
[ "3 4\n1 1 1\n", "3 6\n1 1 1\n" ]
[ "2\n", "3\n" ]
Note to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day.
2,000
[ { "input": "3 4\n1 1 1", "output": "2" }, { "input": "3 6\n1 1 1", "output": "3" }, { "input": "1 12\n1", "output": "1" }, { "input": "3 100\n1 1 1", "output": "3" }, { "input": "5 75\n1 1 1 1 1", "output": "5" }, { "input": "7 115\n1 1 1 1 1 1 1", ...
1,506,567,660
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
n,m=map(int,input().split(" ")) L=list(map(int,input().split(" "))) ct=0 at=0 for k in range(n): ac=L[k] if(at*2+ac<=m): ct+=1 at=ac+at print(ct)
Title: Animals Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he h...
```python n,m=map(int,input().split(" ")) L=list(map(int,input().split(" "))) ct=0 at=0 for k in range(n): ac=L[k] if(at*2+ac<=m): ct+=1 at=ac+at print(ct) ```
-1
900
A
Find Extra One
PROGRAMMING
800
[ "geometry", "implementation" ]
null
null
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
[ "3\n1 1\n-1 -1\n2 -1\n", "4\n1 1\n2 2\n-1 1\n-2 2\n", "3\n1 2\n2 1\n4 60\n" ]
[ "Yes", "No", "Yes" ]
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
500
[ { "input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes" }, { "input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No" }, { "input": "3\n1 2\n2 1\n4 60", "output": "Yes" }, { "input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "output": "Yes" }, { "input": "2\n1...
1,514,382,527
2,147,483,647
Python 3
OK
TESTS
71
389
13,414,400
n = int(input()) l1=[] inth=0 for i in range(n): lh=tuple(map(int, input().split())) l1.append(lh) for tup in l1: if tup[0]<0: inth += 1 if inth==1 or inth==n-1 or inth==0 or inth==n: print("yes") else: print("no")
Title: Find Extra One Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. Input Specification: The first li...
```python n = int(input()) l1=[] inth=0 for i in range(n): lh=tuple(map(int, input().split())) l1.append(lh) for tup in l1: if tup[0]<0: inth += 1 if inth==1 or inth==n-1 or inth==0 or inth==n: print("yes") else: print("no") ```
3
909
A
Generate Login
PROGRAMMING
1,000
[ "brute force", "greedy", "sortings" ]
null
null
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and ...
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
[ "harry potter\n", "tom riddle\n" ]
[ "hap\n", "tomr\n" ]
none
500
[ { "input": "harry potter", "output": "hap" }, { "input": "tom riddle", "output": "tomr" }, { "input": "a qdpinbmcrf", "output": "aq" }, { "input": "wixjzniiub ssdfodfgap", "output": "wis" }, { "input": "z z", "output": "zz" }, { "input": "ertuyivhfg v"...
1,566,323,385
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
139
0
a,b = input().split() l = [] l.append(a[0]) for each in a[1:]: if each == a[-1]: if each < b[0]: l.append(each) l.append(b[0]) break if each < b[0]: l.append(each) else: l.append(b[0]) break print(''.join(l))
Title: Generate Login Time Limit: None seconds Memory Limit: None megabytes Problem Description: The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu...
```python a,b = input().split() l = [] l.append(a[0]) for each in a[1:]: if each == a[-1]: if each < b[0]: l.append(each) l.append(b[0]) break if each < b[0]: l.append(each) else: l.append(b[0]) break print(''.join(l)) ```
0
877
A
Alex and broken contest
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ...
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n" ]
[ "NO", "YES", "NO" ]
none
500
[ { "input": "Alex_and_broken_contest", "output": "NO" }, { "input": "NikitaAndString", "output": "YES" }, { "input": "Danil_and_Olya", "output": "NO" }, { "input": "Slava____and_the_game", "output": "YES" }, { "input": "Olya_and_energy_drinks", "output": "YES" ...
1,691,999,665
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
20
61
0
# Wadea # n = input() arr = ["Danil", "Olya", "Slava", "Ann", "Nikita"] count = 0 for j in arr: if j in n: count += 1 if count == 1: print("YES") else: print("NO")
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems,...
```python # Wadea # n = input() arr = ["Danil", "Olya", "Slava", "Ann", "Nikita"] count = 0 for j in arr: if j in n: count += 1 if count == 1: print("YES") else: print("NO") ```
0
745
A
Hongcow Learns the Cyclic Shift
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ...
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
[ "abcd\n", "bbb\n", "yzyz\n" ]
[ "4\n", "1\n", "2\n" ]
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
500
[ { "input": "abcd", "output": "4" }, { "input": "bbb", "output": "1" }, { "input": "yzyz", "output": "2" }, { "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25" }, { "input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "output": "14...
1,697,175,490
2,147,483,647
PyPy 3-64
OK
TESTS
28
77
0
w = input() s = set() n = len(w) s.add(w) for i in range(n-1): w = w[1:] + w[0] s.add(w) print(len(s))
Title: Hongcow Learns the Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to m...
```python w = input() s = set() n = len(w) s.add(w) for i in range(n-1): w = w[1:] + w[0] s.add(w) print(len(s)) ```
3
980
A
Links and Pearls
PROGRAMMING
900
[ "implementation", "math" ]
null
null
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l...
The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower).
[ "-o-o--", "-o---\n", "-o---o-\n", "ooo\n" ]
[ "YES", "YES", "NO", "YES\n" ]
none
500
[ { "input": "-o-o--", "output": "YES" }, { "input": "-o---", "output": "YES" }, { "input": "-o---o-", "output": "NO" }, { "input": "ooo", "output": "YES" }, { "input": "---", "output": "YES" }, { "input": "--o-o-----o----o--oo-o-----ooo-oo---o--", "...
1,526,237,607
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
61
7,065,600
s = input() o = s.count("o") d = s.count("-") if o == 0 or d == 0 or o%d == 0: print("YES") else: print("NO")
Title: Links and Pearls Time Limit: None seconds Memory Limit: None megabytes Problem Description: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearl...
```python s = input() o = s.count("o") d = s.count("-") if o == 0 or d == 0 or o%d == 0: print("YES") else: print("NO") ```
0
59
B
Fortune Telling
PROGRAMMING
1,200
[ "implementation", "number theory" ]
B. Fortune Telling
2
256
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces a...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100), which is the number of flowers growing in the field. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) which represent the number of petals on a given *i*-th camomile.
Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower.
[ "1\n1\n", "1\n2\n", "3\n5 6 7\n" ]
[ "1\n", "0\n", "13\n" ]
none
1,000
[ { "input": "1\n1", "output": "1" }, { "input": "1\n2", "output": "0" }, { "input": "3\n5 6 7", "output": "13" }, { "input": "2\n5 7", "output": "7" }, { "input": "3\n1 2 3", "output": "5" }, { "input": "4\n4 3 1 2", "output": "9" }, { "inpu...
1,659,186,633
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
92
0
n = input() next = input() ''' e + e = e e + o = o o + o = e no o odd and no of even odd ka num - o/e even ka num - o/e o + o--> e = o good o + e = o good e + o--> e = e e + e = e if odd num ki enty even - sub the least one out of out them ''' o = 0 e = 0 sum = 0 odd = [] l = next.split(' ') #print(l) for i ...
Title: Fortune Telling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her han...
```python n = input() next = input() ''' e + e = e e + o = o o + o = e no o odd and no of even odd ka num - o/e even ka num - o/e o + o--> e = o good o + e = o good e + o--> e = e e + e = e if odd num ki enty even - sub the least one out of out them ''' o = 0 e = 0 sum = 0 odd = [] l = next.split(' ') #print...
0
1,010
A
Fly
PROGRAMMING
1,500
[ "binary search", "math" ]
null
null
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$. Flight from $x$ to $y$ consists ...
The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets. The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload. The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted...
If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel. The answer will be considered correct...
[ "2\n12\n11 8\n7 5\n", "3\n1\n1 4 1\n2 5 3\n", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n" ]
[ "10.0000000000\n", "-1\n", "85.4800000000\n" ]
Let's consider the first example. Initially, the mass of a rocket with fuel is $22$ tons. - At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fu...
500
[ { "input": "2\n12\n11 8\n7 5", "output": "10.0000000000" }, { "input": "3\n1\n1 4 1\n2 5 3", "output": "-1" }, { "input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000" }, { "input": "3\n3\n1 2 1\n2 2 2", "output": "-1" }, { "input": "4\n4\n2 3 2 2\n2...
1,593,092,630
2,147,483,647
PyPy 3
OK
TESTS
76
187
22,118,400
from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd from collections import deque def check(t,m): x=m+t for i in range(1,n+1): x-=x/a[i] x-=x/b[i] if x<m: return False return True n=int(input()) m=int(input()) a=list(map(int,input().split())) ...
Title: Fly Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will ...
```python from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd from collections import deque def check(t,m): x=m+t for i in range(1,n+1): x-=x/a[i] x-=x/b[i] if x<m: return False return True n=int(input()) m=int(input()) a=list(map(int,input()....
3
859
B
Lazy Security Guard
PROGRAMMING
1,000
[ "brute force", "geometry", "math" ]
null
null
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite ...
Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route.
Print the minimum perimeter that can be achieved.
[ "4\n", "11\n", "22\n" ]
[ "8\n", "14\n", "20\n" ]
Here are some possible shapes for the examples: <img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/>
750
[ { "input": "4", "output": "8" }, { "input": "11", "output": "14" }, { "input": "22", "output": "20" }, { "input": "3", "output": "8" }, { "input": "1024", "output": "128" }, { "input": "101", "output": "42" }, { "input": "30", "output":...
1,661,331,824
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
def minimum_possible_perimeter(n): sqrt = int(math.sqrt(n)) perfectSquare = sqrt ** 2 if perfectSquare == n: return n*2 elif (sqrt*(sqrt+1)>=n): return (4*sqrt+2) elif ((sqrt+1)*(sqrt+1)>=n): return (4*sqrt+4) return 0
Title: Lazy Security Guard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is...
```python def minimum_possible_perimeter(n): sqrt = int(math.sqrt(n)) perfectSquare = sqrt ** 2 if perfectSquare == n: return n*2 elif (sqrt*(sqrt+1)>=n): return (4*sqrt+2) elif ((sqrt+1)*(sqrt+1)>=n): return (4*sqrt+4) return 0 ```
0
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,578,828,424
2,147,483,647
Python 3
OK
TESTS
45
248
0
a=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53] x,y=map(int,input().split()) b=a.index(x) if a[b+1]==y: print('YES') else: print('NO')
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python a=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53] x,y=map(int,input().split()) b=a.index(x) if a[b+1]==y: print('YES') else: print('NO') ```
3.938
993
D
Compute Power
PROGRAMMING
2,500
[ "binary search", "dp", "greedy" ]
null
null
You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume. You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up to one task at a time, and no more than two tasks total. The first task ca...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=50) — the number of tasks. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=108), where *a**i* represents the amount of power required for the *i*-th task. The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=...
Print a single integer value — the lowest threshold for which it is possible to assign all tasks in such a way that the system will not blow up after the first round of computation, multiplied by 1000 and rounded up.
[ "6\n8 10 9 9 8 10\n1 1 1 1 1 1\n", "6\n8 10 9 9 8 10\n1 10 5 5 1 10\n" ]
[ "9000\n", "1160\n" ]
In the first example the best strategy is to run each task on a separate computer, getting average compute per processor during the first round equal to 9. In the second task it is best to run tasks with compute 10 and 9 on one computer, tasks with compute 10 and 8 on another, and tasks with compute 9 and 8 on the las...
1,500
[ { "input": "6\n8 10 9 9 8 10\n1 1 1 1 1 1", "output": "9000" }, { "input": "6\n8 10 9 9 8 10\n1 10 5 5 1 10", "output": "1160" }, { "input": "1\n1\n100", "output": "10" }, { "input": "50\n83 43 73 75 11 53 6 43 67 38 83 12 70 27 60 13 9 79 61 30 29 71 10 11 95 87 26 26 19 99 ...
1,692,499,639
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1692499639.4148047")# 1692499639.414821
Title: Compute Power Time Limit: None seconds Memory Limit: None megabytes Problem Description: You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume. You have sufficient number of analog computers, each with enough processors for any task. Each...
```python print("_RANDOM_GUESS_1692499639.4148047")# 1692499639.414821 ```
0
611
A
New Year and Days
PROGRAMMING
900
[ "implementation" ]
null
null
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016. Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ...
The only line of the input is in one of the following two formats: - "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
Print one integer — the number of candies Limak will save in the year 2016.
[ "4 of week\n", "30 of month\n" ]
[ "52\n", "11\n" ]
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday. In the first sample Limak wants to sav...
500
[ { "input": "4 of week", "output": "52" }, { "input": "30 of month", "output": "11" }, { "input": "17 of month", "output": "12" }, { "input": "31 of month", "output": "7" }, { "input": "6 of week", "output": "53" }, { "input": "1 of week", "output":...
1,675,696,693
2,147,483,647
Python 3
OK
TESTS
38
46
0
# LUOGU_RID: 101606798 t = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] a = input().split() if a[2] == 'month': print(sum(x >= int(a[0]) for x in t)) else: print(53 if int(a[0]) in (5, 6) else 52)
Title: New Year and Days Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye...
```python # LUOGU_RID: 101606798 t = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] a = input().split() if a[2] == 'month': print(sum(x >= int(a[0]) for x in t)) else: print(53 if int(a[0]) in (5, 6) else 52) ```
3
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,688,153,393
2,147,483,647
Python 3
OK
TESTS
27
46
0
# Read the input line line = input() # Remove the opening and closing brackets line = line[1:-1] # Split the line into individual letters letters = line.split(", ") # Remove leading/trailing whitespace from each letter letters = [letter.strip() for letter in letters] # Convert the list to a set to remov...
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python # Read the input line line = input() # Remove the opening and closing brackets line = line[1:-1] # Split the line into individual letters letters = line.split(", ") # Remove leading/trailing whitespace from each letter letters = [letter.strip() for letter in letters] # Convert the list to a se...
3
780
A
Andryusha and Socks
PROGRAMMING
800
[ "implementation" ]
null
null
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ...
Print single integer — the maximum number of socks that were on the table at the same time.
[ "1\n1 1\n", "3\n2 1 1 3 2 3\n" ]
[ "1\n", "2\n" ]
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - ...
500
[ { "input": "1\n1 1", "output": "1" }, { "input": "3\n2 1 1 3 2 3", "output": "2" }, { "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5" }, { "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6" }, { "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ...
1,583,520,101
2,147,483,647
PyPy 3
OK
TESTS
56
280
15,872,000
x=int(input());a=list(map(int,input().split()));p=0;mx=0;y=[0 for i in range(x)] for i in range(x*2): y[a[i]-1]+=1 if y[a[i]-1]==2: p-=1 else: p+=1 mx=max(mx,p) print(mx)
Title: Andryusha and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere...
```python x=int(input());a=list(map(int,input().split()));p=0;mx=0;y=[0 for i in range(x)] for i in range(x*2): y[a[i]-1]+=1 if y[a[i]-1]==2: p-=1 else: p+=1 mx=max(mx,p) print(mx) ```
3
625
B
War of the Corporations
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "strings" ]
null
null
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000. This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine...
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
[ "intellect\ntell\n", "google\napple\n", "sirisiri\nsir\n" ]
[ "1", "0", "2" ]
In the first sample AI's name may be replaced with "int#llect". In the second sample Gogol can just keep things as they are. In the third sample one of the new possible names of AI may be "s#ris#ri".
750
[ { "input": "intellect\ntell", "output": "1" }, { "input": "google\napple", "output": "0" }, { "input": "sirisiri\nsir", "output": "2" }, { "input": "sirisiri\nsiri", "output": "2" }, { "input": "aaaaaaa\naaaa", "output": "1" }, { "input": "bbbbbb\nbb",...
1,599,103,808
2,147,483,647
Python 3
OK
TESTS
56
140
307,200
s1=input() s2=input() l1=len(s1) c=0 i=0 l2=len(s2) while i<=len(s1)-len(s2): if s1[i:i+l2]==s2: i=i+l2 c+=1 continue i+=1 print(c)
Title: War of the Corporations Time Limit: None seconds Memory Limit: None megabytes Problem Description: A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Last...
```python s1=input() s2=input() l1=len(s1) c=0 i=0 l2=len(s2) while i<=len(s1)-len(s2): if s1[i:i+l2]==s2: i=i+l2 c+=1 continue i+=1 print(c) ```
3
439
B
Devu, the Dumb Guy
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other ...
The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105).
Output a single integer representing the answer to the problem.
[ "2 3\n4 1\n", "4 2\n5 1 2 1\n", "3 3\n1 1 1\n" ]
[ "11\n", "10\n", "6\n" ]
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ...
1,000
[ { "input": "2 3\n4 1", "output": "11" }, { "input": "4 2\n5 1 2 1", "output": "10" }, { "input": "3 3\n1 1 1", "output": "6" }, { "input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "output": "65" }, { "input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3...
1,545,758,627
2,147,483,647
Python 3
OK
TESTS
31
233
7,372,800
n, x = map(int, input().split()) a = list(map(int, input().split())) a.sort() counter = 0 for i in a: counter += i*x if x > 1: x -= 1 print(counter)
Title: Devu, the Dumb Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co...
```python n, x = map(int, input().split()) a = list(map(int, input().split())) a.sort() counter = 0 for i in a: counter += i*x if x > 1: x -= 1 print(counter) ```
3
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,601,619,550
2,147,483,647
PyPy 3
OK
TESTS
33
140
0
s1 = str(input()) s2 = str(input()) s3 = str(input()) l1 = s1.split() l2 = s2.split() l3 = s3.split() v1 = int(l1[0]) + int(l1[1]) + int(l2[0]) v2 = int(l1[0]) + int(l1[1]) + int(l1[2]) + int(l2[1]) v3 = int(l1[2]) + int(l1[1]) + int(l2[2]) v4 = int(l1[0]) + int(l2[0]) + int(l3[0]) + int(l2[1]) v5 = i...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python s1 = str(input()) s2 = str(input()) s3 = str(input()) l1 = s1.split() l2 = s2.split() l3 = s3.split() v1 = int(l1[0]) + int(l1[1]) + int(l2[0]) v2 = int(l1[0]) + int(l1[1]) + int(l1[2]) + int(l2[1]) v3 = int(l1[2]) + int(l1[1]) + int(l2[2]) v4 = int(l1[0]) + int(l2[0]) + int(l3[0]) + int(l2[1]...
3
571
B
Minimization
PROGRAMMING
2,000
[ "dp", "greedy", "sortings" ]
null
null
You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*. You need to permute the array elements so that value
The first line contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=*min*(5000,<=*n*<=-<=1)). The second line contains *n* integers *A*[1],<=*A*[2],<=...,<=*A*[*n*] (<=-<=109<=≤<=*A*[*i*]<=≤<=109), separate by spaces — elements of the array *A*.
Print the minimum possible value of the sum described in the statement.
[ "3 2\n1 2 4\n", "5 2\n3 -5 3 -5 3\n", "6 3\n4 3 4 3 2 5\n" ]
[ "1\n", "0\n", "3\n" ]
In the first test one of the optimal permutations is 1 4 2. In the second test the initial order is optimal. In the third test one of the optimal permutations is 2 3 4 4 3 5.
1,250
[ { "input": "3 2\n1 2 4", "output": "1" }, { "input": "5 2\n3 -5 3 -5 3", "output": "0" }, { "input": "6 3\n4 3 4 3 2 5", "output": "3" }, { "input": "2 1\n1 100", "output": "99" }, { "input": "4 3\n1 2 4 8", "output": "1" }, { "input": "5 2\n1 2 8 8 16...
1,440,518,000
3,200
PyPy 3
OK
TESTS
52
701
26,316,800
def solve(n, k, As): As.sort() m, r = divmod(n, k) dp = [0] * (r + 1) for i in range(1, k): im = i * m new_dp = [0] * (r + 1) new_dp[0] = dp[0] + As[im] - As[im - 1] for h in range(1, min(i, r) + 1): new_dp[h] = max(dp[h], dp[h - 1]) + As[im + h] - As...
Title: Minimization Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*. You need to permute the array elements so that value Input Specification: The first line contai...
```python def solve(n, k, As): As.sort() m, r = divmod(n, k) dp = [0] * (r + 1) for i in range(1, k): im = i * m new_dp = [0] * (r + 1) new_dp[0] = dp[0] + As[im] - As[im - 1] for h in range(1, min(i, r) + 1): new_dp[h] = max(dp[h], dp[h - 1]) + As[im...
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,695,905,076
2,147,483,647
Python 3
OK
TESTS
50
46
0
n,m=list(map(int,input().split())) s="" for x in range(n): list1=input() s+=list1 s=s.replace(" ","") if "C" in s or "M" in s or "Y" in s: print("#Color") else: print("#Black&White")
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python n,m=list(map(int,input().split())) s="" for x in range(n): list1=input() s+=list1 s=s.replace(" ","") if "C" in s or "M" in s or "Y" in s: print("#Color") else: print("#Black&White") ```
3
748
B
Santa Claus and Keyboard Check
PROGRAMMING
1,500
[ "implementation", "strings" ]
null
null
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. ...
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k...
[ "helloworld\nehoolwlroz\n", "hastalavistababy\nhastalavistababy\n", "merrychristmas\nchristmasmerry\n" ]
[ "3\nh e\nl o\nd z\n", "0\n", "-1\n" ]
none
1,000
[ { "input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z" }, { "input": "hastalavistababy\nhastalavistababy", "output": "0" }, { "input": "merrychristmas\nchristmasmerry", "output": "-1" }, { "input": "kusyvdgccw\nkusyvdgccw", "output": "0" }, { "input": "...
1,593,452,073
2,147,483,647
Python 3
OK
TESTS
86
109
6,963,200
s = input() t = input() w1 = set() w2=set() fifa=0 for i in range(len(s)): l1 = min(s[i],t[i]) l2 = max(s[i], t[i]) if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1: fifa=-1 break else: w2.add(s[i]) w2.add(t[i]) w1.add((l1, l2)) result=[0]*len(s...
Title: Santa Claus and Keyboard Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each ke...
```python s = input() t = input() w1 = set() w2=set() fifa=0 for i in range(len(s)): l1 = min(s[i],t[i]) l2 = max(s[i], t[i]) if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1: fifa=-1 break else: w2.add(s[i]) w2.add(t[i]) w1.add((l1, l2)) result...
3
0
none
none
none
0
[ "none" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. ...
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
0
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { ...
1,510,592,953
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
62
0
arr = sorted(list(map(int,input().split()))) one = arr[0]+arr[5] two = arr[1]+arr[4] if one >= two: one+=min(arr[2],arr[3]) two+=max(arr[2],arr[3]) else: one+=max(arr[2],arr[3]) two+=min(arr[2],arr[3]) if one==two: print("YES") else : print ("NO")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exac...
```python arr = sorted(list(map(int,input().split()))) one = arr[0]+arr[5] two = arr[1]+arr[4] if one >= two: one+=min(arr[2],arr[3]) two+=max(arr[2],arr[3]) else: one+=max(arr[2],arr[3]) two+=min(arr[2],arr[3]) if one==two: print("YES") else : print ("NO") ```
0
463
B
Caisa and Pylons
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
[ "5\n3 4 3 2 4\n", "3\n4 4 4\n" ]
[ "4\n", "4\n" ]
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
1,000
[ { "input": "5\n3 4 3 2 4", "output": "4" }, { "input": "3\n4 4 4", "output": "4" }, { "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20...
1,696,076,254
2,147,483,647
Python 3
OK
TESTS
49
62
13,619,200
n = int(input()) l1 = list(map(int,input().split())) c = max(i for i in l1) print(c)
Title: Caisa and Pylons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0...
```python n = int(input()) l1 = list(map(int,input().split())) c = max(i for i in l1) print(c) ```
3
106
B
Choosing Laptop
PROGRAMMING
1,000
[ "brute force", "implementation" ]
B. Choosing Laptop
2
256
Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those propertie...
The first line contains number *n* (1<=≤<=*n*<=≤<=100). Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides, - *speed*, *ram*, *hdd* and *cost* are integers - 1000<=≤<=*speed*<=≤<=4200 is the processor's speed in megahertz - 256<=≤<=*ram*<=≤<=4096 the RAM volume in megabytes - 1...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data.
[ "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n" ]
[ "4" ]
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
1,000
[ { "input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4" }, { "input": "2\n1500 500 50 755\n1600 600 80 700", "output": "2" }, { "input": "2\n1500 512 50 567\n1600 400 70 789", "output": "1" }, { "input": "4\n10...
1,644,909,884
2,147,483,647
PyPy 3
OK
TESTS
55
154
1,536,000
import sys input = sys.stdin.readline n = int(input()) data = [list(map(int, input().split())) + [i + 1] for i in range(n)] sdata = sorted(data, key=lambda x:x[3]) ans = sdata[-1][4] for i in range(n - 1): flag = True for j in range(i + 1, n): tmp = False for k in range(3): ...
Title: Choosing Laptop Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in ...
```python import sys input = sys.stdin.readline n = int(input()) data = [list(map(int, input().split())) + [i + 1] for i in range(n)] sdata = sorted(data, key=lambda x:x[3]) ans = sdata[-1][4] for i in range(n - 1): flag = True for j in range(i + 1, n): tmp = False for k in range...
3.958639
234
A
Lefthanders and Righthanders
PROGRAMMING
1,200
[ "implementation" ]
null
null
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*. But Vasily Petrov did not like the way the chi...
The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander.
Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space...
[ "6\nLLRLLL\n", "4\nRRLL\n" ]
[ "1 4\n2 5\n6 3\n", "3 1\n4 2\n" ]
none
0
[ { "input": "6\nLLRLLL", "output": "1 4\n2 5\n6 3" }, { "input": "4\nRRLL", "output": "3 1\n4 2" }, { "input": "4\nLLRR", "output": "1 3\n2 4" }, { "input": "6\nRLLRRL", "output": "1 4\n2 5\n3 6" }, { "input": "8\nLRLRLLLR", "output": "1 5\n6 2\n3 7\n4 8" }, ...
1,620,493,617
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
6,758,400
a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10
Title: Lefthanders and Righthanders Time Limit: None seconds Memory Limit: None megabytes Problem Description: One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t...
```python a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 a=10 ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,639,912,743
2,147,483,647
Python 3
OK
TESTS
40
62
0
def main(): s = input() a = ["h","e","l","l","o"] counter = 0 flag = 0 for i in a: x = s.find(i,counter) if x == -1: flag = 1 break else: counter = x + 1 print("YES" if flag == 0 else "NO") main()
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python def main(): s = input() a = ["h","e","l","l","o"] counter = 0 flag = 0 for i in a: x = s.find(i,counter) if x == -1: flag = 1 break else: counter = x + 1 print("YES" if flag == 0 else "NO") main() ```
3.969
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,672,165,257
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
a=[] b,c,d=map(int,input().split()) a.append(b) a.append(c) a.append(d) min=abs(b-c)+abs(b-d) for i in range(min(a),max(a)): if (abs(i-b)+abs(i-c)+abs(i-d))<min: min=abs(i-b)+abs(i-c)+abs(i-d) print(min)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python a=[] b,c,d=map(int,input().split()) a.append(b) a.append(c) a.append(d) min=abs(b-c)+abs(b-d) for i in range(min(a),max(a)): if (abs(i-b)+abs(i-c)+abs(i-d))<min: min=abs(i-b)+abs(i-c)+abs(i-d) print(min) ```
-1
722
B
Verse Pattern
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowel...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text. The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern. Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guarant...
If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
[ "3\n2 2 3\nintel\ncode\nch allenge\n", "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n", "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, one can split words into syllables in the following way: Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.
500
[ { "input": "3\n2 2 3\nintel\ncode\nch allenge", "output": "YES" }, { "input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz", "output": "NO" }, { "input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageo...
1,633,796,952
2,147,483,647
Python 3
OK
TESTS
54
62
6,963,200
vowels = ['a', 'e', 'i', 'o', 'u', 'y'] def verse_pattern(n: int, s: str) -> bool: count = 0 for i in range(6): count += s.count(vowels[i]) return n == count # Inputs result = True n = int(input()) p = list(map(lambda i: int(i), input().split())) for i in range(n): text = input() if (not verse_patte...
Title: Verse Pattern Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary num...
```python vowels = ['a', 'e', 'i', 'o', 'u', 'y'] def verse_pattern(n: int, s: str) -> bool: count = 0 for i in range(6): count += s.count(vowels[i]) return n == count # Inputs result = True n = int(input()) p = list(map(lambda i: int(i), input().split())) for i in range(n): text = input() if (not v...
3
0
none
none
none
0
[ "none" ]
null
null
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world. There is at ...
The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government. The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**...
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
[ "4 1 2\n1 3\n1 2\n", "3 3 1\n2\n1 2\n1 3\n2 3\n" ]
[ "2\n", "0\n" ]
For the first sample test, the graph looks like this: For the second sample test, the graph looks like this:
0
[ { "input": "4 1 2\n1 3\n1 2", "output": "2" }, { "input": "3 3 1\n2\n1 2\n1 3\n2 3", "output": "0" }, { "input": "10 3 2\n1 10\n1 2\n1 3\n4 5", "output": "33" }, { "input": "1 0 1\n1", "output": "0" }, { "input": "1000 0 1\n72", "output": "499500" }, { ...
1,481,999,373
6,873
Python 3
RUNTIME_ERROR
PRETESTS
0
46
4,812,800
def dfs(v): used[v] = True ans[-1].append(v) for elem in g[v]: if not used[elem]: dfs(elem) n, m = map(int, input().split()) cap = list(map(int, input().split())) used = [False for i in range(n)] ans = [] g = [[] for i in range(n)] ansi = 0 for i in range(m): s, f = ma...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the no...
```python def dfs(v): used[v] = True ans[-1].append(v) for elem in g[v]: if not used[elem]: dfs(elem) n, m = map(int, input().split()) cap = list(map(int, input().split())) used = [False for i in range(n)] ans = [] g = [[] for i in range(n)] ansi = 0 for i in range(m): ...
-1
710
A
King Moves
PROGRAMMING
800
[ "implementation" ]
null
null
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik...
The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.
Print the only integer *x* — the number of moves permitted for the king.
[ "e4\n" ]
[ "8\n" ]
none
0
[ { "input": "e4", "output": "8" }, { "input": "a1", "output": "3" }, { "input": "h8", "output": "3" }, { "input": "a4", "output": "5" }, { "input": "g7", "output": "8" }, { "input": "e1", "output": "5" }, { "input": "b2", "output": "8" ...
1,585,080,311
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
139
0
t=input() three=['a1','a8','h1','h8'] five=['a3','a4','a5','a6','h3','h4','h5','h6','c8','d8','e8','f8','c1','d1','e1','f1'] four =['a2','a7','h2','h7','b1','g1','b8','g8'] if t in three: print(3) elif t in five: print(5) elif t in four: print(4) else: print(8)
Title: King Moves Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check...
```python t=input() three=['a1','a8','h1','h8'] five=['a3','a4','a5','a6','h3','h4','h5','h6','c8','d8','e8','f8','c1','d1','e1','f1'] four =['a2','a7','h2','h7','b1','g1','b8','g8'] if t in three: print(3) elif t in five: print(5) elif t in four: print(4) else: print(8) ```
0
913
B
Christmas Spruce
PROGRAMMING
1,200
[ "implementation", "trees" ]
null
null
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a ...
The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*). Vertex 1 is the root. It's guaranteed that the root ha...
Print "Yes" if the tree is a spruce and "No" otherwise.
[ "4\n1\n1\n1\n", "7\n1\n1\n1\n2\n2\n2\n", "8\n1\n1\n1\n1\n3\n3\n3\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
The first example: <img class="tex-graphics" src="https://espresso.codeforces.com/8dd976913226df83d535dfa66193f5525f8471bc.png" style="max-width: 100.0%;max-height: 100.0%;"/> The second example: <img class="tex-graphics" src="https://espresso.codeforces.com/44dad5804f5290a2e026c9c41a15151562df8682.png" style="max-w...
750
[ { "input": "4\n1\n1\n1", "output": "Yes" }, { "input": "7\n1\n1\n1\n2\n2\n2", "output": "No" }, { "input": "8\n1\n1\n1\n1\n3\n3\n3", "output": "Yes" }, { "input": "3\n1\n1", "output": "No" }, { "input": "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10", "output": "N...
1,691,327,411
2,147,483,647
Python 3
OK
TESTS
31
46
0
n=int(input()) vert={} for i in range(n-1): x=int(input()) if x not in vert: vert[x]=[i+2] else: vert[x].append(i+2) f=False for i in vert: neww=0 for j in vert[i]: if j in vert: neww+=1 if len(vert[i])-neww<3: f=True break if f: print('No') else: print('Yes')
Title: Christmas Spruce Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there ex...
```python n=int(input()) vert={} for i in range(n-1): x=int(input()) if x not in vert: vert[x]=[i+2] else: vert[x].append(i+2) f=False for i in vert: neww=0 for j in vert[i]: if j in vert: neww+=1 if len(vert[i])-neww<3: f=True break if f: print('No') else: print('Yes') ```
3
187
A
Permutations
PROGRAMMING
1,500
[ "greedy" ]
null
null
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through *n* and is asked to convert the first one to the second. In one move he can remove the last number from the pe...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the quantity of the numbers in the both given permutations. Next line contains *n* space-separated integers — the first permutation. Each number between 1 to *n* will appear in the permutation exactly once. Next line describe the second permutatio...
Print a single integer denoting the minimum number of moves required to convert the first permutation to the second.
[ "3\n3 2 1\n1 2 3\n", "5\n1 2 3 4 5\n1 5 2 3 4\n", "5\n1 5 2 3 4\n1 2 3 4 5\n" ]
[ "2\n", "1\n", "3\n" ]
In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: - 1 5 2 3 4 - 1 4 5 2 3 - 1 3 4 5 2 ...
500
[ { "input": "3\n3 2 1\n1 2 3", "output": "2" }, { "input": "5\n1 2 3 4 5\n1 5 2 3 4", "output": "1" }, { "input": "5\n1 5 2 3 4\n1 2 3 4 5", "output": "3" }, { "input": "1\n1\n1", "output": "0" }, { "input": "7\n6 1 7 3 4 5 2\n6 1 7 3 4 5 2", "output": "0" },...
1,447,951,716
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
92
0
n = int(input()) permutation = list(map(int, input().split())) target = list(map(int, input().split())) cont = 0 for i in range(0, n): if (permutation[i] != target[i]): cont += 1 for j in range(i + 1, n): if (permutation[j] == target[i]): aux = permutation[0:i] aux.append(permutation[j]) aux.extend(...
Title: Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through *n* and is a...
```python n = int(input()) permutation = list(map(int, input().split())) target = list(map(int, input().split())) cont = 0 for i in range(0, n): if (permutation[i] != target[i]): cont += 1 for j in range(i + 1, n): if (permutation[j] == target[i]): aux = permutation[0:i] aux.append(permutation[j]) a...
0
841
A
Generous Kefa
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his...
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends. Next line contains string *s* — colors of baloons.
Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary.
[ "4 2\naabb\n", "6 3\naacaab\n" ]
[ "YES\n", "NO\n" ]
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
500
[ { "input": "4 2\naabb", "output": "YES" }, { "input": "6 3\naacaab", "output": "NO" }, { "input": "2 2\nlu", "output": "YES" }, { "input": "5 3\novvoo", "output": "YES" }, { "input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf", "output": "YES" }, { "...
1,594,335,786
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
171
22,323,200
l1 = [int(x) for x in input().split()] n = l1[1] l2 = list(input()) for x in set(l2): if x.count(l2)>n: done=1 break if done: print("NO") else: print("YES")
Title: Generous Kefa Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same colo...
```python l1 = [int(x) for x in input().split()] n = l1[1] l2 = list(input()) for x in set(l2): if x.count(l2)>n: done=1 break if done: print("NO") else: print("YES") ```
-1
292
B
Network Topology
PROGRAMMING
1,200
[ "graphs", "implementation" ]
null
null
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them...
The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*...
In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo...
[ "4 3\n1 2\n2 3\n3 4\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "4 3\n1 2\n1 3\n1 4\n", "4 4\n1 2\n2 3\n3 1\n1 4\n" ]
[ "bus topology\n", "ring topology\n", "star topology\n", "unknown topology\n" ]
none
1,000
[ { "input": "4 3\n1 2\n2 3\n3 4", "output": "bus topology" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "ring topology" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "star topology" }, { "input": "4 4\n1 2\n2 3\n3 1\n1 4", "output": "unknown topology" }, { "i...
1,614,814,225
2,147,483,647
PyPy 3
OK
TESTS
45
1,622
8,499,200
n, m = map(int, input().split()) counter = [0]*n for i in range(m): x, y = map(int, input().split()) counter[x-1] += 1 counter[y-1] += 1 #check bus flag = 0 c1 = c2 = 0 for i in range(n): if(counter[i]==1): c1+=1 elif(counter[i]==2): c2+=1 if(c1==2 and c2==n-2): ...
Title: Network Topology Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in...
```python n, m = map(int, input().split()) counter = [0]*n for i in range(m): x, y = map(int, input().split()) counter[x-1] += 1 counter[y-1] += 1 #check bus flag = 0 c1 = c2 = 0 for i in range(n): if(counter[i]==1): c1+=1 elif(counter[i]==2): c2+=1 if(c1==2 and c2==n...
3
888
A
Local Extrema
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=&gt;<=*...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*.
Print the number of local extrema in the given array.
[ "3\n1 2 3\n", "4\n1 5 2 5\n" ]
[ "0\n", "2\n" ]
none
0
[ { "input": "3\n1 2 3", "output": "0" }, { "input": "4\n1 5 2 5", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "1\n548", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n3 2 3", "output": "1" }, { "inp...
1,519,297,452
2,147,483,647
Python 3
OK
TESTS
14
62
5,632,000
import math from sys import stdin number=int(stdin.readline()) string=stdin.readline().strip().split() output=0 for i in range(1, number-1): if int(string[i])<int(string[i-1]) and int(string[i])<int(string[i+1]): output+=1 if int(string[i])>int(string[i-1]) and int(string[i])>int(string[i+1]): ...
Title: Local Extrema Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element c...
```python import math from sys import stdin number=int(stdin.readline()) string=stdin.readline().strip().split() output=0 for i in range(1, number-1): if int(string[i])<int(string[i-1]) and int(string[i])<int(string[i+1]): output+=1 if int(string[i])>int(string[i-1]) and int(string[i])>int(strin...
3
691
A
Fashion in Berland
PROGRAMMING
1,000
[ "implementation" ]
null
null
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fast...
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
[ "3\n1 0 1\n", "3\n1 0 0\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 0 1", "output": "YES" }, { "input": "3\n1 0 0", "output": "NO" }, { "input": "3\n1 1 0", "output": "YES" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n0 0 1", "output": "NO" }, { "input": "3\n0 0 0", "output": "NO" }...
1,546,750,339
2,147,483,647
Python 3
OK
TESTS
83
109
0
x = int(input()) y = list(map(int, input().split(' '))) if (y.count(1) == x-1 or y == [1]) and y != [0]: print("YES") else: print("NO")
Title: Fashion in Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,...
```python x = int(input()) y = list(map(int, input().split(' '))) if (y.count(1) == x-1 or y == [1]) and y != [0]: print("YES") else: print("NO") ```
3
299
B
Ksusha the Squirrel
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ...
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters e...
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
[ "2 1\n..\n", "5 2\n.#.#.\n", "7 3\n.#.###.\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
1,000
[ { "input": "2 1\n..", "output": "YES" }, { "input": "5 2\n.#.#.", "output": "YES" }, { "input": "7 3\n.#.###.", "output": "NO" }, { "input": "2 200\n..", "output": "YES" }, { "input": "2 1\n..", "output": "YES" }, { "input": "2 2\n..", "output": "Y...
1,682,125,219
2,147,483,647
Python 3
OK
TESTS
33
248
1,024,000
n, k = (int(i) for i in input().split()) s = input() ma = 0 for i, c in enumerate(s): if i > ma: break ma = i + k if c == "." else ma res = "YES" if ma >= n - 1 else "NO" print(res)
Title: Ksusha the Squirrel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to t...
```python n, k = (int(i) for i in input().split()) s = input() ma = 0 for i, c in enumerate(s): if i > ma: break ma = i + k if c == "." else ma res = "YES" if ma >= n - 1 else "NO" print(res) ```
3
288
E
Polo the Penguin and Lucky Numbers
PROGRAMMING
2,800
[ "dp", "implementation", "math" ]
null
null
Everybody knows that lucky numbers are positive integers that contain only lucky digits 4 and 7 in their decimal representation. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Polo the Penguin have two positive integers *l* and *r* (*l*<=&lt;<=*r*), both of them are lucky numbers. Moreover, their le...
The first line contains a positive integer *l*, and the second line contains a positive integer *r* (1<=≤<=*l*<=&lt;<=*r*<=≤<=10100000). The numbers are given without any leading zeroes. It is guaranteed that the lengths of the given numbers are equal to each other and that both of them are lucky numbers.
In the single line print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
[ "4\n7\n", "474\n777\n" ]
[ "28\n", "2316330\n" ]
none
2,500
[ { "input": "4\n7", "output": "28" }, { "input": "474\n777", "output": "2316330" }, { "input": "44\n77", "output": "11244" }, { "input": "444\n777", "output": "2726676" }, { "input": "444\n477", "output": "636444" }, { "input": "444\n744", "output":...
1,695,789,036
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
9
122
31,027,200
number1 = int(input()) number2 = int(input()) list_number = [] buffer = 0 for number in range(number1, number2+1): if "0" in str(number): continue elif "1" in str(number): continue elif "2" in str(number): continue elif "3" in str(number): continue el...
Title: Polo the Penguin and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Everybody knows that lucky numbers are positive integers that contain only lucky digits 4 and 7 in their decimal representation. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Polo...
```python number1 = int(input()) number2 = int(input()) list_number = [] buffer = 0 for number in range(number1, number2+1): if "0" in str(number): continue elif "1" in str(number): continue elif "2" in str(number): continue elif "3" in str(number): contin...
0
424
C
Magic Formulas
PROGRAMMING
1,600
[ "math" ]
null
null
People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas: Here, "mod" means the operation of taking the residue after dividing. The expression means applying ...
The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=106). The next line contains *n* integers: *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=2·109).
The only line of output should contain a single integer — the value of *Q*.
[ "3\n1 2 3\n" ]
[ "3\n" ]
none
1,500
[ { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n0", "output": "0" }, { "input": "2\n65535 0", "output": "65534" }, { "input": "10\n1356106972 165139648 978829595 410669403 873711167 287346624 117863440 228957745 835903650 1575323015", "output": "948506286" }, {...
1,478,551,951
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
n = int(input()) p = [0]+[int(i) for i in input().split(' ')] def f(): x = dict() q = 0 c = dict() x[0] = 0 for i in range(1, n+1): x[i] = x[i-1]^i for i in range(1, n+1): if i%2==0: c[i] = p[i]^x[n] else: c[i] = p[i]^x[i-1]^x[n] for i in range(1, n+1): ...
Title: Magic Formulas Time Limit: None seconds Memory Limit: None megabytes Problem Description: People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas: He...
```python n = int(input()) p = [0]+[int(i) for i in input().split(' ')] def f(): x = dict() q = 0 c = dict() x[0] = 0 for i in range(1, n+1): x[i] = x[i-1]^i for i in range(1, n+1): if i%2==0: c[i] = p[i]^x[n] else: c[i] = p[i]^x[i-1]^x[n] for i in range...
0
869
B
The Eternal Immortality
PROGRAMMING
1,100
[ "math" ]
null
null
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno...
The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018).
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
[ "2 4\n", "0 10\n", "107 109\n" ]
[ "2\n", "0\n", "2\n" ]
In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2; In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso...
1,000
[ { "input": "2 4", "output": "2" }, { "input": "0 10", "output": "0" }, { "input": "107 109", "output": "2" }, { "input": "10 13", "output": "6" }, { "input": "998244355 998244359", "output": "4" }, { "input": "999999999000000000 1000000000000000000", ...
1,697,630,778
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
a, b = map(int, input().split()) # If a and b are the same, there's no number between them. if a == b: print(0) else: # Calculate the number of numbers that end with different digits. # This can be done by taking the product of the last digit of 'a' and 'b', # and then subtracting 'a' from 'b'....
Title: The Eternal Immortality Time Limit: None seconds Memory Limit: None megabytes Problem Description: Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like...
```python a, b = map(int, input().split()) # If a and b are the same, there's no number between them. if a == b: print(0) else: # Calculate the number of numbers that end with different digits. # This can be done by taking the product of the last digit of 'a' and 'b', # and then subtracting 'a'...
0
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of int...
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10"...
1,657,528,749
2,147,483,647
Python 3
OK
TESTS
54
92
0
from math import sqrt n, m = map(int, input().split()) m1 = max(m, n) c1 = int(sqrt(m1)) d1 = m1 - c1 ** 2 if d1 ** 2 + c1 == min(m, n): c = 1 while True: c1 -= 1 d1 = m1 - c1 ** 2 if d1 ** 2 + c1 == min(m, n): c += 1 else: break print(...
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi...
```python from math import sqrt n, m = map(int, input().split()) m1 = max(m, n) c1 = int(sqrt(m1)) d1 = m1 - c1 ** 2 if d1 ** 2 + c1 == min(m, n): c = 1 while True: c1 -= 1 d1 = m1 - c1 ** 2 if d1 ** 2 + c1 == min(m, n): c += 1 else: break ...
3
327
A
Flipping Game
PROGRAMMING
1,200
[ "brute force", "dp", "implementation" ]
null
null
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
[ "5\n1 0 0 1 0\n", "4\n1 0 0 1\n" ]
[ "4\n", "4\n" ]
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all nu...
500
[ { "input": "5\n1 0 0 1 0", "output": "4" }, { "input": "4\n1 0 0 1", "output": "4" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "8\n1 0 0 0 1 0 0 0", "output": "7" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1,685,621,100
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
count1 = 0 extra0 = 0 extra0max = -1 n = int(input()) while n > 0: a = int(input()) if a == 1: count1 += 1 if extra0 > 0: extra0 -= 1 else: extra0 += 1 if extra0 > extra0max: extra0max = extra0 n -= 1 print(count1 + extra0max) ...
Title: Flipping Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *...
```python count1 = 0 extra0 = 0 extra0max = -1 n = int(input()) while n > 0: a = int(input()) if a == 1: count1 += 1 if extra0 > 0: extra0 -= 1 else: extra0 += 1 if extra0 > extra0max: extra0max = extra0 n -= 1 print(count1 + e...
-1
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,625,358,972
2,147,483,647
Python 3
OK
TESTS
33
62
0
a,b,c=map(int,input().split()) d,e,f=map(int,input().split()) g,h,i=map(int,input().split()) m=(a+b+d)%2 n=(a+b+c+e)%2 o=(b+c+f)%2 p=(a+d+e+g)%2 q=(b+d+e+f+h)%2 r=(c+e+f+i)%2 s=(d+g+h)%2 t=(e+g+h+i)%2 u=(f+h+i)%2 v=[m,n,o,p,q,r,s,t,u] x=[] for i in v: if i%2==0: x.append('1') else: x.append('0')...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python a,b,c=map(int,input().split()) d,e,f=map(int,input().split()) g,h,i=map(int,input().split()) m=(a+b+d)%2 n=(a+b+c+e)%2 o=(b+c+f)%2 p=(a+d+e+g)%2 q=(b+d+e+f+h)%2 r=(c+e+f+i)%2 s=(d+g+h)%2 t=(e+g+h+i)%2 u=(f+h+i)%2 v=[m,n,o,p,q,r,s,t,u] x=[] for i in v: if i%2==0: x.append('1') else: x.a...
3
794
F
Leha and security system
PROGRAMMING
2,800
[ "data structures" ]
null
null
Bankopolis, the city you already know, finally got a new bank opened! Unfortunately, its security system is not yet working fine... Meanwhile hacker Leha arrived in Bankopolis and decided to test the system! Bank has *n* cells for clients' money. A sequence from *n* numbers *a*1,<=*a*2,<=...,<=*a**n* describes the amo...
The first line of input contains two integers *n* and *q* (1<=≤<=*n*<=≤<=105, 1<=≤<=*q*<=≤<=105) denoting amount of cells in the bank and total amount of queries respectively. The following line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=&lt;<=109) denoting the amount of money in each cell initia...
For each second type query print a single number denoting the required sum.
[ "5 5\n38 43 4 12 70\n1 1 3 4 8\n2 2 4\n1 4 5 0 8\n1 2 5 8 7\n2 1 5\n", "5 5\n25 36 39 40 899\n1 1 3 2 7\n2 1 2\n1 3 5 9 1\n1 4 4 0 9\n2 1 5\n" ]
[ "103\n207\n", "111\n1002\n" ]
Let's look at the example testcase. Initially the sequence is [38, 43, 4, 12, 70]. After the first change each digit equal to 4 becomes 8 for each element with index in interval [1; 3]. Thus, the new sequence is [38, 83, 8, 12, 70]. The answer for the first sum's query is the sum in the interval [2; 4], which equal...
2,750
[]
1,581,168,642
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
108
0
import sys lines = sys.stdin.readlines() print(lines) l = lines[1].split() edit = lambda l, i, j, a, b: [l[x].replace(a, b) for x in range(i - 1, j)] _sum = lambda l, i, j: sum(map(int, l[i - 1:j]))
Title: Leha and security system Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bankopolis, the city you already know, finally got a new bank opened! Unfortunately, its security system is not yet working fine... Meanwhile hacker Leha arrived in Bankopolis and decided to test the system! B...
```python import sys lines = sys.stdin.readlines() print(lines) l = lines[1].split() edit = lambda l, i, j, a, b: [l[x].replace(a, b) for x in range(i - 1, j)] _sum = lambda l, i, j: sum(map(int, l[i - 1:j])) ```
0
873
B
Balanced Substring
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to deter...
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
[ "8\n11010111\n", "3\n111\n" ]
[ "4\n", "0\n" ]
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
0
[ { "input": "8\n11010111", "output": "4" }, { "input": "3\n111", "output": "0" }, { "input": "11\n00001000100", "output": "2" }, { "input": "10\n0100000000", "output": "2" }, { "input": "13\n0001000011010", "output": "6" }, { "input": "14\n0000010010101...
1,511,420,721
2,147,483,647
Python 3
OK
TESTS
53
155
9,318,400
n=int(input()) s=input() a=[2*int(i)-1 for i in s] d={} d[0]=-1 h=0 ans=0 for t in range (n): h+=a[t] if h in d: ans=max(ans,t-d[h]) else: d[h]=t print(ans)
Title: Balanced Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called...
```python n=int(input()) s=input() a=[2*int(i)-1 for i in s] d={} d[0]=-1 h=0 ans=0 for t in range (n): h+=a[t] if h in d: ans=max(ans,t-d[h]) else: d[h]=t print(ans) ```
3
618
A
Slime Combining
PROGRAMMING
800
[ "implementation" ]
null
null
Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of...
The first line of the input will contain a single integer, *n* (1<=≤<=*n*<=≤<=100<=000).
Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left.
[ "1\n", "2\n", "3\n", "8\n" ]
[ "1\n", "2\n", "2 1\n", "4\n" ]
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. S...
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "2 1" }, { "input": "8", "output": "4" }, { "input": "100000", "output": "17 16 11 10 8 6" }, { "input": "12345", "output": "14 13 6 5 4 1" }, { "in...
1,609,342,314
2,147,483,647
Python 3
OK
TESTS
27
109
0
n=int(input()) for i in range(20,-1,-1): if(2**i<=n): print(i+1,end=' ') n-=2**i
Title: Slime Combining Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, y...
```python n=int(input()) for i in range(20,-1,-1): if(2**i<=n): print(i+1,end=' ') n-=2**i ```
3
900
A
Find Extra One
PROGRAMMING
800
[ "geometry", "implementation" ]
null
null
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
[ "3\n1 1\n-1 -1\n2 -1\n", "4\n1 1\n2 2\n-1 1\n-2 2\n", "3\n1 2\n2 1\n4 60\n" ]
[ "Yes", "No", "Yes" ]
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
500
[ { "input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes" }, { "input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No" }, { "input": "3\n1 2\n2 1\n4 60", "output": "Yes" }, { "input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "output": "Yes" }, { "input": "2\n1...
1,587,721,944
2,147,483,647
PyPy 3
OK
TESTS
71
998
9,523,200
n = int(input()) l = 0 r = 0 for i in range(n): x, y = [int(i) for i in input().split()] if (x < 0): l += 1 else: r += 1 if (l in (0, 1) or r in (0, 1)): print("Yes") else: print("No")
Title: Find Extra One Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. Input Specification: The first li...
```python n = int(input()) l = 0 r = 0 for i in range(n): x, y = [int(i) for i in input().split()] if (x < 0): l += 1 else: r += 1 if (l in (0, 1) or r in (0, 1)): print("Yes") else: print("No") ```
3
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whe...
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO"...
1,685,831,677
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
x=input() x=x.split() n=x[0] t=x[1] k=x[2] d=x[3] stat=int(n)-int(k) if t==d: print("NO") elif stat>0 or int(t*2)<int(d): print("YES") else: print("NO")
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu...
```python x=input() x=x.split() n=x[0] t=x[1] k=x[2] d=x[3] stat=int(n)-int(k) if t==d: print("NO") elif stat>0 or int(t*2)<int(d): print("YES") else: print("NO") ```
0
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ...
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihn...
1,585,667,268
2,147,483,647
Python 3
OK
TESTS
58
109
0
s=input().count print(max(0,min((s('n')-1)//2,s('e')//3,s('i'),s('t'))))
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiinetee...
```python s=input().count print(max(0,min((s('n')-1)//2,s('e')//3,s('i'),s('t')))) ```
3
475
B
Strongly Connected City
PROGRAMMING
1,400
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes...
The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length *n*, made of characters '&lt;' and '&gt;', denoting direction of each horizontal street. If the *i*-th character...
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
[ "3 3\n&gt;&lt;&gt;\nv^v\n", "4 6\n&lt;&gt;&lt;&gt;\nv^v^v^\n" ]
[ "NO\n", "YES\n" ]
The figure above shows street directions in the second sample test case.
1,000
[ { "input": "3 3\n><>\nv^v", "output": "NO" }, { "input": "4 6\n<><>\nv^v^v^", "output": "YES" }, { "input": "2 2\n<>\nv^", "output": "YES" }, { "input": "2 2\n>>\n^v", "output": "NO" }, { "input": "3 3\n>><\n^^v", "output": "YES" }, { "input": "3 4\n>>...
1,539,372,112
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
108
0
from sys import stdin n, m = [int(x) for x in stdin.readline().rstrip().split()] h = stdin.readline().rstrip() v = stdin.readline().rstrip() con = h[0] + v[0] + h[n - 1] + v[n - 1] if con == '<v>^' or con == '>^<v': print('YES') else: print('NO')
Title: Strongly Connected City Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one...
```python from sys import stdin n, m = [int(x) for x in stdin.readline().rstrip().split()] h = stdin.readline().rstrip() v = stdin.readline().rstrip() con = h[0] + v[0] + h[n - 1] + v[n - 1] if con == '<v>^' or con == '>^<v': print('YES') else: print('NO') ```
0