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
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }...
1,591,098,720
2,147,483,647
Python 3
OK
TESTS
56
156
7,680,000
n=int(input()) a=[int(i) for i in input().split()] c=0 ind=-1 for i in range(1,n): if a[i]<a[i-1]: c+=1 s=i if c==0: print(0) elif a[0]>=a[n-1]and c==1: print(n-s) else: print(-1)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ...
```python n=int(input()) a=[int(i) for i in input().split()] c=0 ind=-1 for i in range(1,n): if a[i]<a[i-1]: c+=1 s=i if c==0: print(0) elif a[0]>=a[n-1]and c==1: print(n-s) else: print(-1) ```
3
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning ...
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he'...
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input":...
1,691,127,210
2,147,483,647
Python 3
OK
TESTS
30
46
0
arr = list(map(int , input().split())) arr.sort() print(arr[0] , (arr[1] - arr[0]) // 2)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red...
```python arr = list(map(int , input().split())) arr.sort() print(arr[0] , (arr[1] - arr[0]) // 2) ```
3
182
B
Vasya's Calendar
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n...
The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106). The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000). The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — th...
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
[ "4\n2\n2 2\n", "5\n3\n3 4 3\n", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n" ]
[ "2\n", "3\n", "7\n" ]
In the first sample the situation is like this: - Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by ...
500
[ { "input": "4\n2\n2 2", "output": "2" }, { "input": "5\n3\n3 4 3", "output": "3" }, { "input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "output": "7" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n1 1", "output": "0" }, { "input": "2...
1,666,154,184
2,147,483,647
Python 3
OK
TESTS
40
92
0
t = int(input()) a = int(input()) l = input().split(' ') times = 0 for i in range(0, a-1): times += t - int(l[i]) print(times)
Title: Vasya's Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any ...
```python t = int(input()) a = int(input()) l = input().split(' ') times = 0 for i in range(0, a-1): times += t - int(l[i]) print(times) ```
3
559
A
Gerald's Hexagon
PROGRAMMING
1,600
[ "brute force", "geometry", "math" ]
null
null
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He pain...
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides ex...
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
[ "1 1 1 1 1 1\n", "1 2 1 2 1 2\n" ]
[ "6\n", "13\n" ]
This is what Gerald's hexagon looks like in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's what it looks like in the second sample: <img class="tex-graphics" src="https://espress...
500
[ { "input": "1 1 1 1 1 1", "output": "6" }, { "input": "1 2 1 2 1 2", "output": "13" }, { "input": "2 4 5 3 3 6", "output": "83" }, { "input": "45 19 48 18 46 21", "output": "6099" }, { "input": "66 6 65 6 66 5", "output": "5832" }, { "input": "7 5 4 8 ...
1,691,963,585
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
# динпрог на одномерном массиве ''' from random import randint for _ in range(int(input())): n = int(input()) dp = [0]+[10**9 for i in range(n-1)] price = [0]+[randint(1, 10) for i in range(n-1)] for j in range(n): if j+1<n: dp[j+1]=min(dp[j+1], dp[j]+price[j+1]) if j+2<n: dp[j+2]=min(dp[j+2], ...
Title: Gerald's Hexagon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer numbe...
```python # динпрог на одномерном массиве ''' from random import randint for _ in range(int(input())): n = int(input()) dp = [0]+[10**9 for i in range(n-1)] price = [0]+[randint(1, 10) for i in range(n-1)] for j in range(n): if j+1<n: dp[j+1]=min(dp[j+1], dp[j]+price[j+1]) if j+2<n: dp[j+2]=min...
0
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32...
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { ...
1,621,279,517
2,147,483,647
Python 3
OK
TESTS
43
77
0
n = input() a1 = list( map( int , list(input() ))) a2 = list( map( int , list(input() ))) def func(n1, n2): return min(abs(n1-n2), 10 - abs(n1- n2)) count = 0 for n1, n2 in zip(a1, a2): count += func(n1, n2) print(count)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is ...
```python n = input() a1 = list( map( int , list(input() ))) a2 = list( map( int , list(input() ))) def func(n1, n2): return min(abs(n1-n2), 10 - abs(n1- n2)) count = 0 for n1, n2 in zip(a1, a2): count += func(n1, n2) print(count) ```
3
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is...
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not ...
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20...
1,694,023,523
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n=input() n=int(n) x=[int(i) for i in input().split()] x.sort() for i in range(n): print(x[i],end="")
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the bo...
```python n=input() n=int(n) x=[int(i) for i in input().split()] x.sort() for i in range(n): print(x[i],end="") ```
0
965
B
Battleship
PROGRAMMING
1,300
[ "implementation" ]
null
null
Arkady is playing Battleship. The rules of this game aren't really important. There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arka...
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the size of the field and the size of the ship. The next $n$ lines contain the field. Each line contains $n$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).
Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship. If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.
[ "4 3\n#..#\n#.#.\n....\n.###\n", "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#\n", "19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.###############...
[ "3 2\n", "6 1\n", "1 8\n" ]
The picture below shows the three possible locations of the ship that contain the cell $(3, 2)$ in the first sample.
1,000
[ { "input": "4 3\n#..#\n#.#.\n....\n.###", "output": "3 2" }, { "input": "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#", "output": "6 1" }, { "input": "19 6\n##..............###\n#......#####.....##\n.....####...
1,524,746,267
2,147,483,647
PyPy 3
OK
TESTS
39
233
24,576,000
def fix(a,b,c): ret=min(a,c+k-1)-max(c-k+1,b)-k+2 return [0,ret][ret>0] def solve(row,col): a1=a2=row a3=a4=col while(a1+1>=0 and a1+1<n and mp[a1+1][col]!='#'): a1+=1 while(a2-1>=0 and a2-1<n and mp[a2-1][col]!='#'): a2-=1 while(a3+1>=0 and a3+1<n and mp[row][a3+1]!='#'): a3+=1 while(a4-1>=0 ...
Title: Battleship Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady is playing Battleship. The rules of this game aren't really important. There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either ...
```python def fix(a,b,c): ret=min(a,c+k-1)-max(c-k+1,b)-k+2 return [0,ret][ret>0] def solve(row,col): a1=a2=row a3=a4=col while(a1+1>=0 and a1+1<n and mp[a1+1][col]!='#'): a1+=1 while(a2-1>=0 and a2-1<n and mp[a2-1][col]!='#'): a2-=1 while(a3+1>=0 and a3+1<n and mp[row][a3+1]!='#'): a3+=1 whil...
3
152
B
Steps
PROGRAMMING
1,300
[ "binary search", "implementation" ]
null
null
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the yard's sizes. The second line contains integers *x**c* and *y**c* — the initial square's coordinates (1<=≤<=*x**c*<=≤<=*n*,<=1<=≤<=*y**c*<=≤<=*m*). The third line contains an integer *k* (1<=≤<=*k*<=≤<=104) — the number of vectors. ...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "4 5\n1 1\n3\n1 1\n1 1\n0 -2\n", "10 10\n1 2\n1\n-1 0\n" ]
[ "4\n", "0\n" ]
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0,  - 2) and he ends up in square (4, 2). Overall,...
1,000
[ { "input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4" }, { "input": "10 10\n1 2\n1\n-1 0", "output": "0" }, { "input": "10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5", "output": "13" }, { "input": "20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n2...
1,660,325,217
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
def check(x,y): global n,m if x>0 and x<=n and y>0 and y<=m: return True return False n,m=list(map(int,input().split()));pos=list(map(int,input().split()));k=int(input());steps=0 for i in range(k): maxi=10**9;mini=0;arr=[] x,y=list(map(int,input().split())) while mini<=maxi: ...
Title: Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ...
```python def check(x,y): global n,m if x>0 and x<=n and y>0 and y<=m: return True return False n,m=list(map(int,input().split()));pos=list(map(int,input().split()));k=int(input());steps=0 for i in range(k): maxi=10**9;mini=0;arr=[] x,y=list(map(int,input().split())) while min...
0
952
A
Quirky Quantifiers
PROGRAMMING
800
[ "math" ]
null
null
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999). Output 0 or 1.
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1.
[ "13\n", "927\n", "48\n" ]
[ "1\n", "1\n", "0\n" ]
none
0
[ { "input": "13", "output": "1" }, { "input": "927", "output": "1" }, { "input": "48", "output": "0" }, { "input": "10", "output": "0" }, { "input": "999", "output": "1" }, { "input": "142", "output": "0" }, { "input": "309", "output": "...
1,618,562,039
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
77
0
def main_function(): s = input() return 0 print(main_function())
Title: Quirky Quantifiers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (10<=≤<=*a*<=≤<=999). Output 0 or 1. Input Specification: The input contains a single integer *a* (10<=≤<=*a*<=≤<=999). Output Specification: Output 0 or 1. Demo Input: ['1...
```python def main_function(): s = input() return 0 print(main_function()) ```
0
525
B
Pasha and String
PROGRAMMING
1,400
[ "constructive algorithms", "greedy", "math", "strings" ]
null
null
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string. Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ...
The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters. The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) —  the number of days when Pasha changed his string. The third line contains *m* space-separated elements *a**i* (1<=≤<...
In the first line of the output print what Pasha's string *s* will look like after *m* days.
[ "abcdef\n1\n2\n", "vwxyz\n2\n2 2\n", "abcdef\n3\n1 2 3\n" ]
[ "aedcbf\n", "vwxyz\n", "fbdcea\n" ]
none
750
[ { "input": "abcdef\n1\n2", "output": "aedcbf" }, { "input": "vwxyz\n2\n2 2", "output": "vwxyz" }, { "input": "abcdef\n3\n1 2 3", "output": "fbdcea" }, { "input": "jc\n5\n1 1 1 1 1", "output": "cj" }, { "input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3", "out...
1,544,090,159
2,147,483,647
PyPy 3
OK
TESTS
43
233
16,384,000
I=input s=list(I()) S=len(s) n=int(I()) t=0 *l,=sorted(map(int,I().split())) for i in range(S//2): while t<n and l[t]<=i+1:t+=1 if t%2:s[i],s[S-i-1]=s[S-i-1],s[i] print(''.join(s))
Title: Pasha and String Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ...
```python I=input s=list(I()) S=len(s) n=int(I()) t=0 *l,=sorted(map(int,I().split())) for i in range(S//2): while t<n and l[t]<=i+1:t+=1 if t%2:s[i],s[S-i-1]=s[S-i-1],s[i] print(''.join(s)) ```
3
863
A
Quasi-palindrome
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str...
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
[ "131\n", "320\n", "2010200\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
0
[ { "input": "131", "output": "YES" }, { "input": "320", "output": "NO" }, { "input": "2010200", "output": "YES" }, { "input": "1", "output": "YES" }, { "input": "1000000000", "output": "YES" }, { "input": "999999999", "output": "YES" }, { "i...
1,544,105,870
2,147,483,647
Python 3
OK
TESTS
44
109
0
x =input() s = "" t = 0 for i in range(len(x)): if x[len(x) - i -1] != "0": s += x[len(x) -i -1] t = 1 elif t != 0: s += x[len(x) - i - 1] r = "" for i in range(len(s)): r += s[len(s) - i -1] if r == s: print("YES") else: print("NO")
Title: Quasi-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from righ...
```python x =input() s = "" t = 0 for i in range(len(x)): if x[len(x) - i -1] != "0": s += x[len(x) -i -1] t = 1 elif t != 0: s += x[len(x) - i - 1] r = "" for i in range(len(s)): r += s[len(s) - i -1] if r == s: print("YES") else: print("NO") ```
3
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRR...
1,646,825,213
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n=int(input());s=input();t=0 if n==1:print(1) else: if s[:2] in ['UR','RU']: t+=1 for i in range(1,n-1): if s[i-1:i+2] in ['UUR','RRU']:t+=1 print(t)
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence movi...
```python n=int(input());s=input();t=0 if n==1:print(1) else: if s[:2] in ['UR','RU']: t+=1 for i in range(1,n-1): if s[i-1:i+2] in ['UUR','RRU']:t+=1 print(t) ```
0
852
G
Bathroom terminal
PROGRAMMING
1,700
[ "implementation" ]
null
null
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
The first line of input contains two integers *N* and *M* (1<=≤<=*N*<=≤<= 100 000, 1<=≤<=*M*<=≤<= 5000), representing the number of words and patterns respectively. The next *N* lines represent each word, and after those *N* lines, following *M* lines represent each pattern. Each word and each pattern has a maximum le...
Output contains *M* lines and each line consists of one integer, representing the number of words that match the corresponding pattern.
[ "3 1\nabc\naec\nac\na?c\n" ]
[ "3\n" ]
If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively.
0
[ { "input": "3 1\nabc\naec\nac\na?c", "output": "3" }, { "input": "22 2\naaaab\naaabb\naabab\naabbb\nabaab\nababb\nabbab\nabbbb\naaab\naabb\nabab\nabbb\naab\nabb\nab\ncccd\nccdd\ncdcd\ncddd\nccd\ncdd\ncd\na???b\nc??d", "output": "15\n7" }, { "input": "15 6\naaa\naaabbb\naaabb\naaaaa\naaaa...
1,504,435,008
2,208
Python 3
WRONG_ANSWER
TESTS
1
46
0
n, m=map(int, input().split()) M=dict() for i in range(n): s=input() if s in M: M[s]+=1 else: M[s]=1 t=['', 'a', 'b', 'c', 'd', 'e'] for i in range(m): s=input() ans=0 if '?' in s: for p in t: ans+=M.get(s.replace('?', p), 0) else: ans=M.get(s, 0) print(ans)
Title: Bathroom terminal Time Limit: None seconds Memory Limit: None megabytes Problem Description: Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in ...
```python n, m=map(int, input().split()) M=dict() for i in range(n): s=input() if s in M: M[s]+=1 else: M[s]=1 t=['', 'a', 'b', 'c', 'd', 'e'] for i in range(m): s=input() ans=0 if '?' in s: for p in t: ans+=M.get(s.replace('?', p), 0) else: ans=M.get(s, 0) print(ans) ```
0
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t...
Print *m* integers — the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5...
1,699,684,436
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
1,740,800
s = [0]+(list(input())) m = int(input()) for i in range(m): l, r = map(int, input().split()) num = 0 for i in range(l,r): if s[i] == s[i+1]: num += 1 print(num)
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ...
```python s = [0]+(list(input())) m = int(input()) for i in range(m): l, r = map(int, input().split()) num = 0 for i in range(l,r): if s[i] == s[i+1]: num += 1 print(num) ```
0
348
A
Mafia
PROGRAMMING
1,600
[ "binary search", "math", "sortings" ]
null
null
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min...
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n3 2 2\n", "4\n2 2 2 2\n" ]
[ "4\n", "3\n" ]
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
500
[ { "input": "3\n3 2 2", "output": "4" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "7\n9 7 7 8 8 7 8", "output": "9" }, { "input": "10\n13 12 10 13 13 14 10 10 12 12", "output": "14" }, { "input": "10\n94 96 91 95 99 94 96 92 95 99", "output": "106" ...
1,664,651,789
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n=int(input()) l=list(map(int, input().split())) d={i:0 for i in l} for i in l: d[i]+=1 x=[] for i in d: x.append([i,d[i]]) x=sorted(x) if len(x)==1: print(l[0]*2) else: ans=0 if x[0][1]==1: ans=x[0][0]+x[1][0] else: ans=2*x[0][0] for i in ran...
Title: Mafia Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a...
```python n=int(input()) l=list(map(int, input().split())) d={i:0 for i in l} for i in l: d[i]+=1 x=[] for i in d: x.append([i,d[i]]) x=sorted(x) if len(x)==1: print(l[0]*2) else: ans=0 if x[0][1]==1: ans=x[0][0]+x[1][0] else: ans=2*x[0][0] fo...
0
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea...
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n...
1,681,304,650
2,147,483,647
Python 3
OK
TESTS
31
122
409,600
import sys import string input = sys.stdin.readline def print(*args, end='\n', sep=' ') -> None: sys.stdout.write(sep.join(map(str, args)) + end) def solve(home: list, guest: list) -> str: c = 0 for i in home: c += guest.count(i) print(c) def main() -> None: n = int(in...
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W...
```python import sys import string input = sys.stdin.readline def print(*args, end='\n', sep=' ') -> None: sys.stdout.write(sep.join(map(str, args)) + end) def solve(home: list, guest: list) -> str: c = 0 for i in home: c += guest.count(i) print(c) def main() -> None: ...
3
605
A
Sorting Railway Cars
PROGRAMMING
1,600
[ "constructive algorithms", "greedy" ]
null
null
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and telepor...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train.
Print a single integer — the minimum number of actions needed to sort the railway cars.
[ "5\n4 1 2 5 3\n", "4\n4 1 3 2\n" ]
[ "2\n", "2\n" ]
In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
500
[ { "input": "5\n4 1 2 5 3", "output": "2" }, { "input": "4\n4 1 3 2", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "6\n5 3 6 1 4 2", "output": "4" }, ...
1,451,276,887
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
62
0
n=int(input()) p=input().split() car=[] for i in range(len(p)): car.append([int(p[i]),i]) car.sort() ans=[] for i in range(n): ab=0 for j in range(i+1,n): if car[j][1]<car[i][1]: ab+=1 ans.append(ab) print(max(ans))
Title: Sorting Railway Cars Time Limit: None seconds Memory Limit: None megabytes Problem Description: An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the...
```python n=int(input()) p=input().split() car=[] for i in range(len(p)): car.append([int(p[i]),i]) car.sort() ans=[] for i in range(n): ab=0 for j in range(i+1,n): if car[j][1]<car[i][1]: ab+=1 ans.append(ab) print(max(ans)) ```
0
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ...
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" ...
1,697,272,304
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
MOD = 1000000007 n = int(input()) dp = [[0] * 4 for _ in range(n + 1)] # There's only one way to get to D from D in 0 steps dp[0][3] = 1 for i in range(1, n + 1): for j in range(4): dp[i][j] = (dp[i - 1][(j - 1) % 4] + dp[i - 1][(j + 1) % 4]) % MOD # The final answer is the number of ways to...
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m...
```python MOD = 1000000007 n = int(input()) dp = [[0] * 4 for _ in range(n + 1)] # There's only one way to get to D from D in 0 steps dp[0][3] = 1 for i in range(1, n + 1): for j in range(4): dp[i][j] = (dp[i - 1][(j - 1) % 4] + dp[i - 1][(j + 1) % 4]) % MOD # The final answer is the number ...
0
743
B
Chloe and the sequence
PROGRAMMING
1,200
[ "binary search", "bitmasks", "constructive algorithms", "implementation" ]
null
null
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq...
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1).
Print single integer — the integer at the *k*-th position in the obtained sequence.
[ "3 2\n", "4 8\n" ]
[ "2", "4" ]
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2. In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.
1,000
[ { "input": "3 2", "output": "2" }, { "input": "4 8", "output": "4" }, { "input": "5 27", "output": "1" }, { "input": "7 44", "output": "3" }, { "input": "15 18432", "output": "12" }, { "input": "20 259676", "output": "3" }, { "input": "30 6...
1,559,726,118
2,147,483,647
Python 3
MEMORY_LIMIT_EXCEEDED
TESTS
6
280
268,390,400
n,k=map(int,input().split()) a=[1] if(k>=2**(n-1)): k=2**n -k x=len(bin(k)[2:]) for i in range(2,x+1): a.extend(a) a.insert(len(a)//2,i) print(a[k-1])
Title: Chloe and the sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following a...
```python n,k=map(int,input().split()) a=[1] if(k>=2**(n-1)): k=2**n -k x=len(bin(k)[2:]) for i in range(2,x+1): a.extend(a) a.insert(len(a)//2,i) print(a[k-1]) ```
0
408
A
Line to Cashier
PROGRAMMING
900
[ "implementation" ]
null
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i*...
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
[ "1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n" ]
[ "20\n", "100\n" ]
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
500
[ { "input": "1\n1\n1", "output": "20" }, { "input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100" }, { "input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "output": "100" }, { "input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"...
1,643,121,021
2,147,483,647
Python 3
OK
TESTS
20
31
0
n=int(input()) k=list(map(int,input().split())) for i in range(n): a=list(map(int,input().split())) val=sum(a)*5+k[i]*15 if(i==0): m=val else: if(m>val): m=val print(m)
Title: Line to Cashier Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* c...
```python n=int(input()) k=list(map(int,input().split())) for i in range(n): a=list(map(int,input().split())) val=sum(a)*5+k[i]*15 if(i==0): m=val else: if(m>val): m=val print(m) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,567,467,999
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
184
0
c=input() a=int(c[0]) b=int(c[2]) k=0 for i in range(1,7): if(i>=a and i>=b): k=k+1 print(k) if(k%2==0): if(k%3==0): print(1/1) else: k=k/2 print(round(k),"/3",sep='') elif (k%3==0): k=k/3 print(round(k),"/2",sep='') else: print(round(k),'/6',sep='')
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python c=input() a=int(c[0]) b=int(c[2]) k=0 for i in range(1,7): if(i>=a and i>=b): k=k+1 print(k) if(k%2==0): if(k%3==0): print(1/1) else: k=k/2 print(round(k),"/3",sep='') elif (k%3==0): k=k/3 print(round(k),"/2",sep='') else: print(round(k),'/6',sep='') ```
0
797
A
k-Factorization
PROGRAMMING
1,100
[ "implementation", "math", "number theory" ]
null
null
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them.
[ "100000 2\n", "100000 20\n", "1024 5\n" ]
[ "2 50000 \n", "-1\n", "2 64 2 2 2 \n" ]
none
0
[ { "input": "100000 2", "output": "2 50000 " }, { "input": "100000 20", "output": "-1" }, { "input": "1024 5", "output": "2 64 2 2 2 " }, { "input": "100000 10", "output": "2 2 2 2 2 5 5 5 5 5 " }, { "input": "99999 3", "output": "3 813 41 " }, { "input...
1,625,685,866
2,147,483,647
Python 3
OK
TESTS
166
93
0
n, k = map(int, (input().split())) d = [] i = 2 while i <= n: while n % i == 0: d.append(i) n //= i else: i += 1 if len(d) < k: print(-1) else: while len(d) > k: d[-2] *= d[-1] d.pop() print(*d)
Title: k-Factorization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. Input Specification: The first line contains two int...
```python n, k = map(int, (input().split())) d = [] i = 2 while i <= n: while n % i == 0: d.append(i) n //= i else: i += 1 if len(d) < k: print(-1) else: while len(d) > k: d[-2] *= d[-1] d.pop() print(*d) ```
3
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len...
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o...
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form...
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, ...
1,661,703,634
2,147,483,647
Python 3
OK
TESTS
21
46
0
d1,d2,d3=map(int,input().split()) print(min((d1+d2+d3),(2*d1+2*d2),(2*d2+2*d3),(2*d1+2*d3)))
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the...
```python d1,d2,d3=map(int,input().split()) print(min((d1+d2+d3),(2*d1+2*d2),(2*d2+2*d3),(2*d1+2*d3))) ```
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,595,441,141
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
124
20,172,800
s=input() l=list(s) d={} for i in l: if i in d: d[i]+=1 else: d[i]=1 l1=(list(d.keys())) ind1=l1.index('h') ind2=l1.index('e') ind3=l1.index('l') ind4=l1.index('o') if ind1<ind2 and ind2<ind3 and ind3<ind4 and d['l']>=2: 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() l=list(s) d={} for i in l: if i in d: d[i]+=1 else: d[i]=1 l1=(list(d.keys())) ind1=l1.index('h') ind2=l1.index('e') ind3=l1.index('l') ind4=l1.index('o') if ind1<ind2 and ind2<ind3 and ind3<ind4 and d['l']>=2: print("YES") else: print("NO") ...
0
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n5100...
1,607,073,256
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
n=int(input()) l=list(map(int,input().split())) ans=0 s=1 e=1000000 for i in l: if i-s < e-i: ans+=(i-s) s=i e=e-(i-s) else: ans+=e-s e=i s=s+(e-i) ans+=e-s print(ans)
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are di...
```python n=int(input()) l=list(map(int,input().split())) ans=0 s=1 e=1000000 for i in l: if i-s < e-i: ans+=(i-s) s=i e=e-(i-s) else: ans+=e-s e=i s=s+(e-i) ans+=e-s print(ans) ```
0
910
A
The Way to Home
PROGRAMMING
800
[ "dfs and similar", "dp", "greedy", "implementation" ]
null
null
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* ...
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ...
If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
[ "8 4\n10010101\n", "4 2\n1001\n", "8 4\n11100101\n", "12 3\n101111100101\n" ]
[ "2\n", "-1\n", "3\n", "4\n" ]
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a ...
500
[ { "input": "8 4\n10010101", "output": "2" }, { "input": "4 2\n1001", "output": "-1" }, { "input": "8 4\n11100101", "output": "3" }, { "input": "12 3\n101111100101", "output": "4" }, { "input": "5 4\n11011", "output": "1" }, { "input": "5 4\n10001", ...
1,697,242,669
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import java.util.Scanner; public class Teletransporte { public static int teletransporte(String caminho, int posicao, int salto, int contador) { int i = salto + posicao; while (i > posicao) { if (i <= caminho.length() - 1 && caminho.charAt(i) == '1') { if (i == caminho....
Title: The Way to Home Time Limit: None seconds Memory Limit: None megabytes Problem Description: A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c...
```python import java.util.Scanner; public class Teletransporte { public static int teletransporte(String caminho, int posicao, int salto, int contador) { int i = salto + posicao; while (i > posicao) { if (i <= caminho.length() - 1 && caminho.charAt(i) == '1') { if (i =...
-1
160
A
Twins
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
In the single line print the single number — the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't e...
500
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" ...
1,694,754,402
2,147,483,647
Python 3
OK
TESTS
29
92
0
n = int(input()) coins = list(map(int, input().split())) coins.sort(reverse=True) total_sum = sum(coins) my_sum = 0 count = 0 for i in range(n): my_sum += coins[i] count += 1 if my_sum > total_sum - my_sum: break print(count)
Title: Twins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w...
```python n = int(input()) coins = list(map(int, input().split())) coins.sort(reverse=True) total_sum = sum(coins) my_sum = 0 count = 0 for i in range(n): my_sum += coins[i] count += 1 if my_sum > total_sum - my_sum: break print(count) ```
3
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: -...
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "...
1,466,171,653
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
l = list(map(int, input().split())) u = set(l) four = None for c in u: if l.count(c) == 4: four = c break u = u - {four} if four is None: print('Alien') elif len(u) == 1: print('Elephant') else: print('Bear')
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an...
```python l = list(map(int, input().split())) u = set(l) four = None for c in u: if l.count(c) == 4: four = c break u = u - {four} if four is None: print('Alien') elif len(u) == 1: print('Elephant') else: print('Bear') ```
0
299
A
Ksusha and Array
PROGRAMMING
1,000
[ "brute force", "number theory", "sortings" ]
null
null
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n" ]
[ "2\n", "1\n", "-1\n" ]
none
500
[ { "input": "3\n2 2 4", "output": "2" }, { "input": "5\n2 1 3 1 6", "output": "1" }, { "input": "3\n2 3 5", "output": "-1" }, { "input": "1\n331358794", "output": "331358794" }, { "input": "5\n506904227 214303304 136194869 838256937 183952885", "output": "-1" ...
1,642,641,068
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
21
2,000
7,782,400
n = int(input()) a = [int(i) for i in input().split()] t = 0 for i in range(n): div = True for j in range(n): if i != j and a[j] % a[i] != 0: div = False break if div: t = a[i] break if t == 0: print(-1) else: print(t)
Title: Ksusha and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that ...
```python n = int(input()) a = [int(i) for i in input().split()] t = 0 for i in range(n): div = True for j in range(n): if i != j and a[j] % a[i] != 0: div = False break if div: t = a[i] break if t == 0: print(-1) else: print(t) ```
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,634,643,132
2,147,483,647
Python 3
OK
TESTS
40
46
0
s = input() l = ['o','l','l','e','h'] for i in s: if i == l[-1]: l.pop() if len(l) == 0: break if len(l) == 0: 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() l = ['o','l','l','e','h'] for i in s: if i == l[-1]: l.pop() if len(l) == 0: break if len(l) == 0: print('YES') else: print('NO') ```
3.977
447
A
DZY Loves Hash
PROGRAMMING
800
[ "implementation" ]
null
null
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==...
The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Output a single integer — the answer to the problem.
[ "10 5\n0\n21\n53\n41\n53\n", "5 5\n0\n1\n2\n3\n4\n" ]
[ "4\n", "-1\n" ]
none
500
[ { "input": "10 5\n0\n21\n53\n41\n53", "output": "4" }, { "input": "5 5\n0\n1\n2\n3\n4", "output": "-1" }, { "input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537", "output": "4" }, { "input": "2 2\n788371161\n801743052", "output": "-1" }, { ...
1,553,495,167
2,147,483,647
PyPy 3
OK
TESTS
29
124
0
p,n=map(int,input().split()) D=[-1]*p for i in range(n): y=int(input()) if D[y%p]!=-1: print(i+1) exit() else: D[y%p]=0 print(-1)
Title: DZY Loves Hash Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere...
```python p,n=map(int,input().split()) D=[-1]*p for i in range(n): y=int(input()) if D[y%p]!=-1: print(i+1) exit() else: D[y%p]=0 print(-1) ```
3
812
A
Sagheer and Crossroads
PROGRAMMING
1,200
[ "implementation" ]
null
null
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane...
The input consists of four lines with each line describing a road part given in a counter-clockwise order. Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
[ "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4. In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.
500
[ { "input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1", "output": "YES" }, { "input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1", "output": "NO" }, { "input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0", "output": "NO" }, { "input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1", "output": "NO" }, ...
1,496,650,304
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
22
62
0
a=[] for i in range(4): a.append(input().split(' ')) for i in range(4): if a[i][0]=='1' and a[(i+3)%4][3]=='1': print("YES") exit() if a[i][1]=='1' and a[(i+2)%4][3]=='1': print("YES") exit() if a[i][2]=='1' and a[(i+1)%4][3]=='1': print("YES") exit() print("NO")
Title: Sagheer and Crossroads Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l...
```python a=[] for i in range(4): a.append(input().split(' ')) for i in range(4): if a[i][0]=='1' and a[(i+3)%4][3]=='1': print("YES") exit() if a[i][1]=='1' and a[(i+2)%4][3]=='1': print("YES") exit() if a[i][2]=='1' and a[(i+1)%4][3]=='1': print("YES") exit() print("NO") ```
0
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th...
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\...
1,696,647,238
2,147,483,647
Python 3
OK
TESTS
36
46
0
n = int(input()) x = 0 for i in range(n): command = input() if "++" in command: x+=1 else: x-=1 print(x)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ incre...
```python n = int(input()) x = 0 for i in range(n): command = input() if "++" in command: x+=1 else: x-=1 print(x) ```
3
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "ou...
1,693,134,793
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) d=0 x=True def luck(s): a=True while s != 0: if s % 10 != 7 or s % 10 != 4: a=False s //= 10 return a for i in range(3,n): if n % i == 0 and luck(i)=True: print('YES') else: print('NO')
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains 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()) d=0 x=True def luck(s): a=True while s != 0: if s % 10 != 7 or s % 10 != 4: a=False s //= 10 return a for i in range(3,n): if n % i == 0 and luck(i)=True: print('YES') else: print('NO') ```
-1
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,667,653,974
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
x = int(input()) k = x for i in range(3): a,b = list(map(int, input().split())) if k==a: k = b elif k==b: k = a print(k)
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 x = int(input()) k = x for i in range(3): a,b = list(map(int, input().split())) if k==a: k = b elif k==b: k = a print(k) ```
-1
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
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. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,694,611,052
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
122
0
n = list(input()) length = list(str(len(n))) count = 0 res = 0 for i in n: if i == '4' or i == '7': res += 1 else: break if res == len(n): print('YES') else: for i in length: if i == '4' or i == '7': count += 1 else: break if l...
Title: Nearly Lucky Number 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 = list(input()) length = list(str(len(n))) count = 0 res = 0 for i in n: if i == '4' or i == '7': res += 1 else: break if res == len(n): print('YES') else: for i in length: if i == '4' or i == '7': count += 1 else: break...
0
803
C
Maximal GCD
PROGRAMMING
1,900
[ "constructive algorithms", "greedy", "math" ]
null
null
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi...
The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010).
If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
[ "6 3\n", "8 2\n", "5 3\n" ]
[ "1 2 3\n", "2 6\n", "-1\n" ]
none
0
[ { "input": "6 3", "output": "1 2 3" }, { "input": "8 2", "output": "2 6" }, { "input": "5 3", "output": "-1" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output": "-1" }, { "input": "2 1", "output": "2" }, { "input": "2 10000000...
1,600,585,258
2,147,483,647
PyPy 3
OK
TESTS
138
218
9,523,200
def divisors(x): divisor=[] for i in range(1,int(x**(1/2)+1)): if x%i==0: divisor.append(i) if i!=x//i: divisor.append(x//i) return divisor n,k=[int(x) for x in input().split()] factors=sorted(divisors(n)) maxfactor=0 for i in factors: if i*(k*(k+1)//2)<=n: maxfactor=i if m...
Title: Maximal GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal. Grea...
```python def divisors(x): divisor=[] for i in range(1,int(x**(1/2)+1)): if x%i==0: divisor.append(i) if i!=x//i: divisor.append(x//i) return divisor n,k=[int(x) for x in input().split()] factors=sorted(divisors(n)) maxfactor=0 for i in factors: if i*(k*(k+1)//2)<=n: maxfactor=i ...
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,623,745,035
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
154
0
n = int(input()) l1 = list(map(int,input().split())) s = 0 ans = "YES" l = [] if(l1[0]>25): print("NO") else: c25 = 0 c50 = 0 c100 = 0 ans = "YES" for i in l1: if(i==50): if(c25>0): c25-=1 c50+=1 else: ...
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()) l1 = list(map(int,input().split())) s = 0 ans = "YES" l = [] if(l1[0]>25): print("NO") else: c25 = 0 c50 = 0 c100 = 0 ans = "YES" for i in l1: if(i==50): if(c25>0): c25-=1 c50+=1 else: ...
0
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,683,223,478
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
1,433,600
# q20 A. Die Roll from fractions import Fraction y,w = map(int,input().split(' ')) chances = 6 - (max(y,w)) +1 if (Fraction(chances/6)==1): print('1/1') elif (Fraction(chances/6)==7505999378950827/9007199254740992): print('5/6') else: print (Fraction(chances/6))
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python # q20 A. Die Roll from fractions import Fraction y,w = map(int,input().split(' ')) chances = 6 - (max(y,w)) +1 if (Fraction(chances/6)==1): print('1/1') elif (Fraction(chances/6)==7505999378950827/9007199254740992): print('5/6') else: print (Fraction(chances/6)) ```
0
505
A
Mr. Kitayuta's Gift
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes...
The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter.
If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
[ "revive\n", "ee\n", "kitayuta\n" ]
[ "reviver\n", "eye", "NA\n" ]
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver". For the second sample, there is more than one solution. For example, "eve" will also be accepted. For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
500
[ { "input": "revive", "output": "reviver" }, { "input": "ee", "output": "eee" }, { "input": "kitayuta", "output": "NA" }, { "input": "evima", "output": "NA" }, { "input": "a", "output": "aa" }, { "input": "yutampo", "output": "NA" }, { "inpu...
1,448,022,278
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
19
561
10,854,400
from pip._vendor.distlib.compat import raw_input L = raw_input() l = 0 r = len(L)-1 flag = 1 ok = 1 gg = -1 while l <= r: if L[l] != L[r] and flag == 1: flag = 0 l+=1 gg = r elif L[l] != L[r] and flag == 0: ok = 0 break else: l+=1 r-...
Title: Mr. Kitayuta's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re...
```python from pip._vendor.distlib.compat import raw_input L = raw_input() l = 0 r = len(L)-1 flag = 1 ok = 1 gg = -1 while l <= r: if L[l] != L[r] and flag == 1: flag = 0 l+=1 gg = r elif L[l] != L[r] and flag == 0: ok = 0 break else: l+=1 ...
0
611
B
New Year and Old Property
PROGRAMMING
1,300
[ "bitmasks", "brute force", "implementation" ]
null
null
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Lim...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
[ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n" ]
[ "2\n", "1\n", "0\n", "26\n" ]
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<su...
750
[ { "input": "5 10", "output": "2" }, { "input": "2015 2015", "output": "1" }, { "input": "100 105", "output": "0" }, { "input": "72057594000000000 72057595000000000", "output": "26" }, { "input": "1 100", "output": "16" }, { "input": "100000000000000000...
1,660,928,912
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
#I = lambda: [int(i) for i in input().split()] #import io, os, sys #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # n = int(input()) # l1 = list(map(int,input().split())) # n,x = map(int,input().split()) # s = input() mod = 1000000007 # print("Case #"+str(_+1)+":",) from collections import ...
Title: New Year and Old Property Time Limit: None seconds Memory Limit: None megabytes Problem Description: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2...
```python #I = lambda: [int(i) for i in input().split()] #import io, os, sys #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # n = int(input()) # l1 = list(map(int,input().split())) # n,x = map(int,input().split()) # s = input() mod = 1000000007 # print("Case #"+str(_+1)+":",) from collectio...
0
877
B
Nikita and string
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
[ "abba\n", "bab\n" ]
[ "4", "2" ]
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
1,000
[ { "input": "abba", "output": "4" }, { "input": "bab", "output": "2" }, { "input": "bbabbbaabbbb", "output": "9" }, { "input": "bbabbbbbaaba", "output": "10" }, { "input": "bbabbbababaa", "output": "9" }, { "input": "aabbaababbab", "output": "8" }...
1,655,718,120
2,147,483,647
Python 3
OK
TESTS
46
46
0
inp = str(input()) a = [0] * 3 for i in inp: if i == 'a': a[2] = max(a) + 1 a[0] += 1 else: a[1] = max(a[:2]) + 1 print(max(a))
Title: Nikita and string Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ...
```python inp = str(input()) a = [0] * 3 for i in inp: if i == 'a': a[2] = max(a) + 1 a[0] += 1 else: a[1] = max(a[:2]) + 1 print(max(a)) ```
3
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, ...
1,627,621,614
2,147,483,647
PyPy 3
OK
TESTS
30
216
21,504,000
def main(): n = int(input()) arr = list(map(int, input().split())) count = 1 arr.sort() for i in arr: if i != count: print(count) exit() count += 1 print(count) main()
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the...
```python def main(): n = int(input()) arr = list(map(int, input().split())) count = 1 arr.sort() for i in arr: if i != count: print(count) exit() count += 1 print(count) main() ```
3.905946
808
B
Average Sleep Time
PROGRAMMING
1,300
[ "data structures", "implementation", "math" ]
null
null
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp k...
The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point.
[ "3 2\n3 4 7\n", "1 1\n10\n", "8 2\n1 2 4 100000 123 456 789 1\n" ]
[ "9.0000000000\n", "10.0000000000\n", "28964.2857142857\n" ]
In the third example there are *n* - *k* + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
0
[ { "input": "3 2\n3 4 7", "output": "9.0000000000" }, { "input": "1 1\n10", "output": "10.0000000000" }, { "input": "8 2\n1 2 4 100000 123 456 789 1", "output": "28964.2857142857" }, { "input": "1 1\n1", "output": "1.0000000000" }, { "input": "1 1\n100000", "ou...
1,565,186,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
n,k = map(int,input().split()) arr = list(map(int,input().split())) acc = sum(arr[0:k]) sleep = acc print(sleep) for i in range(k,n): acc += arr[i] acc -= arr[i-k] sleep += acc print(sleep / (n-k+1))
Title: Average Sleep Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days! When Polycarp went to a doctor with his problem, the doctor asked him about his s...
```python n,k = map(int,input().split()) arr = list(map(int,input().split())) acc = sum(arr[0:k]) sleep = acc print(sleep) for i in range(k,n): acc += arr[i] acc -= arr[i-k] sleep += acc print(sleep / (n-k+1)) ```
0
12
A
Super Agent
PROGRAMMING
800
[ "implementation" ]
A. Super Agent
2
256
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage...
Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
[ "XX.\n...\n.XX\n", "X.X\nX..\n...\n" ]
[ "YES\n", "NO\n" ]
If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry
0
[ { "input": "XX.\n...\n.XX", "output": "YES" }, { "input": ".X.\n.X.\n.X.", "output": "YES" }, { "input": "XXX\nXXX\nXXX", "output": "YES" }, { "input": "XXX\nX.X\nXXX", "output": "YES" }, { "input": "X..\n.X.\n..X", "output": "YES" }, { "input": "...\n...
1,624,457,785
2,147,483,647
Python 3
OK
TESTS
40
154
0
kl=""; for i in range(3): kl+=input(); print(['NO','YES'][kl==kl[::-1]]);
Title: Super Agent Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin...
```python kl=""; for i in range(3): kl+=input(); print(['NO','YES'][kl==kl[::-1]]); ```
3.9615
747
B
Mammoth's Genome Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s...
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
[ "8\nAG?C??CT\n", "4\nAGCT\n", "6\n????G?\n", "4\nAA??\n" ]
[ "AGACGTCT\n", "AGCT\n", "===\n", "===\n" ]
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is ...
1,000
[ { "input": "8\nAG?C??CT", "output": "AGACGTCT" }, { "input": "4\nAGCT", "output": "AGCT" }, { "input": "6\n????G?", "output": "===" }, { "input": "4\nAA??", "output": "===" }, { "input": "4\n????", "output": "ACGT" }, { "input": "252\n???????GCG??T??TT...
1,687,625,853
2,147,483,647
Python 3
OK
TESTS
95
46
0
def solve(s): TYPES = ['A', 'C', 'G', 'T'] letterToCount = {} for ch in s: if ch != '?': letterToCount[ch] = letterToCount.get(ch, 0) + 1 if len(s) % 4 != 0 or any(count * 4 > len(s) for count in letterToCount.values()): return "===" result = [] for ch ...
Title: Mammoth's Genome Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter...
```python def solve(s): TYPES = ['A', 'C', 'G', 'T'] letterToCount = {} for ch in s: if ch != '?': letterToCount[ch] = letterToCount.get(ch, 0) + 1 if len(s) % 4 != 0 or any(count * 4 > len(s) for count in letterToCount.values()): return "===" result = [] ...
3
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,666,046,448
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
# a def test(string): # ybocyboybocyboa for idx, i in enumerate(string): # abacabaabacabaa for j in range(idx + 1, len(string)): if string[idx] == string[j]: string = string.replace(string[idx], '',1) strin...
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 # a def test(string): # ybocyboybocyboa for idx, i in enumerate(string): # abacabaabacabaa for j in range(idx + 1, len(string)): if string[idx] == string[j]: string = string.replace(string[idx], '',1) ...
0
0
none
none
none
0
[ "none" ]
null
null
Farmer John has just given the cows a program to play with! The program contains two integer variables, *x* and *y*, and performs the following operations on a sequence *a*1,<=*a*2,<=...,<=*a**n* of positive integers: 1. Initially, *x*<==<=1 and *y*<==<=0. If, after any step, *x*<=≤<=0 or *x*<=&gt;<=*n*, the program ...
The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The next line contains *n*<=-<=1 space separated integers, *a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output *n*<=-<=1 lines. On the *i*-th line, print the requested value when the program is run on the sequence *i*,<=*a*2,<=*a*3,<=...*a**n*. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4\n2 4 1\n", "3\n1 2\n" ]
[ "3\n6\n8\n", "-1\n-1\n" ]
In the first sample 1. For *i* = 1,  *x* becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d87035805e6f1c669693d86603da6d89c5730833.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *y* becomes 1 + 2 = 3. 1. For *i* = 2,  *x* becomes <img align="middle" class="tex-formula" ...
0
[]
1,630,424,891
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
1,216
26,214,400
import math import time dp=[[float('inf') for i in range(2)] for j in range(200001)] arr=[0]*(200001) def ans(i,val,n,step): if i>=n or i<0: return val if dp[i][step]!=float('inf'): return val+dp[i][step] dp[i][step]=-float('inf') new_idx=i-arr[i] if step else i+arr[i] ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Farmer John has just given the cows a program to play with! The program contains two integer variables, *x* and *y*, and performs the following operations on a sequence *a*1,<=*a*2,<=...,<=*a**n* of positive integers: 1. Initial...
```python import math import time dp=[[float('inf') for i in range(2)] for j in range(200001)] arr=[0]*(200001) def ans(i,val,n,step): if i>=n or i<0: return val if dp[i][step]!=float('inf'): return val+dp[i][step] dp[i][step]=-float('inf') new_idx=i-arr[i] if step else i...
0
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,699,879,425
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n=int(input()) k=0 for i in range(n): a,b,c=map(int,input().split()) if(a==1 and (b==1 or c==1)) or ( b==1 and( c==1 or a==1)) or (c==1 or(a==1 or b==1)): k+=1 print(k)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python n=int(input()) k=0 for i in range(n): a,b,c=map(int,input().split()) if(a==1 and (b==1 or c==1)) or ( b==1 and( c==1 or a==1)) or (c==1 or(a==1 or b==1)): k+=1 print(k) ```
0
554
A
Kyoya and Photobooks
PROGRAMMING
900
[ "brute force", "math", "strings" ]
null
null
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters.
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
[ "a\n", "hi\n" ]
[ "51\n", "76\n" ]
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
250
[ { "input": "a", "output": "51" }, { "input": "hi", "output": "76" }, { "input": "y", "output": "51" }, { "input": "kgan", "output": "126" }, { "input": "zoabkyuvus", "output": "276" }, { "input": "spyemhyznjieyhhbk", "output": "451" }, { "i...
1,446,474,622
622
Python 3
OK
TESTS
33
62
0
a = input() print((len(a)+1) * 25 + 1)
Title: Kyoya and Photobooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b...
```python a = input() print((len(a)+1) * 25 + 1) ```
3
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's we...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li...
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output...
1,693,688,298
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
61
2,764,800
st=int(input()) sec=int(input()) i=0 while(st<=sec): st *=3 sec *=2 i+=1 print(i)
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e...
```python st=int(input()) sec=int(input()) i=0 while(st<=sec): st *=3 sec *=2 i+=1 print(i) ```
-1
907
A
Masha and Bears
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg...
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=&gt;<=*V*2<=&gt;<=*V*3.
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes).
[ "50 30 10 10\n", "100 50 10 21\n" ]
[ "50\n30\n10\n", "-1\n" ]
In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
500
[ { "input": "50 30 10 10", "output": "50\n30\n10" }, { "input": "100 50 10 21", "output": "-1" }, { "input": "100 50 19 10", "output": "100\n50\n19" }, { "input": "99 50 25 49", "output": "100\n99\n49" }, { "input": "3 2 1 1", "output": "4\n3\n1" }, { "...
1,514,038,315
415
Python 3
WRONG_ANSWER
PRETESTS
2
31
5,529,600
a,b,c,d = map(int , input().split()) if 2*c>=d: print(a) print(b) print(d) else: print(-1)
Title: Masha and Bears Time Limit: None seconds Memory Limit: None megabytes Problem Description: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b...
```python a,b,c,d = map(int , input().split()) if 2*c>=d: print(a) print(b) print(d) else: print(-1) ```
0
93
A
Frames
PROGRAMMING
1,700
[ "implementation" ]
A. Frames
2
256
Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well. This time Igor K. got disappointed in ...
The only line contains four integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*<=≤<=109, 1<=≤<=*a*<=≤<=*b*<=≤<=*n*). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.
Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from *a* to *b*.
[ "11 4 3 9\n", "20 5 2 20\n" ]
[ "3\n", "2\n" ]
The images below illustrate statement tests. The first test: <img class="tex-graphics" src="https://espresso.codeforces.com/a0e4ba690dd16e3c68210a28afd82020b23fb605.png" style="max-width: 100.0%;max-height: 100.0%;"/> In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our se...
500
[ { "input": "11 4 3 9", "output": "3" }, { "input": "20 5 2 20", "output": "2" }, { "input": "1 1 1 1", "output": "1" }, { "input": "26 5 2 18", "output": "3" }, { "input": "21 5 1 15", "output": "1" }, { "input": "21 5 1 21", "output": "1" }, {...
1,509,018,860
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
n, m, a, b = map(int, input().split()) a -= 1 if b == n: b += (m - b) % m x, y = a % m, b % m print([1, 2 - (x * y == 0), 3 - (x == y) - (x == y == 0)][min(b // m - a // m, 2)])
Title: Frames Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always ad...
```python n, m, a, b = map(int, input().split()) a -= 1 if b == n: b += (m - b) % m x, y = a % m, b % m print([1, 2 - (x * y == 0), 3 - (x == y) - (x == y == 0)][min(b // m - a // m, 2)]) ```
0
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,687,524,776
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
values_str = input() values_set = set(values_str.split(',')) print(len(values_set))
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 values_str = input() values_set = set(values_str.split(',')) print(len(values_set)) ```
0
0
none
none
none
0
[ "none" ]
null
null
Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «...
В первой строке входных данных записаны два целых числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=100) — количество строк и столбцов в схематичном изображении соответственно. Далее следуют *n* строк по *m* символов в каждой — схематичное изображение горного хребта. Каждый символ схематичного изображения — это либо «.», либо «*»....
Выведите через пробел два целых числа: - величину наибольшего подъёма за день (или 0, если в профиле горного хребта нет ни одного подъёма), - величину наибольшего спуска за день (или 0, если в профиле горного хребта нет ни одного спуска).
[ "6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********\n", "5 5\n....*\n...**\n..***\n.****\n*****\n", "8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******\n" ]
[ "3 4\n", "1 0\n", "6 2\n" ]
В первом тестовом примере высоты гор равны: 3, 4, 1, 1, 2, 1, 1, 1, 2, 5, 1. Наибольший подъем равен 3 и находится между горой номер 9 (её высота равна 2) и горой номер 10 (её высота равна 5). Наибольший спуск равен 4 и находится между горой номер 10 (её высота равна 5) и горой номер 11 (её высота равна 1). Во втором ...
0
[ { "input": "6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********", "output": "3 4" }, { "input": "5 5\n....*\n...**\n..***\n.****\n*****", "output": "1 0" }, { "input": "8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******", "outpu...
1,458,745,532
332
Python 3
OK
TESTS
107
62
5,120,000
def main(): n, m = [int(i) for i in input().split()] d = [list(input()) for i in range(n)] a = [0] * m for i in range(m): for j in range(n): if d[j][i] == '*': a[i] += 1 x = y = 0 for i in range(1, m): if a[i] > a[i - 1]: x = max(...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо...
```python def main(): n, m = [int(i) for i in input().split()] d = [list(input()) for i in range(n)] a = [0] * m for i in range(m): for j in range(n): if d[j][i] == '*': a[i] += 1 x = y = 0 for i in range(1, m): if a[i] > a[i - 1]...
3
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin...
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord...
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3...
1,670,132,760
2,147,483,647
Python 3
OK
TESTS
45
46
0
n,d=map(int,input().split()) m=list(map(int,input().split())) k,c = 0,2 for i in range(n-1): k = abs(m[i]-m[i+1]) if k > 2*d: c+=2 if k==2*d: c+=1 print(c)
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer c...
```python n,d=map(int,input().split()) m=list(map(int,input().split())) k,c = 0,2 for i in range(n-1): k = abs(m[i]-m[i+1]) if k > 2*d: c+=2 if k==2*d: c+=1 print(c) ```
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,600,379,807
2,147,483,647
PyPy 3
OK
TESTS
40
124
0
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1]))#might need to remove the -1 def invr(): return(map(int,input...
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 import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1]))#might need to remove the -1 def invr(): return(map...
3.938
886
A
ACM ICPC
PROGRAMMING
1,000
[ "brute force" ]
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.
500
[ { "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,653,786,683
2,147,483,647
PyPy 3-64
OK
TESTS
53
62
0
a = [int(x) for x in input().split()] sa = sum(a) if sa % 2 != 0: print('NO') exit() for i in range(64): total = 0 c = 0 for b in range(6): if ((i >> b) & 1) == 1: total += a[b] c += 1 if c != 3: continue if total == sa // 2: ...
Title: ACM ICPC 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 ...
```python a = [int(x) for x in input().split()] sa = sum(a) if sa % 2 != 0: print('NO') exit() for i in range(64): total = 0 c = 0 for b in range(6): if ((i >> b) & 1) == 1: total += a[b] c += 1 if c != 3: continue if total == sa ...
3
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for...
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhe...
1,681,128,185
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
409,600
import sys, string s=sys.stdin.readline().strip() y=sys.stdin.readline().strip() s=''.join(list(dict.fromkeys(s))) print("impossible" if int(y) > len(s) else int(y)-len(s[:int(y)]))
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it...
```python import sys, string s=sys.stdin.readline().strip() y=sys.stdin.readline().strip() s=''.join(list(dict.fromkeys(s))) print("impossible" if int(y) > len(s) else int(y)-len(s[:int(y)])) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,621,108,170
2,147,483,647
Python 3
OK
TESTS
32
124
0
n=int(input()) nas=list(map(int,input().split())) ctr=0 mtr=0 ct=[] mt=[] for i in range(len(nas)): if nas[i]%2: ctr+=1 ct.append(i) else: mtr+=1 mt.append(i) if ctr>=1 and mtr>=1: if ctr<mtr: print(ct[-1]+1) break elif...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n=int(input()) nas=list(map(int,input().split())) ctr=0 mtr=0 ct=[] mt=[] for i in range(len(nas)): if nas[i]%2: ctr+=1 ct.append(i) else: mtr+=1 mt.append(i) if ctr>=1 and mtr>=1: if ctr<mtr: print(ct[-1]+1) break ...
3.969
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,691,727,985
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n, m, a = map(int, input().split()) # Calculate the number of flagstones needed if n%a ==0: horizontal_flagstones = (n//a) else: horizontal_flagstones = (n // a)+1 if n%a ==0: vertical_flagstones = (n//a) else: vertical_flagstones = (n // a)+1 # Calculate the total number of flagstones ...
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 n, m, a = map(int, input().split()) # Calculate the number of flagstones needed if n%a ==0: horizontal_flagstones = (n//a) else: horizontal_flagstones = (n // a)+1 if n%a ==0: vertical_flagstones = (n//a) else: vertical_flagstones = (n // a)+1 # Calculate the total number of flag...
0
382
B
Number Busters
PROGRAMMING
2,000
[ "binary search", "math" ]
null
null
Arthur and Alexander are number busters. Today they've got a competition. Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=≤<=*b*<=&lt;<=*w*,<=0<=&lt;<=*x*<=&lt;<=*w*) and Alexander took integer *с*. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each s...
The first line contains integers *a*,<=*b*,<=*w*,<=*x*,<=*c* (1<=≤<=*a*<=≤<=2·109,<=1<=≤<=*w*<=≤<=1000,<=0<=≤<=*b*<=&lt;<=*w*,<=0<=&lt;<=*x*<=&lt;<=*w*,<=1<=≤<=*c*<=≤<=2·109).
Print a single integer — the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits.
[ "4 2 3 1 6\n", "4 2 3 1 7\n", "1 2 3 2 6\n", "1 1 2 1 1\n" ]
[ "2\n", "4\n", "13\n", "0\n" ]
none
2,500
[ { "input": "4 2 3 1 6", "output": "2" }, { "input": "4 2 3 1 7", "output": "4" }, { "input": "1 2 3 2 6", "output": "13" }, { "input": "1 1 2 1 1", "output": "0" }, { "input": "1 0 1000 999 2000000000", "output": "1999999999000" }, { "input": "10 1 6 4...
1,389,977,922
5,322
Python 3
WRONG_ANSWER
PRETESTS
7
61
409,600
a,b,w,x,c = map(int,input().split()) poc = 0 s = set() s.add(b) pa,pb,pc = a,b,c while (c > a) : c -= 1 if b >= x: b = b-x else: a -= 1 b = w - (x-b) if b in s: kolko = len(s) break s.add(b) dl = len(s) kolko = pa-a roz = max(pc - pa - 2,0) poc = roz*dl c = pc - poc a = pa - roz*kolko b = pb #a,b,c,poc=p...
Title: Number Busters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arthur and Alexander are number busters. Today they've got a competition. Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=≤<=*b*<=&lt;<=*w*,<=0<=&lt;<=*x*<=&lt;<=*w*) and Alexander took integer *с*. Arth...
```python a,b,w,x,c = map(int,input().split()) poc = 0 s = set() s.add(b) pa,pb,pc = a,b,c while (c > a) : c -= 1 if b >= x: b = b-x else: a -= 1 b = w - (x-b) if b in s: kolko = len(s) break s.add(b) dl = len(s) kolko = pa-a roz = max(pc - pa - 2,0) poc = roz*dl c = pc - poc a = pa - roz*kolko b = pb #a...
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,668,364,654
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
# f=open('Documents/projects/CPDev/input.txt','r') # def get_int():return list(map(int,f.readline().split())) # def get_list(n): return [f.readline().split() for _ in range(n)] def get_list(n): return list(input().split() for _ in range(n)) def get_int():return list(map(int,input().strip().split())) n,m = get_int() ...
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python # f=open('Documents/projects/CPDev/input.txt','r') # def get_int():return list(map(int,f.readline().split())) # def get_list(n): return [f.readline().split() for _ in range(n)] def get_list(n): return list(input().split() for _ in range(n)) def get_int():return list(map(int,input().strip().split())) n,m = ...
0
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,694,670,238
2,147,483,647
Python 3
OK
TESTS
34
46
0
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ m = int(input()) s = 1 while m > 5: m -= 5 s += 1 print(s)
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python # -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ m = int(input()) s = 1 while m > 5: m -= 5 s += 1 print(s) ```
3
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s...
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch...
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,609,909,254
2,147,483,647
PyPy 3
OK
TESTS
26
155
0
n, limit = map(int, input().split()) lst = list(map(int, input().split())) s = sum(lst) + (n - 1) * 10 if s > limit: print(-1) else: print(2 * (n - 1) + (limit - s) // 5)
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit...
```python n, limit = map(int, input().split()) lst = list(map(int, input().split())) s = sum(lst) + (n - 1) * 10 if s > limit: print(-1) else: print(2 * (n - 1) + (limit - s) // 5) ```
3
508
A
Pasha and Pixels
PROGRAMMING
1,100
[ "brute force" ]
null
null
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos...
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*...
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
[ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n" ]
[ "4\n", "5\n", "0\n" ]
none
500
[ { "input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4" }, { "input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5" }, { "input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0" }, { "input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3", ...
1,698,126,974
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n,m,k=map(int,input(),split()) x=[(m+2)*[0] for i in range(n+2)] def check(i,j): if x[i][j+1]==1 and x[i+1][j]==1 and x[i+1][j+1]==1: return True if x[i][j-1]==1 and x[i+1][j]==1 and x[i+1][j-1]==1: return True if x[i-1][j]==1 and x[i][j+1]==1 and x[i-1][j+1]==1: return Tru...
Title: Pasha and Pixels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ...
```python n,m,k=map(int,input(),split()) x=[(m+2)*[0] for i in range(n+2)] def check(i,j): if x[i][j+1]==1 and x[i+1][j]==1 and x[i+1][j+1]==1: return True if x[i][j-1]==1 and x[i+1][j]==1 and x[i+1][j-1]==1: return True if x[i-1][j]==1 and x[i][j+1]==1 and x[i-1][j+1]==1: ...
-1
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 58697...
1,693,939,260
2,147,483,647
PyPy 3
OK
TESTS
34
186
0
nums = input().split() copy = [] for i in range(4): if nums[i] not in copy: copy.append(nums[i]) ans = 4 - len(copy) print(ans)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ...
```python nums = input().split() copy = [] for i in range(4): if nums[i] not in copy: copy.append(nums[i]) ans = 4 - len(copy) print(ans) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,585,588,871
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
80
218
0
x=int(input()) s=0 for i in range(x): y=list(map(int,input().split())) s=s+sum(y) if s==0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python x=int(input()) s=0 for i in range(x): y=list(map(int,input().split())) s=s+sum(y) if s==0: print('YES') else: print('NO') ```
0
33
A
What is for dinner?
PROGRAMMING
1,200
[ "greedy", "implementation" ]
A. What is for dinner?
2
256
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where bel...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
[ "4 3 18\n2 3\n1 2\n3 6\n2 3\n", "2 2 13\n1 13\n2 12\n" ]
[ "11\n", "13\n" ]
none
500
[ { "input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11" }, { "input": "2 2 13\n1 13\n2 12", "output": "13" }, { "input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3", "output": "8" }, { "input": "1 1 0\n1 3", "output": "0" }, { "input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 1...
1,593,772,371
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
186
307,200
R=lambda:map(int,input().split()) s=sorted n,k=R() _,u,v,w=l=[[],[],[],[]] for _ in[0]*n:t,a,b=R();l[2*a+b]+=t, a=*map(sum,zip(s(u),s(v))),*w print(sum((s(a)+[-sum(a)-1])[:k]))
Title: What is for dinner? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that...
```python R=lambda:map(int,input().split()) s=sorted n,k=R() _,u,v,w=l=[[],[],[],[]] for _ in[0]*n:t,a,b=R();l[2*a+b]+=t, a=*map(sum,zip(s(u),s(v))),*w print(sum((s(a)+[-sum(a)-1])[:k])) ```
-1
719
B
Anatoly and Cockroaches
PROGRAMMING
1,400
[ "greedy" ]
null
null
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room. Anatoly just made all his cockroaches to form a single line. As he is a perfectio...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches. The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
[ "5\nrbbrr\n", "5\nbbbbb\n", "3\nrbr\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this. In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns. In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ...
1,000
[ { "input": "5\nrbbrr", "output": "1" }, { "input": "5\nbbbbb", "output": "2" }, { "input": "3\nrbr", "output": "0" }, { "input": "13\nrbbbrbrrbrrbb", "output": "3" }, { "input": "18\nrrrrrrrrrrrrrrrrrb", "output": "8" }, { "input": "100\nbrbbbrrrbbrbrb...
1,632,674,400
2,147,483,647
PyPy 3
OK
TESTS
46
124
22,323,200
def calc(s,i): c=[0,0] for x in range(len(s)): if s[x]!=i[x]:c[x%2]+=1 return max(c) n=int(input());s=input() i1=('rb'*(n//2+1))[:n] i2=('br'*(n//2+1))[:n] print(min(calc(s,i1),calc(s,i2)))
Title: Anatoly and Cockroaches Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches...
```python def calc(s,i): c=[0,0] for x in range(len(s)): if s[x]!=i[x]:c[x%2]+=1 return max(c) n=int(input());s=input() i1=('rb'*(n//2+1))[:n] i2=('br'*(n//2+1))[:n] print(min(calc(s,i1),calc(s,i2))) ```
3
202
A
LLPS
PROGRAMMING
800
[ "binary search", "bitmasks", "brute force", "greedy", "implementation", "strings" ]
null
null
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*...
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Print the lexicographically largest palindromic subsequence of string *s*.
[ "radar\n", "bowwowwow\n", "codeforces\n", "mississipp\n" ]
[ "rr\n", "wwwww\n", "s\n", "ssss\n" ]
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
500
[ { "input": "radar", "output": "rr" }, { "input": "bowwowwow", "output": "wwwww" }, { "input": "codeforces", "output": "s" }, { "input": "mississipp", "output": "ssss" }, { "input": "tourist", "output": "u" }, { "input": "romka", "output": "r" }, ...
1,564,850,974
2,147,483,647
Python 3
OK
TESTS
54
218
0
# import sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out","w") a=list(map(ord,input())) b=max(a) print(chr(b)*a.count(b))
Title: LLPS Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ...
```python # import sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out","w") a=list(map(ord,input())) b=max(a) print(chr(b)*a.count(b)) ```
3
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nck...
1,695,759,625
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
17
46
6,348,800
l=[];x=int(input());c=0;l2=[] for i in range(x): z=input() l.append(z) for i in range(x-1): if l[i][i]== l[i+1][i+1]: c+=1 for i in l: for j in i: l2.append(j) if c == x-1 and len(set(l2))==2: print("YES") else: print("NO")
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a...
```python l=[];x=int(input());c=0;l2=[] for i in range(x): z=input() l.append(z) for i in range(x-1): if l[i][i]== l[i+1][i+1]: c+=1 for i in l: for j in i: l2.append(j) if c == x-1 and len(set(l2))==2: print("YES") else: print("NO") ```
0
472
D
Design Tutorial: Inverse the Problem
PROGRAMMING
1,900
[ "dfs and similar", "dsu", "shortest paths", "trees" ]
null
null
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example. Now ...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000) — the number of nodes in that graph. Then next *n* lines each contains *n* integers *d**i*,<=*j* (0<=≤<=*d**i*,<=*j*<=≤<=109) — the distance between node *i* and node *j*.
If there exists such a tree, output "YES", otherwise output "NO".
[ "3\n0 2 7\n2 0 9\n7 9 0\n", "3\n1 2 7\n2 0 9\n7 9 0\n", "3\n0 2 2\n7 0 9\n7 9 0\n", "3\n0 1 1\n1 0 1\n1 1 0\n", "2\n0 0\n0 0\n" ]
[ "YES\n", "NO\n", "NO\n", "NO\n", "NO\n" ]
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7. In the second example, it is impossible because *d*<sub class="lower-index">1, 1</sub> should be 0, but it is 1. In the third example, it is impossible because *d*<sub...
2,000
[ { "input": "3\n0 2 7\n2 0 9\n7 9 0", "output": "YES" }, { "input": "3\n1 2 7\n2 0 9\n7 9 0", "output": "NO" }, { "input": "3\n0 2 2\n7 0 9\n7 9 0", "output": "NO" }, { "input": "3\n0 1 1\n1 0 1\n1 1 0", "output": "NO" }, { "input": "2\n0 0\n0 0", "output": "NO...
1,690,484,802
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
61
0
print("_RANDOM_GUESS_1690484802.8884575")# 1690484802.8884773
Title: Design Tutorial: Inverse the Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original probl...
```python print("_RANDOM_GUESS_1690484802.8884575")# 1690484802.8884773 ```
0
199
A
Hexadecimal's theorem
PROGRAMMING
900
[ "brute force", "constructive algorithms", "implementation", "number theory" ]
null
null
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F...
The input contains of a single integer *n* (0<=≤<=*n*<=&lt;<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them.
[ "3\n", "13\n" ]
[ "1 1 1\n", "2 3 8\n" ]
none
500
[ { "input": "3", "output": "1 1 1" }, { "input": "13", "output": "2 3 8" }, { "input": "0", "output": "0 0 0" }, { "input": "1", "output": "1 0 0" }, { "input": "2", "output": "1 1 0" }, { "input": "1597", "output": "233 377 987" }, { "input...
1,609,539,519
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
280
0
ser = [0, 1] def fib(n): i = 1 while i < n: ser.append(i) i = ser[-1] + ser[-2] if i != n: return -1 else: return len(ser) n = int(input()) a, b, c = 0, 0, 0 ans = 1 if n == 1: a = 1 elif n == 2: a = 1 b = 1 elif n == 3: a = 1 b =...
Title: Hexadecimal's theorem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let'...
```python ser = [0, 1] def fib(n): i = 1 while i < n: ser.append(i) i = ser[-1] + ser[-2] if i != n: return -1 else: return len(ser) n = int(input()) a, b, c = 0, 0, 0 ans = 1 if n == 1: a = 1 elif n == 2: a = 1 b = 1 elif n == 3: a = ...
0
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,676,539,978
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
1,843,200
import math a,b = input().split() c = math.factorial(int(a)) d = math.factorial(int(b)) print(math.gcd(c,d))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi...
```python import math a,b = input().split() c = math.factorial(int(a)) d = math.factorial(int(b)) print(math.gcd(c,d)) ```
0
71
B
Progress Bar
PROGRAMMING
1,300
[ "implementation", "math" ]
B. Progress Bar
1
256
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar. A bar is represented as *n* squares, located in line. To add clarity, let's number them with positive integers from 1 to *n* fr...
We are given 3 space-separated integers *n*, *k*, *t* (1<=≤<=*n*,<=*k*<=≤<=100, 0<=≤<=*t*<=≤<=100).
Print *n* numbers. The *i*-th of them should be equal to *a**i*.
[ "10 10 54\n", "11 13 37\n" ]
[ "10 10 10 10 10 4 0 0 0 0 ", "13 13 13 13 0 0 0 0 0 0 0 " ]
none
1,000
[ { "input": "10 10 54", "output": "10 10 10 10 10 4 0 0 0 0 " }, { "input": "11 13 37", "output": "13 13 13 13 0 0 0 0 0 0 0 " }, { "input": "9 25 50", "output": "25 25 25 25 12 0 0 0 0 " }, { "input": "43 47 77", "output": "47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 ...
1,680,593,347
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
import numpy nkt = list(map(int,input().strip().split())) n = nkt[0] k = nkt[1] t = nkt[2] print(n,k,t) add=0 z=n total = n*k list1 = [] cal = 0 while n != 0: if cal < t: list1.append(k) add = sum(list1) # print(add) cal = ((add+k)/total)*100 n -= 1 ...
Title: Progress Bar Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar. A bar is represented as *n* squar...
```python import numpy nkt = list(map(int,input().strip().split())) n = nkt[0] k = nkt[1] t = nkt[2] print(n,k,t) add=0 z=n total = n*k list1 = [] cal = 0 while n != 0: if cal < t: list1.append(k) add = sum(list1) # print(add) cal = ((add+k)/total)*100 n -= 1...
-1
265
B
Roadside Trees (Simplified Edition)
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol...
The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees. Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*.
Print a single integer — the minimal time required to eat all nuts in seconds.
[ "2\n1\n2\n", "5\n2\n1\n2\n1\n1\n" ]
[ "5\n", "14\n" ]
none
1,000
[ { "input": "2\n1\n2", "output": "5" }, { "input": "5\n2\n1\n2\n1\n1", "output": "14" }, { "input": "1\n1", "output": "2" } ]
1,626,610,844
2,147,483,647
Python 3
OK
TESTS
15
434
6,963,200
n = int(input()) total = 0 h = int(input()) total += h + 1 cur = h for i in range(n-1): hi = int(input()) if h > hi: total += h-hi #d own total += 1 # jump total += 1 # eat else: total += 1 # jump diff = hi-h total += diff # up total +...
Title: Roadside Trees (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wan...
```python n = int(input()) total = 0 h = int(input()) total += h + 1 cur = h for i in range(n-1): hi = int(input()) if h > hi: total += h-hi #d own total += 1 # jump total += 1 # eat else: total += 1 # jump diff = hi-h total += diff # up ...
3
152
A
Marks
PROGRAMMING
900
[ "implementation" ]
null
null
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at ...
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa...
Print the single number — the number of successful students in the given group.
[ "3 3\n223\n232\n112\n", "3 5\n91728\n11828\n11111\n" ]
[ "2\n", "3\n" ]
In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject. In the second sample test each student is the best at at least one subject.
500
[ { "input": "3 3\n223\n232\n112", "output": "2" }, { "input": "3 5\n91728\n11828\n11111", "output": "3" }, { "input": "2 2\n48\n27", "output": "1" }, { "input": "2 1\n4\n6", "output": "1" }, { "input": "1 2\n57", "output": "1" }, { "input": "1 1\n5", ...
1,525,028,523
2,147,483,647
PyPy 3
OK
TESTS
44
109
22,016,000
n,m = map(int, input().split()) a = [0]*(n) ss = [[] for _ in range(m)] for i in range(n): s = list(input()) for j in range(m): ss[j].append(s[j]) for i in range(m): mx = max(ss[i]) for j in range(n): if ss[i][j] == mx: a[j] = 1 print(sum(a))
Title: Marks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student ...
```python n,m = map(int, input().split()) a = [0]*(n) ss = [[] for _ in range(m)] for i in range(n): s = list(input()) for j in range(m): ss[j].append(s[j]) for i in range(m): mx = max(ss[i]) for j in range(n): if ss[i][j] == mx: a[j] = 1 print(sum(a)) ```
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }...
1,540,240,345
2,147,483,647
Python 3
OK
TESTS
43
218
0
a = input() b = input() c = int(a) + int(b) def rz( n ): n = str(n) ret = "" for i in n: if i != "0": ret += i return ( ret ) if int( rz(a) ) + int( rz(b) ) == int( rz(c) ): print( "YES" ) else: print( "NO" )
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu...
```python a = input() b = input() c = int(a) + int(b) def rz( n ): n = str(n) ret = "" for i in n: if i != "0": ret += i return ( ret ) if int( rz(a) ) + int( rz(b) ) == int( rz(c) ): print( "YES" ) else: print( "NO" ) ```
3.9455
180
C
Letter
PROGRAMMING
1,400
[ "dp" ]
null
null
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to...
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Print a single number — the least number of actions needed to make the message fancy.
[ "PRuvetSTAaYA\n", "OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n", "helloworld\n" ]
[ "5\n", "0\n", "0\n" ]
none
0
[ { "input": "PRuvetSTAaYA", "output": "5" }, { "input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA", "output": "0" }, { "input": "helloworld", "output": "0" }, { "input": "P", "output": "0" }, { "input": "t", "output": "0" }, { "input": "XdJ", "output": "1...
1,685,634,086
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
s_new = input() # 将原有的变量名s改为更具意义的s_new n = len(s_new) prefix_num = 0 # 将prefix改为具体说明其含义的prefix_num suffix_num = 0 # 将suffix改为具体说明其含义的suffix_num ans = float('inf') for i in range(n): if 'a' <= s_new[i] <= 'z': prefix_num += 1 for i in range(n - 1, -1, -1): if 'A' <= s_new[i] <= 'Z': suffix...
Title: Letter Time Limit: None seconds Memory Limit: None megabytes Problem Description: Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them...
```python s_new = input() # 将原有的变量名s改为更具意义的s_new n = len(s_new) prefix_num = 0 # 将prefix改为具体说明其含义的prefix_num suffix_num = 0 # 将suffix改为具体说明其含义的suffix_num ans = float('inf') for i in range(n): if 'a' <= s_new[i] <= 'z': prefix_num += 1 for i in range(n - 1, -1, -1): if 'A' <= s_new[i] <= 'Z': ...
-1
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are...
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { ...
1,607,687,141
2,147,483,647
Python 3
OK
TESTS
43
140
0
a = list(input()) count = 0 t = 0 for i in range(0, len(a)): for j in range(i, len(a)): for k in range(j, len(a)): if a[i] == "Q" and a[j] == "A" and a[k] == "Q": count += 1 print(count)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"...
```python a = list(input()) count = 0 t = 0 for i in range(0, len(a)): for j in range(i, len(a)): for k in range(j, len(a)): if a[i] == "Q" and a[j] == "A" and a[k] == "Q": count += 1 print(count) ```
3
916
A
Jamie and Alarm Snooze
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He ...
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60). The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59).
Print the minimum number of times he needs to press the button.
[ "3\n11 23\n", "5\n01 07\n" ]
[ "2\n", "0\n" ]
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
500
[ { "input": "3\n11 23", "output": "2" }, { "input": "5\n01 07", "output": "0" }, { "input": "34\n09 24", "output": "3" }, { "input": "2\n14 37", "output": "0" }, { "input": "14\n19 54", "output": "9" }, { "input": "42\n15 44", "output": "12" }, ...
1,617,269,633
2,147,483,647
PyPy 3
OK
TESTS
254
156
4,710,400
import datetime n = int(input()) a , b = input().split() x = datetime.timedelta(hours= int(a) , minutes=int(b)) c = 0 while '7' not in str(x): x -= datetime.timedelta(hours= 0 , minutes=n) c +=1 print(c)
Title: Jamie and Alarm Snooze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will the...
```python import datetime n = int(input()) a , b = input().split() x = datetime.timedelta(hours= int(a) , minutes=int(b)) c = 0 while '7' not in str(x): x -= datetime.timedelta(hours= 0 , minutes=n) c +=1 print(c) ```
3
902
A
Visiting a Friend
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ...
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "3 5\n0 2\n2 4\n3 5\n", "3 7\n0 4\n2 5\n6 7\n" ]
[ "YES\n", "NO\n" ]
The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You...
500
[ { "input": "3 5\n0 2\n2 4\n3 5", "output": "YES" }, { "input": "3 7\n0 4\n2 5\n6 7", "output": "NO" }, { "input": "1 1\n0 0", "output": "NO" }, { "input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7...
1,513,750,980
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
5,529,600
x = input().split() tel = int(x[0]) target = int(x[1]) join = True prev = 0 for i in range(tel): y = input().split() now = int(y[0]) if now > prev: join = False prev = int(y[1]) if join == True and prev >= target: print("YES") else: print("NO")
Title: Visiting a Friend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain ...
```python x = input().split() tel = int(x[0]) target = int(x[1]) join = True prev = 0 for i in range(tel): y = input().split() now = int(y[0]) if now > prev: join = False prev = int(y[1]) if join == True and prev >= target: print("YES") else: print("NO") ```
0
821
A
Okabe and Future Gadget Laboratory
PROGRAMMING
800
[ "implementation" ]
null
null
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ...
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab. The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105).
Print "Yes" if the given lab is good and "No" otherwise. You can output each letter in upper or lower case.
[ "3\n1 1 2\n2 3 1\n6 4 1\n", "3\n1 5 2\n1 1 1\n1 2 3\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes". In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an inte...
500
[ { "input": "3\n1 1 2\n2 3 1\n6 4 1", "output": "Yes" }, { "input": "3\n1 5 2\n1 1 1\n1 2 3", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1", "output": "Yes" }, { "input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2...
1,579,283,951
2,147,483,647
Python 3
OK
TESTS
31
109
307,200
n=int(input()) l=[list(map(int,input().split())) for _ in range(n)] flag=0 for i in range(n): for j in range(n): if( l[i][j]==1 )or any(l[i][j]-l[x][j] in l[i] for x in range(n)): continue else: print('No') flag=1 break if(flag==1): ...
Title: Okabe and Future Gadget Laboratory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in whi...
```python n=int(input()) l=[list(map(int,input().split())) for _ in range(n)] flag=0 for i in range(n): for j in range(n): if( l[i][j]==1 )or any(l[i][j]-l[x][j] in l[i] for x in range(n)): continue else: print('No') flag=1 break if(flag...
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,686,053,705
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
n = int(input()) sum1 = sum2 = sum3 = 0 for _ in range(n): row = list(map(int,input().split())) sum1 += row[0] sum2 += row[1] sum3 += row[2] if sum1==0 or sum2==0 or sum3==0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n = int(input()) sum1 = sum2 = sum3 = 0 for _ in range(n): row = list(map(int,input().split())) sum1 += row[0] sum2 += row[1] sum3 += row[2] if sum1==0 or sum2==0 or sum3==0: print("YES") else: print("NO") ```
0
221
A
Little Elephant and Function
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works...
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists.
[ "1\n", "2\n" ]
[ "1 ", "2 1 " ]
none
500
[ { "input": "1", "output": "1 " }, { "input": "2", "output": "2 1 " }, { "input": "3", "output": "3 1 2 " }, { "input": "4", "output": "4 1 2 3 " }, { "input": "5", "output": "5 1 2 3 4 " }, { "input": "6", "output": "6 1 2 3 4 5 " }, { "inp...
1,645,195,420
2,147,483,647
PyPy 3
OK
TESTS
34
186
1,433,600
# Bismillahir Rahmanir Rahim # Abu Hurayra - Handle: HurayraIIT import sys import math def mp(): return map(int, sys.stdin.readline().split()) def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.s...
Title: Little Elephant and Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm...
```python # Bismillahir Rahmanir Rahim # Abu Hurayra - Handle: HurayraIIT import sys import math def mp(): return map(int, sys.stdin.readline().split()) def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws...
3
994
B
Knights of a Polygonal Table
PROGRAMMING
1,400
[ "greedy", "implementation", "sortings" ]
null
null
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo...
The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement. The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct. The third line contains $n...
Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights.
[ "4 2\n4 5 9 7\n1 2 11 33\n", "5 1\n1 2 3 4 5\n1 2 3 4 5\n", "1 0\n2\n3\n" ]
[ "1 3 46 36 ", "1 3 5 7 9 ", "3 " ]
Consider the first example. - The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o...
1,000
[ { "input": "4 2\n4 5 9 7\n1 2 11 33", "output": "1 3 46 36 " }, { "input": "5 1\n1 2 3 4 5\n1 2 3 4 5", "output": "1 3 5 7 9 " }, { "input": "1 0\n2\n3", "output": "3 " }, { "input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9", "output": "0 3 10 16 14 17 18 " }, { "input"...
1,529,169,672
2,772
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
7
1,000
9,728,000
n,k = input().split() n = int(n) k = int(k) a = input().split() b = input().split() final = "" for i in range(len(a)): a[i] = int(a[i]) for i in range(len(b)): b[i] = int(b[i]) for i in range(n): ans = b[i] coins = [] for j in range(n): if a[i] != a[j]: if a[j] <...
Title: Knights of a Polygonal Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ...
```python n,k = input().split() n = int(n) k = int(k) a = input().split() b = input().split() final = "" for i in range(len(a)): a[i] = int(a[i]) for i in range(len(b)): b[i] = int(b[i]) for i in range(n): ans = b[i] coins = [] for j in range(n): if a[i] != a[j]: ...
0
571
C
CNF 2
PROGRAMMING
2,500
[ "constructive algorithms", "dfs and similar", "graphs", "greedy" ]
null
null
'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals' (cited from https://en.wikipedia.org/wiki/Conjunctive_normal_form) In the other words, CNF is a formula of type , where &amp; represents a logical "AND...
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of clauses and the number variables, correspondingly. Next *n* lines contain the descriptions of each clause. The *i*-th line first contains first number *k**i* (*k**i*<=≥<=1) — the number of literals in the *i*-th clauses. Then foll...
If CNF is not satisfiable, print a single line "NO" (without the quotes), otherwise print two strings: string "YES" (without the quotes), and then a string of *m* numbers zero or one — the values of variables in satisfying assignment in the order from *x*1 to *x**m*.
[ "2 2\n2 1 -2\n2 2 -1\n", "4 3\n1 1\n1 2\n3 -1 -2 3\n1 -3\n", "5 6\n2 1 2\n3 1 -2 3\n4 -3 5 4 6\n2 -6 -4\n1 5\n" ]
[ "YES\n11\n", "NO\n", "YES\n100010\n" ]
In the first sample test formula is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a8654a57efa13b47a585b7998c9defb42712ded.png" style="max-width: 100.0%;max-height: 100.0%;"/>. One of possible answer is *x*<sub class="lower-index">1</sub> = *TRUE*, *x*<sub class="lower-index">2</sub> = *T...
1,500
[]
1,441,689,853
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
38,092,800
from itertools import * ent=input() n=int(ent.split()[0]) m=int(ent.split()[1]) form=[] for i in range (n): ent=input() k=int(ent.split()[0]) claus=[] for i in range (1,k+1): claus.append(int(ent.split()[i])) form.append(claus) #print(form) def noref(formula): formul=[] ...
Title: CNF 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: 'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals' (cited from https://en.wikipedia.org/wiki/Conjunctive_normal_...
```python from itertools import * ent=input() n=int(ent.split()[0]) m=int(ent.split()[1]) form=[] for i in range (n): ent=input() k=int(ent.split()[0]) claus=[] for i in range (1,k+1): claus.append(int(ent.split()[i])) form.append(claus) #print(form) def noref(formula): fo...
0
342
C
Cupboard and Balloons
PROGRAMMING
1,900
[ "geometry" ]
null
null
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is *r*, that is, it looks like a rectangle with base *r* and height *h*<=+<=*r* from the sides. The figure be...
The single line contains two integers *r*,<=*h* (1<=≤<=*r*,<=*h*<=≤<=107).
Print a single integer — the maximum number of balloons Xenia can put in the cupboard.
[ "1 1\n", "1 2\n", "2 1\n" ]
[ "3\n", "5\n", "2\n" ]
none
1,500
[ { "input": "1 1", "output": "3" }, { "input": "1 2", "output": "5" }, { "input": "2 1", "output": "2" }, { "input": "2 2", "output": "3" }, { "input": "2 3", "output": "4" }, { "input": "4 1", "output": "1" }, { "input": "5 1", "output"...
1,380,005,207
1,907
Python 3
OK
TESTS
48
124
0
r, h = map(int, input().split()) a = 1 + 2 * h // r if h % r >=3 ** 0.5 * r / 2: a += 1 print(a)
Title: Cupboard and Balloons Time Limit: None seconds Memory Limit: None megabytes Problem Description: A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is...
```python r, h = map(int, input().split()) a = 1 + 2 * h // r if h % r >=3 ** 0.5 * r / 2: a += 1 print(a) ```
3
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,649,173,592
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
a,b = map(int,input().split()) c = input() count = [0] * 26 for i in c: if 'a'<=i<='z': nomer = ord(i) - 97 count[nomer]+=1 f = 0 d = 0 for i in range(26): if count[i]>0: if count[i]!=b: f +=1 else: d +=1 if d > f: print('YES') else: print('NO')
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 a,b = map(int,input().split()) c = input() count = [0] * 26 for i in c: if 'a'<=i<='z': nomer = ord(i) - 97 count[nomer]+=1 f = 0 d = 0 for i in range(26): if count[i]>0: if count[i]!=b: f +=1 else: d +=1 if d > f: print('YES') else: print('NO') ```
0
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,650,886,328
2,147,483,647
Python 3
OK
TESTS
20
31
0
a,b,c=map(int,input().split()) n=a//c; if (a%c>0): n=n+1 m=b//c if (b%c>0): m=m+1 print(n*m)
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 a,b,c=map(int,input().split()) n=a//c; if (a%c>0): n=n+1 m=b//c if (b%c>0): m=m+1 print(n*m) ```
3.9845
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,684,368,323
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
46
0
import sys input=sys.stdin.readline n=int(input()) if n%2: print( 9, n-9 ) else: print( n//2, n//2 )
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 import sys input=sys.stdin.readline n=int(input()) if n%2: print( 9, n-9 ) else: print( n//2, n//2 ) ```
0
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894"...
1,623,504,071
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
500
0
n,k = input("").rsplit() n,k=int(n),int(k) x =n+1 while x% k !=0: x+=1 print(x)
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *...
```python n,k = input("").rsplit() n,k=int(n),int(k) x =n+1 while x% k !=0: x+=1 print(x) ```
0
887
A
Div. 64
PROGRAMMING
1,000
[ "implementation" ]
null
null
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi...
In the only line given a non-empty binary string *s* with length up to 100.
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
[ "100010001\n", "100\n" ]
[ "yes", "no" ]
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system. You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system)
500
[ { "input": "100010001", "output": "yes" }, { "input": "100", "output": "no" }, { "input": "0000001000000", "output": "yes" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "no" }, { "in...
1,659,342,097
2,147,483,647
PyPy 3
OK
TESTS
98
93
0
a=int(input()) s=str(a) count=0 for i in s: if i=="0": count+=1 if (count>=6): print("yes") else: print("no")
Title: Div. 64 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig...
```python a=int(input()) s=str(a) count=0 for i in s: if i=="0": count+=1 if (count>=6): print("yes") else: print("no") ```
3
900
B
Position in Fraction
PROGRAMMING
1,300
[ "math", "number theory" ]
null
null
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=&lt;<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9).
Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
[ "1 2 0\n", "2 3 7\n" ]
[ "2", "-1" ]
The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position. The fraction in the second example ...
1,000
[ { "input": "1 2 0", "output": "2" }, { "input": "2 3 7", "output": "-1" }, { "input": "1 100000 1", "output": "5" }, { "input": "1 7 7", "output": "6" }, { "input": "99999 100000 8", "output": "-1" }, { "input": "44102 73848 2", "output": "132" }...
1,516,951,836
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
5,632,000
import sys a,b,c=map(int,sys.stdin.readline().split()) flag=0 for i in range(1,b+1): a=a*10 if(a//b==i): flag=1 break if(flag): print(i) else: print(-1)
Title: Position in Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. Input Specification: The first contains three single positive integers *a*, *b*, ...
```python import sys a,b,c=map(int,sys.stdin.readline().split()) flag=0 for i in range(1,b+1): a=a*10 if(a//b==i): flag=1 break if(flag): print(i) else: print(-1) ```
0
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors...
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ...
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReal...
1,671,718,224
2,147,483,647
PyPy 3-64
OK
TESTS
64
62
0
have = 0 col = ['purple', 'green', 'blue', 'orange', 'red', 'yellow'] stones = [ 'Power','Time','Space','Soul','Reality','Mind'] for no_testcase in range(int(input())): n = input() t = col.index(n) col.pop(t) stones.pop(t) have+=1 print(6-have) print(*stones,sep="\n")
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So...
```python have = 0 col = ['purple', 'green', 'blue', 'orange', 'red', 'yellow'] stones = [ 'Power','Time','Space','Soul','Reality','Mind'] for no_testcase in range(int(input())): n = input() t = col.index(n) col.pop(t) stones.pop(t) have+=1 print(6-have) print(*stones,sep="\n...
3
157
A
Game Outcome
PROGRAMMING
800
[ "brute force" ]
null
null
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
[ "1\n1\n", "2\n1 2\n3 4\n", "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n" ]
[ "0\n", "2\n", "6\n" ]
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
500
[ { "input": "1\n1", "output": "0" }, { "input": "2\n1 2\n3 4", "output": "2" }, { "input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "4" }, { "inpu...
1,608,819,312
2,147,483,647
Python 3
OK
TESTS
49
218
307,200
n=int(input()) matrix=[] rowsum=0 colsum=0 k=0 r=[] c=[] for i in range(n): matrix.append(list(map(int,input().split()))) for i in range(n): rowsum=0 colsum=0 for j in range(n): rowsum+=matrix[i][j] colsum+=matrix[j][i] r.append(rowsum) c.append(colsum) for i...
Title: Game Outcome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each s...
```python n=int(input()) matrix=[] rowsum=0 colsum=0 k=0 r=[] c=[] for i in range(n): matrix.append(list(map(int,input().split()))) for i in range(n): rowsum=0 colsum=0 for j in range(n): rowsum+=matrix[i][j] colsum+=matrix[j][i] r.append(rowsum) c.append(colsum...
3
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", ...
1,672,997,651
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
62
4,096,000
table = [0]*10**5 + [0] def main(): input() for i in map(input().split()): table[i] += i #Summing up the same elements together a = 0 #a is DP(i-1) b = 0 #b is DP(i-2) for i in table: a, b = max(a, b+i), a print(a) main()
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make ...
```python table = [0]*10**5 + [0] def main(): input() for i in map(input().split()): table[i] += i #Summing up the same elements together a = 0 #a is DP(i-1) b = 0 #b is DP(i-2) for i in table: a, b = max(a, b+i), a print(a) main() ```
-1
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ...
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Print Eleven's new name on the first and only line of output.
[ "8\n", "15\n" ]
[ "OOOoOooO\n", "OOOoOooOooooOoo\n" ]
none
500
[ { "input": "8", "output": "OOOoOooO" }, { "input": "15", "output": "OOOoOooOooooOoo" }, { "input": "85", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo" }, { "input": "381", "output": "OOOoOooOooooOoooooooOooooooooooooOooo...
1,546,480,013
2,147,483,647
Python 3
OK
TESTS
18
109
0
n = int(input()) f1 = 1 f2 = 1 f = f1+f2 s = 'O' idx = 2 while idx <= n: if idx == f: s += 'O' f1 = f2 f2 = f f = f1+f2 else: s += 'o' idx += 1 print(s)
Title: Eleven Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should o...
```python n = int(input()) f1 = 1 f2 = 1 f = f1+f2 s = 'O' idx = 2 while idx <= n: if idx == f: s += 'O' f1 = f2 f2 = f f = f1+f2 else: s += 'o' idx += 1 print(s) ```
3
996
B
World Cup
PROGRAMMING
1,300
[ "binary search", "math" ]
null
null
Allen wants to enter a fan zone that occupies a round square and has $n$ entrances. There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute. Allen uses the following strategy to enter the fan zone: - Initially he s...
The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of entrances. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the number of people in queues. These numbers do not include Allen.
Print a single integer — the number of entrance that Allen will use.
[ "4\n2 3 2 0\n", "2\n10 10\n", "6\n5 2 6 5 7 4\n" ]
[ "3\n", "1\n", "6\n" ]
In the first example the number of people (not including Allen) changes as follows: $[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance. In the second example the number of people...
1,000
[ { "input": "4\n2 3 2 0", "output": "3" }, { "input": "2\n10 10", "output": "1" }, { "input": "6\n5 2 6 5 7 4", "output": "6" }, { "input": "2\n483544186 940350702", "output": "1" }, { "input": "10\n3 3 3 5 6 9 3 1 7 3", "output": "7" }, { "input": "10\...
1,689,255,410
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
61
0
n = int(input()) queue_sizes = list(map(int, input().split())) current_entrance = 1 for i in range(max(queue_sizes)): if queue_sizes[current_entrance - 1] == 0: break queue_sizes[current_entrance - 1] -= 1 current_entrance += 1 if current_entrance > n: current_entrance = 1 print(cur...
Title: World Cup Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen wants to enter a fan zone that occupies a round square and has $n$ entrances. There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zo...
```python n = int(input()) queue_sizes = list(map(int, input().split())) current_entrance = 1 for i in range(max(queue_sizes)): if queue_sizes[current_entrance - 1] == 0: break queue_sizes[current_entrance - 1] -= 1 current_entrance += 1 if current_entrance > n: current_entrance = 1 ...
0