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
660
B
Seating On Bus
PROGRAMMING
1,000
[ "implementation" ]
null
null
Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*. Consider that *m* (*m*<=≤<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to...
The only line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=4*n*) — the number of pairs of rows and the number of passengers.
Print *m* distinct integers from 1 to *m* — the order in which the passengers will get off the bus.
[ "2 7\n", "9 36\n" ]
[ "5 1 6 2 7 3 4\n", "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18\n" ]
none
0
[ { "input": "2 7", "output": "5 1 6 2 7 3 4" }, { "input": "9 36", "output": "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18" }, { "input": "1 1", "output": "1" }, { "input": "1 4", "output": "3 1 4 2" }, { "input...
1,595,769,998
2,147,483,647
Python 3
OK
TESTS
23
109
6,656,000
n,m=map(int,input().split()) c2=2*n+1 c1=1 for i in range(n*2): if(c2<=m): print(c2,end=' ') c2+=1 if(c1<=m): print(c1,end=' ') c1+=1 print('')
Title: Seating On Bus Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*. Consider that *m* (*m*<...
```python n,m=map(int,input().split()) c2=2*n+1 c1=1 for i in range(n*2): if(c2<=m): print(c2,end=' ') c2+=1 if(c1<=m): print(c1,end=' ') c1+=1 print('') ```
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,692,547,084
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
n = int(input()) a = map(int, input().split()) print(sum(a) / (n*100))
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python n = int(input()) a = map(int, input().split()) print(sum(a) / (n*100)) ```
0
534
A
Exam
PROGRAMMING
1,100
[ "constructive algorithms", "implementation", "math" ]
null
null
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other...
A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam.
In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position...
[ "6", "3\n" ]
[ "6\n1 5 3 6 2 4", "2\n1 3" ]
none
500
[ { "input": "6", "output": "6\n5 3 1 6 4 2 " }, { "input": "3", "output": "2\n1 3" }, { "input": "1", "output": "1\n1 " }, { "input": "2", "output": "1\n1" }, { "input": "4", "output": "4\n3 1 4 2 " }, { "input": "5", "output": "5\n5 3 1 4 2 " }, ...
1,628,163,452
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
61
20,172,800
# RawCoder : https://bit.ly/RCyouTube # Author : MehulYK ''' import math as m def lmap(): return list(map(int, input().split())) def mmap(): return map(int, input().split()) ''' def inp(): return int(input()) n = inp() w = [] for k in range(n): w.append(k + 1) ans = [] if(...
Title: Exam Time Limit: None seconds Memory Limit: None megabytes Problem Description: An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and bec...
```python # RawCoder : https://bit.ly/RCyouTube # Author : MehulYK ''' import math as m def lmap(): return list(map(int, input().split())) def mmap(): return map(int, input().split()) ''' def inp(): return int(input()) n = inp() w = [] for k in range(n): w.append(k + 1) ans...
0
507
B
Amr and Pins
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b...
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
[ "2 0 0 0 4\n", "1 1 1 4 4\n", "4 5 6 5 6\n" ]
[ "1\n", "3\n", "0\n" ]
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter). <img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "2 0 0 0 4", "output": "1" }, { "input": "1 1 1 4 4", "output": "3" }, { "input": "4 5 6 5 6", "output": "0" }, { "input": "10 20 0 40 0", "output": "1" }, { "input": "9 20 0 40 0", "output": "2" }, { "input": "5 -1 -6 -5 1", "output": "...
1,631,693,647
2,147,483,647
Python 3
OK
TESTS
37
77
6,963,200
import sys import math from sys import stdin, stdout # TAKE INPUT def get_ints_in_variables(): return map(int, sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list( map(int, sys.stdin.readline().strip().split())) def get_list_of_list(n): return...
Title: Amr and Pins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can ...
```python import sys import math from sys import stdin, stdout # TAKE INPUT def get_ints_in_variables(): return map(int, sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list( map(int, sys.stdin.readline().strip().split())) def get_list_of_list(...
3
451
A
Game With Sticks
PROGRAMMING
900
[ "implementation" ]
null
null
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid show...
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
[ "2 2\n", "2 3\n", "3 3\n" ]
[ "Malvika\n", "Malvika\n", "Akshat\n" ]
Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov...
500
[ { "input": "2 2", "output": "Malvika" }, { "input": "2 3", "output": "Malvika" }, { "input": "3 3", "output": "Akshat" }, { "input": "20 68", "output": "Malvika" }, { "input": "1 1", "output": "Akshat" }, { "input": "1 2", "output": "Akshat" }, ...
1,699,204,268
2,147,483,647
Python 3
OK
TESTS
28
46
0
n,m=map(int,input().split()) if min([n,m])%2==0: print("Malvika") else: print("Akshat")
Title: Game With Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid...
```python n,m=map(int,input().split()) if min([n,m])%2==0: print("Malvika") else: print("Akshat") ```
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,679,510,821
2,147,483,647
Python 3
OK
TESTS
30
46
0
a,b=map(int,input().split()) c=(a+b)-max(a,b) import math d=math.floor((a+b-c*2)/2) print(c,d)
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 a,b=map(int,input().split()) c=(a+b)-max(a,b) import math d=math.floor((a+b-c*2)/2) print(c,d) ```
3
577
A
Multiplication Table
PROGRAMMING
1,000
[ "implementation", "number theory" ]
null
null
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num...
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
Print a single number: the number of times *x* occurs in the table.
[ "10 5\n", "6 12\n", "5 13\n" ]
[ "2\n", "4\n", "0\n" ]
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
500
[ { "input": "10 5", "output": "2" }, { "input": "6 12", "output": "4" }, { "input": "5 13", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "100000 1", "output": "1" }, { "input": "1 10000000...
1,650,111,448
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
0
n,x = map(int, input().split()) count = 0 for i in range(1, n+1): for j in range(1, n+1): if j*i==x: count+=1 print(count)
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. Y...
```python n,x = map(int, input().split()) count = 0 for i in range(1, n+1): for j in range(1, n+1): if j*i==x: count+=1 print(count) ```
0
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuska...
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a r...
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,647,646,007
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
n = int(input()) for i in range (n): x = int(input()) deu_bom = False if x < 60: print('NO') else: for j in range (3, 100): aux = x * j aux2 = (j - 2) * 180 if aux == aux2: print('YES') deu_bom = True ...
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can...
```python n = int(input()) for i in range (n): x = int(input()) deu_bom = False if x < 60: print('NO') else: for j in range (3, 100): aux = x * j aux2 = (j - 2) * 180 if aux == aux2: print('YES') deu_bom = True ...
0
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", ...
1,620,766,833
2,147,483,647
Python 3
OK
TESTS
79
109
14,540,800
import random n=int(input()) result=0 array=list(map(int,input().split())) seconds=set(array) result=len(seconds) if array.count(0)>0: result=result-1 print(result)
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second ...
```python import random n=int(input()) result=0 array=list(map(int,input().split())) seconds=set(array) result=len(seconds) if array.count(0)>0: result=result-1 print(result) ```
3
59
D
Team Arrangement
PROGRAMMING
2,000
[ "constructive algorithms", "greedy", "implementation" ]
D. Team Arrangement
3
256
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3*n*, and...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) which is the number of resulting teams. The second line contains 3*n* space-separated integers from 1 to 3*n* which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once. Then follow *n* lines ea...
Print 3*n*<=-<=1 numbers — the lexicographically smallest list of priorities for the student number *k*. The lexicographical comparison is performed by the standard &lt; operator in modern programming languages. The list *a* is lexicographically less that the list *b* if exists such an *i* (1<=≤<=*i*<=≤<=3*n*), that ...
[ "3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n4\n", "3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n8\n", "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n4\n" ]
[ "2 3 5 6 9 1 7 8 ", "1 2 3 4 5 6 7 9 ", "5 6 1 2 3 " ]
none
2,000
[]
1,659,957,422
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
#input the number of the problems as integer number = int(input()) answer=0 #for loop on each problem we input f1 , f2 ,and f3 for i in range (number): inp =input() sum=inp.count("1") if sum >=2 : answer +=1 #print answer print(answer)
Title: Team Arrangement Time Limit: 3 seconds Memory Limit: 256 megabytes Problem Description: Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each...
```python #input the number of the problems as integer number = int(input()) answer=0 #for loop on each problem we input f1 , f2 ,and f3 for i in range (number): inp =input() sum=inp.count("1") if sum >=2 : answer +=1 #print answer print(answer) ```
0
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,680,679,973
2,147,483,647
Python 3
OK
TESTS
101
92
0
n=int(input()) l=list(map(int,input().split())) ind=[i for i in range(n)] ans=[True]*n for i in range(n): ans[l[i]-1]=i+1 for i in ans: print(i,end=" ")
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n=int(input()) l=list(map(int,input().split())) ind=[i for i in range(n)] ans=[True]*n for i in range(n): ans[l[i]-1]=i+1 for i in ans: print(i,end=" ") ```
3
115
A
Party
PROGRAMMING
900
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immedi...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate...
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
500
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": ...
1,646,116,021
2,147,483,647
Python 3
OK
TESTS
106
872
0
n=int(input()) p,s=[int(input())for i in range(n)],0 for i in range(n): c=0 while i>=0:i=p[i]-1;c+=1 s=max(s,c) print(s)
Title: Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an...
```python n=int(input()) p,s=[int(input())for i in range(n)],0 for i in range(n): c=0 while i>=0:i=p[i]-1;c+=1 s=max(s,c) print(s) ```
3
773
A
Success Rate
PROGRAMMING
1,700
[ "binary search", "math" ]
null
null
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equal to *x*<=/<=*y*. Your favorite rational number in the [0;1] range is *p*<=/<=*q*. Now you wonde...
The first line contains a single integer *t* (1<=≤<=*t*<=≤<=1000) — the number of test cases. Each of the next *t* lines contains four integers *x*, *y*, *p* and *q* (0<=≤<=*x*<=≤<=*y*<=≤<=109; 0<=≤<=*p*<=≤<=*q*<=≤<=109; *y*<=&gt;<=0; *q*<=&gt;<=0). It is guaranteed that *p*<=/<=*q* is an irreducible fraction. Hacks...
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
[ "4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1\n" ]
[ "4\n10\n0\n-1\n" ]
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submiss...
500
[ { "input": "4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1", "output": "4\n10\n0\n-1" }, { "input": "8\n0 1 0 1\n0 2 1 2\n0 3 1 1\n1 2 0 1\n1 2 1 1\n2 2 0 1\n3 3 1 2\n4 4 1 1", "output": "0\n2\n-1\n-1\n-1\n-1\n3\n0" }, { "input": "5\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 100...
1,507,552,328
2,147,483,647
Python 3
OK
TESTS
56
77
0
for i in range(int(input())): x, y, p, q = map(int, input().split()) print(-(x > 0) if not p else -(y > x) if p == q else max((x - 1) // p, (y - x - 1) // (q - p)) * q + q - y)
Title: Success Rate Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equ...
```python for i in range(int(input())): x, y, p, q = map(int, input().split()) print(-(x > 0) if not p else -(y > x) if p == q else max((x - 1) // p, (y - x - 1) // (q - p)) * q + q - y) ```
3
416
C
Booking System
PROGRAMMING
1,600
[ "binary search", "dp", "greedy", "implementation" ]
null
null
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i*...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they w...
In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly. Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this...
[ "3\n10 50\n2 100\n5 30\n3\n4 6 9\n" ]
[ "2 130\n2 1\n3 2\n" ]
none
1,500
[ { "input": "3\n10 50\n2 100\n5 30\n3\n4 6 9", "output": "2 130\n2 1\n3 2" }, { "input": "1\n1 1\n1\n1", "output": "1 1\n1 1" }, { "input": "1\n2 1\n1\n1", "output": "0 0" }, { "input": "2\n10 10\n5 5\n1\n5", "output": "1 5\n2 1" }, { "input": "2\n10 10\n5 5\n1\n10...
1,553,848,482
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
248
409,600
n = int(input()) a = [] for i in range(n): c, p = map(int, input().split()) a.append((p, c, i)) k = int(input()) st = list(map(int, input().split())) a.sort(reverse = True) summ = 0 ans = [] l = 0 for i in range(n): price = a[i][0] col = a[i][1] ind = a[i][2] fl = False uk = 1000001 for j in range(k): if col ...
Title: Booking System Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. ...
```python n = int(input()) a = [] for i in range(n): c, p = map(int, input().split()) a.append((p, c, i)) k = int(input()) st = list(map(int, input().split())) a.sort(reverse = True) summ = 0 ans = [] l = 0 for i in range(n): price = a[i][0] col = a[i][1] ind = a[i][2] fl = False uk = 1000001 for j in range(k):...
0
332
C
Students' Revenge
PROGRAMMING
2,200
[ "data structures", "greedy", "sortings" ]
null
null
A student's life is fraught with complications. Some Berland University students know this only too well. Having studied for two years, they contracted strong antipathy towards the chairperson of some department. Indeed, the person in question wasn't the kindest of ladies to begin with: prone to reforming groups, banni...
The first line contains three integers *n* (1<=≤<=*n*<=≤<=105), *p* (1<=≤<=*p*<=≤<=*n*), *k* (1<=≤<=*k*<=≤<=*p*) — the number of orders the directors are going to discuss, the number of orders to pass and the number of orders to be obeyed by the chairperson, correspondingly. Each of the following *n* lines contains two...
Print in an arbitrary order *p* distinct integers — the numbers of the orders to accept so that the students could carry out the revenge. The orders are indexed from 1 to *n* in the order they occur in the input. If there are multiple solutions, you can print any of them.
[ "5 3 2\n5 6\n5 8\n1 3\n4 3\n4 11\n", "5 3 3\n10 18\n18 17\n10 20\n20 18\n20 18\n" ]
[ "3 1 2 ", "2 4 5 " ]
In the first sample one of optimal solutions is to pass orders 1, 2, 3. In this case the chairperson obeys orders number 1 and 2. She gets 10 new grey hairs in the head and the directors' displeasement will equal 3. Note that the same result can be achieved with order 4 instead of order 3. In the second sample, the ch...
3,000
[ { "input": "5 3 2\n5 6\n5 8\n1 3\n4 3\n4 11", "output": "3 1 2 " }, { "input": "5 3 3\n10 18\n18 17\n10 20\n20 18\n20 18", "output": "2 4 5 " }, { "input": "10 7 4\n4 3\n5 3\n5 5\n4 3\n4 5\n3 5\n4 5\n4 4\n3 5\n4 5", "output": "1 4 8 3 5 7 10 " }, { "input": "20 15 10\n79 84\n...
1,374,721,324
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
import functools n, p, k = map(int, input().split()) order = sorted([list(map(int, input().split())) + [i] for i in range(n)], reverse=True) done = [False] * n for i in range(k): done[order[i][2]] = True order = sorted(order, key=functools.cmp_to_key(lambda a, b: a[1] - b[1] if a[1] != b[1] else a[0] - b[0])) f...
Title: Students' Revenge Time Limit: None seconds Memory Limit: None megabytes Problem Description: A student's life is fraught with complications. Some Berland University students know this only too well. Having studied for two years, they contracted strong antipathy towards the chairperson of some department. Inde...
```python import functools n, p, k = map(int, input().split()) order = sorted([list(map(int, input().split())) + [i] for i in range(n)], reverse=True) done = [False] * n for i in range(k): done[order[i][2]] = True order = sorted(order, key=functools.cmp_to_key(lambda a, b: a[1] - b[1] if a[1] != b[1] else a[0] ...
0
761
C
Dasha and Password
PROGRAMMING
1,500
[ "brute force", "dp", "implementation" ]
null
null
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string,...
The first line contains two integers *n*, *m* (3<=≤<=*n*<=≤<=50,<=1<=≤<=*m*<=≤<=50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next *n* lines contains the string which is assigned to the *i*-th symbol of the password string. Its length is *m*, it consist...
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
[ "3 4\n1**2\na3*0\nc4**\n", "5 5\n#*&amp;#*\n*a1c&amp;\n&amp;q2w*\n#a3c#\n*&amp;#*&amp;\n" ]
[ "1\n", "3\n" ]
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
1,500
[ { "input": "3 4\n1**2\na3*0\nc4**", "output": "1" }, { "input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3" }, { "input": "5 2\n&l\n*0\n*9\n*#\n#o", "output": "2" }, { "input": "25 16\nvza**ooxkmd#*ywa\ndip#*#&ef&z&&&pv\nwggob&&72#*&&nku\nrsb##*&jm&#u**te\nzif#lu#...
1,500,868,503
3,483
Python 3
OK
TESTS
52
140
4,608,000
R= lambda: map(int,input().split()) n,m= R() l=[[150,150,150] for i in range(n)] for i in range(n): a=input() for j in range(m): if a[j] in ['#','*','&']: l[i][2]=min(l[i][2],min(j,m-j)) elif a[j].isdigit(): l[i][1]=min(l[i][1],min(j,m-j)) else: l[i][0]=min(l[i][0],min(j,m...
Title: Dasha and Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements: - There is at least one dig...
```python R= lambda: map(int,input().split()) n,m= R() l=[[150,150,150] for i in range(n)] for i in range(n): a=input() for j in range(m): if a[j] in ['#','*','&']: l[i][2]=min(l[i][2],min(j,m-j)) elif a[j].isdigit(): l[i][1]=min(l[i][1],min(j,m-j)) else: l[i][0]=min(l[i][...
3
656
D
Rosetta Problem
PROGRAMMING
2,100
[ "*special" ]
null
null
The input contains a single integer *a* (0<=≤<=*a*<=≤<=1<=000<=000).
Output a single integer.
[ "129\n" ]
[ "1\n" ]
none
0
[ { "input": "129", "output": "1" }, { "input": "0", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "0" }, { "input": "16", "output": "0" }, { "input": "299593", "output": "7" }, { "input": "398929", "output":...
1,608,952,952
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
A=input() b=oct(A) b=b[2:] p=0 p=b.count('1')
Title: Rosetta Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Input Specification: The input contains a single integer *a* (0<=≤<=*a*<=≤<=1<=000<=000). Output Specification: Output a single integer. Demo Input: ['129\n'] Demo Output: ['1\n'] Note: none
```python A=input() b=oct(A) b=b[2:] p=0 p=b.count('1') ```
-1
302
A
Eugeny and Array
PROGRAMMING
800
[ "implementation" ]
null
null
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a...
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
[ "2 3\n1 -1\n1 1\n1 2\n2 2\n", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n" ]
[ "0\n1\n0\n", "0\n1\n0\n1\n0\n" ]
none
500
[ { "input": "2 3\n1 -1\n1 1\n1 2\n2 2", "output": "0\n1\n0" }, { "input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5", "output": "0\n1\n0\n1\n0" }, { "input": "3 3\n1 1 1\n2 2\n1 1\n1 1", "output": "0\n0\n0" }, { "input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1", "output": "...
1,616,595,379
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#copy pasted test run inpArr = raw_input().split() n = int(inpArr[0]) m = int(inpArr[1]) aArr = [int(inp) for inp in raw_input().split()] numPlus = 0 numMinus = 0 for a in aArr: if a == 1: numPlus += 1 elif a == -1: numMinus += 1 for i in range(m): inpArr = raw_input().split() l = i...
Title: Eugeny and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (...
```python #copy pasted test run inpArr = raw_input().split() n = int(inpArr[0]) m = int(inpArr[1]) aArr = [int(inp) for inp in raw_input().split()] numPlus = 0 numMinus = 0 for a in aArr: if a == 1: numPlus += 1 elif a == -1: numMinus += 1 for i in range(m): inpArr = raw_input().split()...
-1
495
A
Digital Counter
PROGRAMMING
1,100
[ "implementation" ]
null
null
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ...
The only line of input contains exactly two digits representing number *n* (0<=≤<=*n*<=≤<=99). Note that *n* may have a leading zero.
In the only line of the output print the number of good integers.
[ "89\n", "00\n", "73\n" ]
[ "2\n", "4\n", "15\n" ]
In the first sample the counter may be supposed to show 88 or 89. In the second sample the good integers are 00, 08, 80 and 88. In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.
500
[ { "input": "89", "output": "2" }, { "input": "00", "output": "4" }, { "input": "73", "output": "15" }, { "input": "08", "output": "2" }, { "input": "26", "output": "4" }, { "input": "49", "output": "6" }, { "input": "88", "output": "1" ...
1,665,005,770
2,147,483,647
Python 3
OK
TESTS
29
46
0
num=input() sol=[2,7,2,3,3,4,2,5,1,2] f_num = sol[int(num[0])] s_num = sol[int(num[1])] print(f_num*s_num)
Title: Digital Counter Time Limit: None seconds Memory Limit: None megabytes Problem Description: Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a numbe...
```python num=input() sol=[2,7,2,3,3,4,2,5,1,2] f_num = sol[int(num[0])] s_num = sol[int(num[1])] print(f_num*s_num) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,652,252,544
2,147,483,647
Python 3
OK
TESTS
30
62
0
n = input() s = [ ] i = 0 while i < len(n): if n[i] == '.': s += [0] i += 1 elif n[i] == '-' and n[i + 1] == '.': i += 2 s += [1] elif n[i] == '-' and n[i + 1] == '-': i += 2 s += [2] print(*s ,sep = '')
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ...
```python n = input() s = [ ] i = 0 while i < len(n): if n[i] == '.': s += [0] i += 1 elif n[i] == '-' and n[i + 1] == '.': i += 2 s += [1] elif n[i] == '-' and n[i + 1] == '-': i += 2 s += [2] print(*s ,sep = '') ```
3.9845
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. Th...
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0...
1,650,780,296
2,147,483,647
Python 3
OK
TESTS
35
46
0
n, k = map(int, input().split()) li = list(map(int, input().split())) li = [i+k for i in li] li.sort() c = 0 for i in li: if i<=5: c = c+1 print(c//3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi...
```python n, k = map(int, input().split()) li = list(map(int, input().split())) li = [i+k for i in li] li.sort() c = 0 for i in li: if i<=5: c = c+1 print(c//3) ```
3
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul...
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter t...
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input":...
1,599,846,676
2,147,483,647
Python 3
OK
TESTS
50
218
307,200
# # Author: eloyhz # Date: Sep/11/2020 # # # # def read_weight(): w = list(input()) if w[1] == '>': w[1] = '<' w[0], w[2] = w[2], w[0] return ''.join(w) if __name__ == '__main__': coins = [['ABC', 'A<B', 'A<C', 'B<C'], ['ACB', 'A<C', 'A<B', 'C<B'], ...
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ...
```python # # Author: eloyhz # Date: Sep/11/2020 # # # # def read_weight(): w = list(input()) if w[1] == '>': w[1] = '<' w[0], w[2] = w[2], w[0] return ''.join(w) if __name__ == '__main__': coins = [['ABC', 'A<B', 'A<C', 'B<C'], ['ACB', 'A<C', 'A<B', 'C<...
3.944928
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then...
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1...
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "outpu...
1,656,396,648
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
12
3,000
4,915,200
nmsg=int(input()) list=[] for x in range(nmsg): i=input() if i in list: list.remove(i) list.insert(0,i) else: list.insert(0,i) for k in list: print(k)
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela...
```python nmsg=int(input()) list=[] for x in range(nmsg): i=input() if i in list: list.remove(i) list.insert(0,i) else: list.insert(0,i) for k in list: print(k) ```
0
165
B
Burning Midnight Oil
PROGRAMMING
1,500
[ "binary search", "implementation" ]
null
null
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lin...
The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10.
Print the only integer — the minimum value of *v* that lets Vasya write the program in one night.
[ "7 2\n", "59 9\n" ]
[ "4\n", "54\n" ]
In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task. In the second sample the answer is *v* = 54. Vasya writes the code in the following por...
1,000
[ { "input": "7 2", "output": "4" }, { "input": "59 9", "output": "54" }, { "input": "1 9", "output": "1" }, { "input": "11 2", "output": "7" }, { "input": "747 2", "output": "376" }, { "input": "6578 2", "output": "3293" }, { "input": "37212...
1,662,330,808
2,147,483,647
PyPy 3-64
OK
TESTS
56
124
1,638,400
def sigma(v,k): s = 0 for i in range(50): s += v//k**i return s n,k = map(int, input().split()) lo = 1; hi = n while (hi-lo)>1: m = (lo+hi)//2 if sigma(m,k) < n: lo = m else: hi = m if sigma(hi,k) >= n: print(hi) else: print(lo)
Title: Burning Midnight Oil Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of c...
```python def sigma(v,k): s = 0 for i in range(50): s += v//k**i return s n,k = map(int, input().split()) lo = 1; hi = n while (hi-lo)>1: m = (lo+hi)//2 if sigma(m,k) < n: lo = m else: hi = m if sigma(hi,k) >= n: print(hi) else: print...
3
962
B
Students in Railway Carriage
PROGRAMMING
1,300
[ "constructive algorithms", "greedy", "implementation" ]
null
null
There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carri...
The first line contain three integers $n$, $a$ and $b$ ($1 \le n \le 2\cdot10^{5}$, $0 \le a, b \le 2\cdot10^{5}$, $a + b &gt; 0$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes. The second line contains a string with length $n$, consisting o...
Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.
[ "5 1 1\n*...*\n", "6 2 3\n*...*.\n", "11 3 10\n.*....**.*.\n", "3 2 3\n***\n" ]
[ "2\n", "4\n", "7\n", "0\n" ]
In the first example you can put all student, for example, in the following way: *.AB* In the second example you can put four students, for example, in the following way: *BAB*B In the third example you can put seven students, for example, in the following way: B*ABAB**A*B The letter A means a student-programmer, an...
0
[ { "input": "5 1 1\n*...*", "output": "2" }, { "input": "6 2 3\n*...*.", "output": "4" }, { "input": "11 3 10\n.*....**.*.", "output": "7" }, { "input": "3 2 3\n***", "output": "0" }, { "input": "9 5 3\n*...*...*", "output": "6" }, { "input": "9 2 4\n*....
1,524,314,353
1,753
Python 3
OK
TESTS
93
358
8,089,600
n, a, b = map(int, input().split()) vagon = input() + '*' free, ans = 0, 0 pr_a, pr_b = a, b for i in range(n + 1): if a == 0 and b == 0: break if vagon[i] == '.': free += 1 else: if a >= b: a, b = a - min(a, (free - 1) // 2 + 1), b - min(b, free // 2) else: ...
Title: Students in Railway Carriage Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of $a$ student-programmers and $b$ student-...
```python n, a, b = map(int, input().split()) vagon = input() + '*' free, ans = 0, 0 pr_a, pr_b = a, b for i in range(n + 1): if a == 0 and b == 0: break if vagon[i] == '.': free += 1 else: if a >= b: a, b = a - min(a, (free - 1) // 2 + 1), b - min(b, free // 2) e...
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,632,904,703
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
154
20,172,800
y, w = map(int, input().split()) mx = 6 - max(y, w) + 1 if not 6%mx: v = 6//mx print('1/'+str(v)) else: print(str(mx)+'/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 y, w = map(int, input().split()) mx = 6 - max(y, w) + 1 if not 6%mx: v = 6//mx print('1/'+str(v)) else: print(str(mx)+'/6') ```
0
373
A
Collecting Beats is Fun
PROGRAMMING
900
[ "implementation" ]
null
null
Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with...
The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand. Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per...
Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).
[ "1\n.135\n1247\n3468\n5789\n", "5\n..1.\n1111\n..1.\n..1.\n", "1\n....\n12.1\n.2..\n.2..\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.
500
[ { "input": "1\n.135\n1247\n3468\n5789", "output": "YES" }, { "input": "5\n..1.\n1111\n..1.\n..1.", "output": "YES" }, { "input": "1\n....\n12.1\n.2..\n.2..", "output": "NO" }, { "input": "1\n6981\n.527\n4163\n2345", "output": "YES" }, { "input": "5\n9999\n9999\n99...
1,684,009,981
2,147,483,647
Python 3
OK
TESTS
27
46
0
n = int(input()) d = [0]*9 for i in range(0,4): s = input() for x in s: if x != '.': d[int(x)-1] +=1 if max(d) > 2*n: print("NO") else: print("YES")
Title: Collecting Beats is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preff...
```python n = int(input()) d = [0]*9 for i in range(0,4): s = input() for x in s: if x != '.': d[int(x)-1] +=1 if max(d) > 2*n: print("NO") else: print("YES") ```
3
429
A
Xor-tree
PROGRAMMING
1,300
[ "dfs and similar", "trees" ]
null
null
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds t...
In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*.
[ "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n" ]
[ "2\n4\n7\n" ]
none
500
[ { "input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1", "output": "2\n4\n7" }, { "input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0", "output"...
1,676,466,558
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n = int(input()) for i in range(n - 1): a = list(map(int, input().split())) a1 = input().split() a2 = input().split() print(abs(a1.count('1') - a2.count('1'))) for i in range(n): if a1[i] != a2[i]: print(i + 1)
Title: Xor-tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played ...
```python n = int(input()) for i in range(n - 1): a = list(map(int, input().split())) a1 = input().split() a2 = input().split() print(abs(a1.count('1') - a2.count('1'))) for i in range(n): if a1[i] != a2[i]: print(i + 1) ```
0
710
D
Two Arithmetic Progressions
PROGRAMMING
2,500
[ "math", "number theory" ]
null
null
You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some integers *k*',<=*l*'<=≥<=0.
The only line contains six integers *a*1,<=*b*1,<=*a*2,<=*b*2,<=*L*,<=*R* (0<=&lt;<=*a*1,<=*a*2<=≤<=2·109,<=<=-<=2·109<=≤<=*b*1,<=*b*2,<=*L*,<=*R*<=≤<=2·109,<=*L*<=≤<=*R*).
Print the desired number of integers *x*.
[ "2 0 3 3 5 21\n", "2 4 3 0 6 17\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "2 0 3 3 5 21", "output": "3" }, { "input": "2 4 3 0 6 17", "output": "2" }, { "input": "2 0 4 2 -39 -37", "output": "0" }, { "input": "1 9 3 11 49 109", "output": "20" }, { "input": "3 81 5 72 -1761 501", "output": "28" }, { "input": "8 -89...
1,471,969,958
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
4,608,000
def gcdex(a, b): if b == 0: return a, 1, 0 else: d, x, y = gcdex(b, a % b) return d, y, x - y * (a // b) a1, b1, a2, b2, L, R = map(int, input().split()) a = a1 b = -a2 c = (b2 - b1) d, x0, y0 = gcdex(a, b) if (b2 - b1) % d == 0: a //= d b //= d c //= d ...
Title: Two Arithmetic Progressions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some i...
```python def gcdex(a, b): if b == 0: return a, 1, 0 else: d, x, y = gcdex(b, a % b) return d, y, x - y * (a // b) a1, b1, a2, b2, L, R = map(int, input().split()) a = a1 b = -a2 c = (b2 - b1) d, x0, y0 = gcdex(a, b) if (b2 - b1) % d == 0: a //= d b //= d ...
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,676,214,949
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
arr = list(map(int,input().split()) print(max(arr)-min(arr))
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python arr = list(map(int,input().split()) print(max(arr)-min(arr)) ```
-1
399
A
Pages
PROGRAMMING
0
[ "implementation" ]
null
null
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this: When someone clicks the button "&lt;&lt;" he is redirected to page 1, and wh...
The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*)
Print the proper navigation. Follow the format of the output from the test samples.
[ "17 5 2\n", "6 5 2\n", "6 1 2\n", "6 2 2\n", "9 6 3\n", "10 6 3\n", "8 5 4\n" ]
[ "&lt;&lt; 3 4 (5) 6 7 &gt;&gt; ", "&lt;&lt; 3 4 (5) 6 ", "(1) 2 3 &gt;&gt; ", "1 (2) 3 4 &gt;&gt;", "&lt;&lt; 3 4 5 (6) 7 8 9", "&lt;&lt; 3 4 5 (6) 7 8 9 &gt;&gt;", "1 2 3 4 (5) 6 7 8 " ]
none
500
[ { "input": "17 5 2", "output": "<< 3 4 (5) 6 7 >> " }, { "input": "6 5 2", "output": "<< 3 4 (5) 6 " }, { "input": "6 1 2", "output": "(1) 2 3 >> " }, { "input": "6 2 2", "output": "1 (2) 3 4 >> " }, { "input": "9 6 3", "output": "<< 3 4 5 (6) 7 8 9 " }, {...
1,585,388,371
2,147,483,647
Python 3
OK
TESTS
26
108
307,200
n, p, k = input().split(' ') n,p,k = int(n), int(p), int(k) pages = [] for i in range(p-k, p+k+1): if i > 0 and i <= n: pages.append(i) string = '' if pages[0] != 1: string+='<< ' for i in pages: if i == p: string+= "({0}) ".format(i) else: string+= '{0} '.format(i) if pages[-1]!= n: str...
Title: Pages Time Limit: None seconds Memory Limit: None megabytes Problem Description: User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo...
```python n, p, k = input().split(' ') n,p,k = int(n), int(p), int(k) pages = [] for i in range(p-k, p+k+1): if i > 0 and i <= n: pages.append(i) string = '' if pages[0] != 1: string+='<< ' for i in pages: if i == p: string+= "({0}) ".format(i) else: string+= '{0} '.format(i) if pages[-1]!...
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,672,252,313
2,147,483,647
Python 3
OK
TESTS
40
92
0
source=input() translation=input() if(source[::-1]==translation): print('YES') else: print('NO')
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python source=input() translation=input() if(source[::-1]==translation): print('YES') else: print('NO') ```
3.977
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "outpu...
1,535,069,994
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
218
0
sum_of_digits = int(input()) solution = '-1' for b in range(sum_of_digits//7 + 1): if (sum_of_digits - 7*b) % 4 == 0: a = (sum_of_digits - 7*b)//4 solution = ['4']*a solution.extend(['7']*b) solution = ''.join(solution) break print(solution)
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python sum_of_digits = int(input()) solution = '-1' for b in range(sum_of_digits//7 + 1): if (sum_of_digits - 7*b) % 4 == 0: a = (sum_of_digits - 7*b)//4 solution = ['4']*a solution.extend(['7']*b) solution = ''.join(solution) break print(solution) ```
0
777
B
Game of Credit Cards
PROGRAMMING
1,300
[ "data structures", "dp", "greedy", "sortings" ]
null
null
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use. The second line contains *n* digits — Sherlock's credit card number. The third line contains *n* digits — Moriarty's credit card number.
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
[ "3\n123\n321\n", "2\n88\n00\n" ]
[ "0\n2\n", "2\n0\n" ]
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
1,000
[ { "input": "3\n123\n321", "output": "0\n2" }, { "input": "2\n88\n00", "output": "2\n0" }, { "input": "1\n4\n5", "output": "0\n1" }, { "input": "1\n8\n7", "output": "1\n0" }, { "input": "2\n55\n55", "output": "0\n0" }, { "input": "3\n534\n432", "out...
1,488,405,984
2,147,483,647
PyPy 3
OK
TESTS
55
109
23,859,200
from sys import stdin N = int(stdin.readline()) sherlock = list(map(int, stdin.readline().strip())) moriarty = list(map(int, stdin.readline().strip())) mcounts = [0] * 10 for m in moriarty: mcounts[m] += 1 def minflicks(counts): flicks = 0 for s in sherlock: si = s while counts[si % 10] =...
Title: Game of Credit Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simpl...
```python from sys import stdin N = int(stdin.readline()) sherlock = list(map(int, stdin.readline().strip())) moriarty = list(map(int, stdin.readline().strip())) mcounts = [0] * 10 for m in moriarty: mcounts[m] += 1 def minflicks(counts): flicks = 0 for s in sherlock: si = s while counts[...
3
340
C
Tourist Problem
PROGRAMMING
1,600
[ "combinatorics", "implementation", "math" ]
null
null
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a*...
The first line contains integer *n* (2<=≤<=*n*<=≤<=105). Next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107).
Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.
[ "3\n2 3 5\n" ]
[ "22 3" ]
Consider 6 possible routes: - [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5; - [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7; - [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7; - [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8; - [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9; - [5, 3, 2]: |5 – 0| + |3 – 5|...
2,000
[ { "input": "3\n2 3 5", "output": "22 3" }, { "input": "4\n1 5 77 2", "output": "547 4" }, { "input": "5\n3 3842 288 199 334", "output": "35918 5" }, { "input": "7\n1 2 3 40 52 33 86", "output": "255 1" }, { "input": "7\n1 10 100 1000 10000 1000000 10000000", "...
1,586,787,568
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
218
0
def gcd(a,b): if b == 0: return a return gcd(b,a%b) n = int(input()) a = [int(x) for x in input().split()] sum1 = sum(a) sum2 = 0 sumbefore = 0 for i in range(n): sum2 += a[i]*(i) - sumbefore sumbefore += a[i] sumtot = sum1 + 2*sum2 k = gcd(sumtot,n) print(sumtot//k,n//k)
Title: Tourist Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* d...
```python def gcd(a,b): if b == 0: return a return gcd(b,a%b) n = int(input()) a = [int(x) for x in input().split()] sum1 = sum(a) sum2 = 0 sumbefore = 0 for i in range(n): sum2 += a[i]*(i) - sumbefore sumbefore += a[i] sumtot = sum1 + 2*sum2 k = gcd(sumtot,n) print(sumtot/...
0
964
A
Splits
PROGRAMMING
800
[ "math" ]
null
null
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$. Th...
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output one integer — the answer to the problem.
[ "7\n", "8\n", "9\n" ]
[ "4\n", "5\n", "5\n" ]
In the first sample, there are following possible weights of splits of $7$: Weight 1: [$\textbf 7$] Weight 2: [$\textbf 3$, $\textbf 3$, 1] Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1] Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$]
500
[ { "input": "7", "output": "4" }, { "input": "8", "output": "5" }, { "input": "9", "output": "5" }, { "input": "1", "output": "1" }, { "input": "286", "output": "144" }, { "input": "48", "output": "25" }, { "input": "941", "output": "471...
1,526,107,984
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
return int(input())//2+1
Title: Splits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The foll...
```python return int(input())//2+1 ```
-1
246
B
Increase and Decrease
PROGRAMMING
1,300
[ "greedy", "math" ]
null
null
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: - he chooses two elements of the array *a**i...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array.
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
[ "2\n2 1\n", "3\n1 4 1\n" ]
[ "1\n", "3\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 4 1", "output": "3" }, { "input": "4\n2 -7 -2 -6", "output": "3" }, { "input": "4\n2 0 -2 -1", "output": "3" }, { "input": "6\n-1 1 0 0 -1 -1", "output": "5" }, { "input": "5\n0 0 0 0 0", "outp...
1,508,443,648
2,147,483,647
Python 3
OK
TESTS
30
154
7,987,200
n = int(input()) nums = list(map(int, input().split(" "))) average = int(sum(nums) / len(nums)) if(average - sum(nums) / len(nums) == 0): print(len(nums)) else: print(len(nums) - 1)
Title: Increase and Decrease Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that...
```python n = int(input()) nums = list(map(int, input().split(" "))) average = int(sum(nums) / len(nums)) if(average - sum(nums) / len(nums) == 0): print(len(nums)) else: print(len(nums) - 1) ```
3
254
A
Cards with Numbers
PROGRAMMING
1,200
[ "constructive algorithms", "sortings" ]
null
null
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs. Separate the numbers on the lines by spaces. You...
[ "3\n20 30 10 30 20 10\n", "1\n1 2\n" ]
[ "4 2\n1 5\n6 3\n", "-1" ]
none
500
[ { "input": "3\n20 30 10 30 20 10", "output": "4 2\n1 5\n6 3" }, { "input": "1\n1 2", "output": "-1" }, { "input": "5\n2 2 2 2 2 1 2 2 1 2", "output": "2 1\n3 4\n7 5\n6 9\n10 8" }, { "input": "5\n2 1 2 2 1 1 1 1 1 2", "output": "3 1\n2 5\n7 6\n8 9\n10 4" }, { "inpu...
1,569,169,434
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
44,544,000
import sys sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") n=2*int(input()) arr=[int(x) for x in input().split(' ')] arr2=[] for x in range(n): arr2.append([arr[x],x+1]) arr2.sort() ans=[] for x in range(1,n,2): a,b=arr2[x-1][0],arr2[x][0] if a==b: ans.append([arr2[x-1][1],arr2[x][1]]) ...
Title: Cards with Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card wit...
```python import sys sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") n=2*int(input()) arr=[int(x) for x in input().split(' ')] arr2=[] for x in range(n): arr2.append([arr[x],x+1]) arr2.sort() ans=[] for x in range(1,n,2): a,b=arr2[x-1][0],arr2[x][0] if a==b: ans.append([arr2[x-1][1],arr...
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,688,225,895
2,147,483,647
Python 3
OK
TESTS
40
92
0
num=input("") n=input(" ") if(num==n[::-1]): print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python num=input("") n=input(" ") if(num==n[::-1]): print("YES") else: print("NO") ```
3.977
445
A
DZY Loves Chessboard
PROGRAMMING
1,200
[ "dfs and similar", "implementation" ]
null
null
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ...
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It ...
[ "1 1\n.\n", "2 2\n..\n..\n", "3 3\n.-.\n---\n--." ]
[ "B\n", "BW\nWB\n", "B-B\n---\n--B" ]
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
500
[ { "input": "1 1\n.", "output": "B" }, { "input": "2 2\n..\n..", "output": "BW\nWB" }, { "input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B" }, { "input": "3 1\n-\n.\n.", "output": "-\nW\nB" }, { "input": "11 11\n-----------\n-----------\n-----------\n--------...
1,699,339,300
2,147,483,647
Python 3
OK
TESTS
37
46
0
n, m = map(int, input().split()) S = [] for i in range(n): row = input().strip() new_row = [] for j in range(m): if row[j] == '.': if (i + j) % 2 == 0: new_row.append('B') else: new_row.append('W') else: new_...
Title: DZY Loves Chessboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ...
```python n, m = map(int, input().split()) S = [] for i in range(n): row = input().strip() new_row = [] for j in range(m): if row[j] == '.': if (i + j) % 2 == 0: new_row.append('B') else: new_row.append('W') else: ...
3
0
none
none
none
0
[ "none" ]
null
null
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical. Valera absolutel...
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Print on the single line the answer to the problem: the amount of subarrays, which are magical. Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
[ "4\n2 1 1 4\n", "5\n-2 -2 -2 0 1\n" ]
[ "5\n", "8\n" ]
Notes to sample tests: Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end. In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3]. In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].
0
[ { "input": "4\n2 1 1 4", "output": "5" }, { "input": "5\n-2 -2 -2 0 1", "output": "8" }, { "input": "1\n10", "output": "1" }, { "input": "2\n5 6", "output": "2" }, { "input": "5\n5 5 4 5 5", "output": "7" }, { "input": "8\n1 2 0 0 0 0 3 3", "output...
1,621,253,516
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
186
0
n=int(input()) arr = sorted([int(x) for x in input().strip().split()]) arr1=arr[0] c=1 s=0 for ele in arr[1:]: if arr1==ele: c+=1 else : s+=(c*(c-1))//2 c=1 arr1=ele print(n+s)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular...
```python n=int(input()) arr = sorted([int(x) for x in input().strip().split()]) arr1=arr[0] c=1 s=0 for ele in arr[1:]: if arr1==ele: c+=1 else : s+=(c*(c-1))//2 c=1 arr1=ele print(n+s) ```
0
496
A
Minimum Difficulty
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,...
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict...
Print a single number — the minimum difficulty of the track after removing a single hold.
[ "3\n1 4 6\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n" ]
[ "5\n", "2\n", "4\n" ]
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5. In the second test after removing every hold the difficulty equals 2. In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic...
500
[ { "input": "3\n1 4 6", "output": "5" }, { "input": "5\n1 2 3 4 5", "output": "2" }, { "input": "5\n1 2 3 7 8", "output": "4" }, { "input": "3\n1 500 1000", "output": "999" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "2" }, { "input": "10\n1 4 9...
1,612,857,466
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
92
0
n = int(input()) arr = list(map(int,input().split())) t=arr.copy() min=1000 max =0 for i in range(n-2): arr.remove(arr[i+1]) j = 0 while(j<n-2): c = arr[j+1]-arr[j] #print(c) if c>max: max=c j+=1 arr=t.copy() if max<min: min = max ...
Title: Minimum Difficulty Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 fo...
```python n = int(input()) arr = list(map(int,input().split())) t=arr.copy() min=1000 max =0 for i in range(n-2): arr.remove(arr[i+1]) j = 0 while(j<n-2): c = arr[j+1]-arr[j] #print(c) if c>max: max=c j+=1 arr=t.copy() if max<min: m...
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,657,743,136
2,147,483,647
PyPy 3-64
OK
TESTS
43
62
1,433,600
input() a=list(map(int,input())) b=list(map(int,input())) cnt=0 for i in range(len(a)): cnt+=min(abs(a[i]-b[i]),10-abs(a[i]-b[i])) print(cnt)
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 input() a=list(map(int,input())) b=list(map(int,input())) cnt=0 for i in range(len(a)): cnt+=min(abs(a[i]-b[i]),10-abs(a[i]-b[i])) print(cnt) ```
3
868
D
Huge Strings
PROGRAMMING
2,200
[ "bitmasks", "brute force", "dp", "implementation", "strings" ]
null
null
You are given *n* strings *s*1,<=*s*2,<=...,<=*s**n* consisting of characters 0 and 1. *m* operations are performed, on each of them you concatenate two existing strings into a new one. On the *i*-th operation the concatenation *s**a**i**s**b**i* is saved into a new string *s**n*<=+<=*i* (the operations are numbered st...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of strings. The next *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=|*s**i*|<=≤<=100), one per line. The total length of strings is not greater than 100. The next line contains single integer *m* (1<=≤<=*m*<=≤<=100) — the number o...
Print *m* lines, each should contain one integer — the answer to the question after the corresponding operation.
[ "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4\n" ]
[ "1\n2\n0\n" ]
On the first operation, a new string "0110" is created. For *k* = 1 the two possible binary strings of length *k* are "0" and "1", they are substrings of the new string. For *k* = 2 and greater there exist strings of length *k* that do not appear in this string (for *k* = 2 such string is "00"). So the answer is 1. On...
1,500
[ { "input": "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4", "output": "1\n2\n0" }, { "input": "5\n01\n1\n0011\n0\n01\n6\n5 5\n3 2\n4 2\n6 7\n5 1\n9 7", "output": "1\n1\n1\n2\n1\n2" }, { "input": "5\n111101000111100011100110000100\n000111001\n01101000\n000011010010001001100100000001010010011...
1,549,546,696
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
1,544
9,216,000
def abc (w,x,y,s) : s1 = s[x] + s[y] d1={} co=0 for i in range(len(s1)-w+1) : k = s1[i:i+w] p=0 for j in range (len(k)): for w1 in range (j,len(k)) : if k[w1:len(k)] not in d1 : d1[k[w1:len(k)]]=1 co+=...
Title: Huge Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* strings *s*1,<=*s*2,<=...,<=*s**n* consisting of characters 0 and 1. *m* operations are performed, on each of them you concatenate two existing strings into a new one. On the *i*-th operation the concaten...
```python def abc (w,x,y,s) : s1 = s[x] + s[y] d1={} co=0 for i in range(len(s1)-w+1) : k = s1[i:i+w] p=0 for j in range (len(k)): for w1 in range (j,len(k)) : if k[w1:len(k)] not in d1 : d1[k[w1:len(k)]]=1 ...
0
63
A
Sinking Ship
PROGRAMMING
900
[ "implementation", "sortings", "strings" ]
A. Sinking Ship
2
256
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri...
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa...
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
[ "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n" ]
[ "Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n" ]
none
500
[ { "input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack" }, { "input": "1\nA captain", "output": "A" }, { "input": "1\nAbcdefjhij captain", "output": "Abcdefjhij" }, { "input": "5\nA captain...
1,603,564,984
2,147,483,647
PyPy 3
OK
TESTS
26
374
0
a = [] rat = [] wmn = [] man = [] cap = [] for j in range(int(input())): s = input() a.append(s) for j in a: s = j[j.find(' ')+1:len(j)] if(s == str("rat")): rat.append(j) elif(s== "woman" or s== "child" ): wmn.append(j) elif(s == "man"): man.append(j) elif(s== "...
Title: Sinking Ship Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ...
```python a = [] rat = [] wmn = [] man = [] cap = [] for j in range(int(input())): s = input() a.append(s) for j in a: s = j[j.find(' ')+1:len(j)] if(s == str("rat")): rat.append(j) elif(s== "woman" or s== "child" ): wmn.append(j) elif(s == "man"): man.append(j) ...
3.9065
283
A
Cows and Sequence
PROGRAMMING
1,600
[ "constructive algorithms", "data structures", "implementation" ]
null
null
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following: 1. Add the integer *x**i* to the first *a**i* elements of the sequence. 1. Append an integer *k**i* to the end of ...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of operations. The next *n* lines describe the operations. Each line will start with an integer *t**i* (1<=≤<=*t**i*<=≤<=3), denoting the type of the operation (see above). If *t**i*<==<=1, it will be followed by two integers *a**i*,<=*x**i...
Output *n* lines each containing the average of the numbers in the sequence after the corresponding operation. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "5\n2 1\n3\n2 3\n2 1\n3\n", "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3\n" ]
[ "0.500000\n0.000000\n1.500000\n1.333333\n1.500000\n", "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000\n" ]
In the second sample, the sequence becomes <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fb5aaaa5dc516fe540cef52fd153768bfdb941c8.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "5\n2 1\n3\n2 3\n2 1\n3", "output": "0.500000\n0.000000\n1.500000\n1.333333\n1.500000" }, { "input": "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3", "output": "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000" }, { "input": "1\n1 1 1", "output": "1.000000" }, { ...
1,610,902,919
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
1
124
2,048,000
def sr(a, n): return a / n n = int(input()) a = [0] sm = 0 l = 1 for i in range(n): t = list(map(int, input().split())) if t[0] == 1: for i in range(min(l, r[2])): a[i] += t[1] sm += t[1] print(sr(sm, l)) elif t[0] == 2: a += [t[1]] ...
Title: Cows and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following: 1. Add the i...
```python def sr(a, n): return a / n n = int(input()) a = [0] sm = 0 l = 1 for i in range(n): t = list(map(int, input().split())) if t[0] == 1: for i in range(min(l, r[2])): a[i] += t[1] sm += t[1] print(sr(sm, l)) elif t[0] == 2: a += [t...
-1
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", ...
1,666,543,002
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
92
0
n = int(input()) if n%2 == 1: print(-1) else: l = list(range(1, n+1)) L = l[::-1] print(''.join(str(j) for j in L))
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ...
```python n = int(input()) if n%2 == 1: print(-1) else: l = list(range(1, n+1)) L = l[::-1] print(''.join(str(j) for j in L)) ```
0
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on...
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,667,898,868
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
n,m=map(int,input().split(' ')) s=0 x=0 a=n while(a>=m): x+=a%m a=int(a/m) s=s+a if int(x/m)>=1: print(s+n+x) else: print(s+n)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th...
```python n,m=map(int,input().split(' ')) s=0 x=0 a=n while(a>=m): x+=a%m a=int(a/m) s=s+a if int(x/m)>=1: print(s+n+x) else: print(s+n) ```
0
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which int...
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" ...
1,634,452,446
2,147,483,647
Python 3
OK
TESTS
64
62
0
t=(input()) z=int(t)%10 if t[-1]==0: print(t) elif z>5: t=int(t) t=t+10-z print(t) else: t=int(t) t=t-z print(t)
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5...
```python t=(input()) z=int(t)%10 if t[-1]==0: print(t) elif z>5: t=int(t) t=t+10-z print(t) else: t=int(t) t=t-z print(t) ```
3
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,579,312,257
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
12
280
0
n, m = map(int, input().split()) prices = [int(p) for p in input().split()] tvs = [] for p in prices: if p < 0: tvs.append(p * -1) l = len(tvs) if l <= m: print(sum(tvs)) else: tvs.sort() print(sum(tvs[:m]))
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python n, m = map(int, input().split()) prices = [int(p) for p in input().split()] tvs = [] for p in prices: if p < 0: tvs.append(p * -1) l = len(tvs) if l <= m: print(sum(tvs)) else: tvs.sort() print(sum(tvs[:m])) ```
0
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", ...
1,613,385,444
2,147,483,647
Python 3
OK
TESTS
54
77
307,200
n = int(input()) w = str(input()) w = w + 'W' t = 0 c = [0]*n j = 0 for i in range(n+1): if w[i] == 'B': t+=1 if i + 1 >= len(w): break if w[i+1] == 'W': c[j] = t j+=1 t = 0 e= c.count(0) for i in range(e): c.remove(0) print(len(c)) for i in range(len(c)): p...
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the...
```python n = int(input()) w = str(input()) w = w + 'W' t = 0 c = [0]*n j = 0 for i in range(n+1): if w[i] == 'B': t+=1 if i + 1 >= len(w): break if w[i+1] == 'W': c[j] = t j+=1 t = 0 e= c.count(0) for i in range(e): c.remove(0) print(len(c)) for i in range(len...
3
658
A
Bear and Reverse Radewoosh
PROGRAMMING
800
[ "implementation" ]
null
null
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff...
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=&lt;<=*p**i*<=+<=1) — initial scores. The third...
Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.
[ "3 2\n50 85 250\n10 15 25\n", "3 6\n50 85 250\n10 15 25\n", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n" ]
[ "Limak\n", "Radewoosh\n", "Tie\n" ]
In the first sample, there are 3 problems. Limak solves them as follows: 1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85...
500
[ { "input": "3 2\n50 85 250\n10 15 25", "output": "Limak" }, { "input": "3 6\n50 85 250\n10 15 25", "output": "Radewoosh" }, { "input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76", "output": "Tie" }, { "input": "4 1\n3 5 6 9\n1 2 4 8", "output": "Limak" }, {...
1,648,375,506
2,147,483,647
Python 3
OK
TESTS
29
46
0
n,c=map(int,input().split()) p=list(map(int,input().split())) t=list(map(int,input().split())) l=[] r=[] for i in range(len(p)): l.append(max(0,p[i]-c*sum(t[:i+1]))) for i in range(len(p)): r.append(max(0,p[n-i-1]-c*sum(t[n-i-1:]))) if(sum(l)>sum(r)): print('Limak') elif(sum(l)<sum(r)): prin...
Title: Bear and Reverse Radewoosh Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-...
```python n,c=map(int,input().split()) p=list(map(int,input().split())) t=list(map(int,input().split())) l=[] r=[] for i in range(len(p)): l.append(max(0,p[i]-c*sum(t[:i+1]))) for i in range(len(p)): r.append(max(0,p[n-i-1]-c*sum(t[n-i-1:]))) if(sum(l)>sum(r)): print('Limak') elif(sum(l)<sum(r)):...
3
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output"...
1,560,768,537
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
93
0
Y,B=map(int,input().split()) y,g,b=map(int,input().split()) ye=(2*y+(g))+(3*b+(g)) if ((Y+B)-ye)>0: print("0") else: print(abs((Y+B)-ye))
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obta...
```python Y,B=map(int,input().split()) y,g,b=map(int,input().split()) ye=(2*y+(g))+(3*b+(g)) if ((Y+B)-ye)>0: print("0") else: print(abs((Y+B)-ye)) ```
0
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,594,120,453
2,147,483,647
Python 3
OK
TESTS
10
109
6,963,200
def main(): n=int(input()) refer = {} refer[1] = [1 for i in range(n)] for i in range(2,n+1): row_prev = refer[i-1] row = [1] for j in range(0,n-1): row.append(row[j]+row_prev[j+1]) refer[i] = row print(refer[n][-1]) if __name__ == "__main...
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python def main(): n=int(input()) refer = {} refer[1] = [1 for i in range(n)] for i in range(2,n+1): row_prev = refer[i-1] row = [1] for j in range(0,n-1): row.append(row[j]+row_prev[j+1]) refer[i] = row print(refer[n][-1]) if __name__ ...
3
753
A
Santa Claus and Candies
PROGRAMMING
1,000
[ "dp", "greedy", "math" ]
null
null
Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has.
The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has.
Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them.
[ "5\n", "9\n", "2\n" ]
[ "2\n2 3\n", "3\n3 5 1\n", "1\n2 \n" ]
none
500
[ { "input": "5", "output": "2\n1 4 " }, { "input": "9", "output": "3\n1 2 6 " }, { "input": "2", "output": "1\n2 " }, { "input": "1", "output": "1\n1 " }, { "input": "3", "output": "2\n1 2 " }, { "input": "1000", "output": "44\n1 2 3 4 5 6 7 8 9 10 ...
1,545,553,427
2,147,483,647
PyPy 3
OK
TESTS
49
124
0
n=int(input()) a=[0]*50 i=1;cnt=0 while(True): if n-i>=i+1: a[i]=i;cnt+=1 n-=i;i+=1 else: a[i]=n cnt+=1 break print(cnt) print(*a[1:cnt+1])
Title: Santa Claus and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n...
```python n=int(input()) a=[0]*50 i=1;cnt=0 while(True): if n-i>=i+1: a[i]=i;cnt+=1 n-=i;i+=1 else: a[i]=n cnt+=1 break print(cnt) print(*a[1:cnt+1]) ```
3
965
C
Greedy Arkady
PROGRAMMING
2,000
[ "math" ]
null
null
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ...
The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ...
Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$.
[ "20 4 5 2\n", "30 9 4 1\n" ]
[ "8\n", "4\n" ]
In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total...
1,500
[ { "input": "20 4 5 2", "output": "8" }, { "input": "30 9 4 1", "output": "4" }, { "input": "2 2 1 1", "output": "1" }, { "input": "42 20 5 29", "output": "5" }, { "input": "1000000000000000000 135 1000000000000000 1000", "output": "8325624421831635" }, { ...
1,524,680,993
3,293
PyPy 3
WRONG_ANSWER
PRETESTS
4
78
21,401,600
n, k, M, D = map(int, input().split()) ans = 0 for i in range(2, D+1): if ((n + k*i - 1)// (k * i)) < (n + k*(i-1) -1)//(k*(i-1)): x = (n + k*(i-1) - 1)//(k*(i-1)) - 1 if x <= M: ans = max(ans, x*i) ans = max(ans, M) print(ans)
Title: Greedy Arkady Time Limit: None seconds Memory Limit: None megabytes Problem Description: $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka...
```python n, k, M, D = map(int, input().split()) ans = 0 for i in range(2, D+1): if ((n + k*i - 1)// (k * i)) < (n + k*(i-1) -1)//(k*(i-1)): x = (n + k*(i-1) - 1)//(k*(i-1)) - 1 if x <= M: ans = max(ans, x*i) ans = max(ans, M) print(ans) ```
0
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,592,921,105
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
6,656,000
Sticks = list(map(int,input().split())) variations = len(set(Sticks)) if variations==2: print("Elephant") elif variations==3: print("Bear") else: print("Alien")
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 Sticks = list(map(int,input().split())) variations = len(set(Sticks)) if variations==2: print("Elephant") elif variations==3: print("Bear") else: print("Alien") ```
0
0
none
none
none
0
[ "none" ]
null
null
You have multiset of *n* strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position *i* and some letter *c* of the English alphabet, such that this string is the only string in the multiset that has letter *c* in pos...
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=20) — the number of strings in the multiset and the length of the strings respectively. Next *n* lines contain the strings of the multiset, consisting only of lowercase English letters, each string's length is *m*. Next *n* lines contain *m* integers e...
Print a single number — the answer to the problem.
[ "4 5\nabcde\nabcde\nabcde\nabcde\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n", "4 3\nabc\naba\nadc\nada\n10 10 10\n10 1 10\n10 10 10\n10 1 10\n", "3 3\nabc\nada\nssa\n1 1 1\n1 1 1\n1 1 1\n" ]
[ "3\n", "2\n", "0\n" ]
none
0
[ { "input": "4 5\nabcde\nabcde\nabcde\nabcde\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "output": "3" }, { "input": "4 3\nabc\naba\nadc\nada\n10 10 10\n10 1 10\n10 10 10\n10 1 10", "output": "2" }, { "input": "3 3\nabc\nada\nssa\n1 1 1\n1 1 1\n1 1 1", "output": "0" }, { "in...
1,689,647,894
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
print("_RANDOM_GUESS_1689647894.6279874")# 1689647894.628007
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have multiset of *n* strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position *i* and some letter *c* of the English alp...
```python print("_RANDOM_GUESS_1689647894.6279874")# 1689647894.628007 ```
0
653
B
Bear and Compressing
PROGRAMMING
1,300
[ "brute force", "dfs and similar", "dp", "strings" ]
null
null
Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of *q* possible operations. Limak can perform them in any order...
The first line contains two integers *n* and *q* (2<=≤<=*n*<=≤<=6, 1<=≤<=*q*<=≤<=36) — the length of the initial string and the number of available operations. The next *q* lines describe the possible operations. The *i*-th of them contains two strings *a**i* and *b**i* (|*a**i*|<==<=2,<=|*b**i*|<==<=1). It's guarante...
Print the number of strings of length *n* that Limak will be able to transform to string "a" by applying only operations given in the input.
[ "3 5\nab a\ncc c\nca a\nee c\nff d\n", "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c\n", "6 2\nbb a\nba a\n" ]
[ "4\n", "1\n", "0\n" ]
In the first sample, we count initial strings of length 3 from which Limak can get a required string "a". There are 4 such strings: "abb", "cab", "cca", "eea". The first one Limak can compress using operation 1 two times (changing "ab" to a single "a"). The first operation would change "abb" to "ab" and the second oper...
1,000
[ { "input": "3 5\nab a\ncc c\nca a\nee c\nff d", "output": "4" }, { "input": "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c", "output": "1" }, { "input": "6 2\nbb a\nba a", "output": "0" }, { "input": "2 5\nfe b\nbb a\naf b\nfd b\nbf c", "output": "1" }, { "i...
1,674,819,575
2,147,483,647
Python 3
OK
TESTS
32
61
102,400
from collections import defaultdict n, q = [int(e) for e in input().split() ] operations = defaultdict(list) count = [0 ] def solve(string, depth,count): # print(string, depth) if depth == n : # print(f'count: {count}') count[0] += 1 else: children = operations[st...
Title: Bear and Compressing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', '...
```python from collections import defaultdict n, q = [int(e) for e in input().split() ] operations = defaultdict(list) count = [0 ] def solve(string, depth,count): # print(string, depth) if depth == n : # print(f'count: {count}') count[0] += 1 else: children = ope...
3
439
B
Devu, the Dumb Guy
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other ...
The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105).
Output a single integer representing the answer to the problem.
[ "2 3\n4 1\n", "4 2\n5 1 2 1\n", "3 3\n1 1 1\n" ]
[ "11\n", "10\n", "6\n" ]
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ...
1,000
[ { "input": "2 3\n4 1", "output": "11" }, { "input": "4 2\n5 1 2 1", "output": "10" }, { "input": "3 3\n1 1 1", "output": "6" }, { "input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "output": "65" }, { "input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3...
1,647,239,424
2,147,483,647
Python 3
OK
TESTS
31
140
7,372,800
n, x = map(int, input().split()) c = list(map(int, input().split())) c = sorted(c) res = 0 for s in c: res += s * x if x > 1: x -= 1 print(res)
Title: Devu, the Dumb Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co...
```python n, x = map(int, input().split()) c = list(map(int, input().split())) c = sorted(c) res = 0 for s in c: res += s * x if x > 1: x -= 1 print(res) ```
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,698,234,820
2,147,483,647
Python 3
OK
TESTS
62
46
0
#https://codeforces.com/contest/791/problem/A a,b = map(int,input().split()); ans = 0 while (a<=b): a*=3 b*=2 ans+=1 print(ans)
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 #https://codeforces.com/contest/791/problem/A a,b = map(int,input().split()); ans = 0 while (a<=b): a*=3 b*=2 ans+=1 print(ans) ```
3
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,649,511,952
2,147,483,647
Python 3
OK
TESTS
10
46
0
n = int(input()) if n <= 2: print(n) else: matrix = [] m = [] for i in range(n): m.append(1) matrix.append(m) for i in range(1,n): a = [1] for j in range(1,n): x = a[j-1]+matrix[i-1][j] a.append(x) matrix.append(a) print(matrix[-1][-1])
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n = int(input()) if n <= 2: print(n) else: matrix = [] m = [] for i in range(n): m.append(1) matrix.append(m) for i in range(1,n): a = [1] for j in range(1,n): x = a[j-1]+matrix[i-1][j] a.append(x) matrix.append(a) print(matrix[-1][-1]) ``...
3
385
A
Bear and Raspberry
PROGRAMMING
1,000
[ "brute force", "greedy", "implementation" ]
null
null
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry. Unfo...
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100...
Print a single integer — the answer to the problem.
[ "5 1\n5 10 7 3 20\n", "6 2\n100 1 10 40 10 40\n", "3 0\n1 2 3\n" ]
[ "3\n", "97\n", "0\n" ]
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3. In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da...
500
[ { "input": "5 1\n5 10 7 3 20", "output": "3" }, { "input": "6 2\n100 1 10 40 10 40", "output": "97" }, { "input": "3 0\n1 2 3", "output": "0" }, { "input": "2 0\n2 1", "output": "1" }, { "input": "10 5\n10 1 11 2 12 3 13 4 14 5", "output": "4" }, { "in...
1,623,399,387
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
108
0
n,c=map(int,input().split()) l=[*map(int,input().split())] small=l.index(min(l)) if small==0: print(0) else: print(l[small-1]-l[small]-c)
Title: Bear and Raspberry Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1...
```python n,c=map(int,input().split()) l=[*map(int,input().split())] small=l.index(min(l)) if small==0: print(0) else: print(l[small-1]-l[small]-c) ```
0
794
A
Bank Robbery
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f...
The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=&lt;<=*a*<=&lt;<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively. The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the numbe...
Output a single integer: the maximum number of banknotes Oleg can take.
[ "5 3 7\n8\n4 7 5 5 3 6 2 8\n", "6 5 7\n5\n1 5 7 92 3\n" ]
[ "4\n", "0\n" ]
In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se...
500
[ { "input": "5 3 7\n8\n4 7 5 5 3 6 2 8", "output": "4" }, { "input": "6 5 7\n5\n1 5 7 92 3", "output": "0" }, { "input": "3 2 4\n1\n3", "output": "1" }, { "input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6", "output": "8" }, { "input": "7 3 10\n5\n3 3 3 3 3", "output...
1,548,356,986
2,147,483,647
Python 3
OK
TESTS
46
155
8,396,800
def oleg_grabit(lst, b, c): result = 0 for elem in lst: if b < elem < c: result += 1 return result A, B, C = [int(i) for i in input().split()] n = int(input()) z = [int(j) for j in input().split()] print(oleg_grabit(z, B, C))
Title: Bank Robbery Time Limit: None seconds Memory Limit: None megabytes Problem Description: A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and...
```python def oleg_grabit(lst, b, c): result = 0 for elem in lst: if b < elem < c: result += 1 return result A, B, C = [int(i) for i in input().split()] n = int(input()) z = [int(j) for j in input().split()] print(oleg_grabit(z, B, C)) ```
3
996
A
Hit the Lottery
PROGRAMMING
800
[ "dp", "greedy" ]
null
null
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output the minimum number of bills that Allen could receive.
[ "125\n", "43\n", "1000000000\n" ]
[ "3\n", "5\n", "10000000\n" ]
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen...
500
[ { "input": "125", "output": "3" }, { "input": "43", "output": "5" }, { "input": "1000000000", "output": "10000000" }, { "input": "4", "output": "4" }, { "input": "5", "output": "1" }, { "input": "1", "output": "1" }, { "input": "74", "o...
1,693,850,519
2,147,483,647
Python 3
OK
TESTS
49
46
0
n=int(input()) denominations=[100,20,10,5,1] count=0 for denom in denominations: count += n//denom n%=denom print(count)
Title: Hit the Lottery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$...
```python n=int(input()) denominations=[100,20,10,5,1] count=0 for denom in denominations: count += n//denom n%=denom print(count) ```
3
902
B
Coloring a Tree
PROGRAMMING
1,200
[ "dfs and similar", "dsu", "greedy" ]
null
null
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1. Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0. You have to color the tree into the given colors using the smallest possible number of steps. On eac...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*. The third line contains *n* integers *c*1,<...
Print a single integer — the minimum number of steps you have to perform to color the tree into given colors.
[ "6\n1 2 2 1 5\n2 1 1 1 1 1\n", "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n" ]
[ "3\n", "5\n" ]
The tree from the first sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color ...
1,000
[ { "input": "6\n1 2 2 1 5\n2 1 1 1 1 1", "output": "3" }, { "input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3", "output": "5" }, { "input": "2\n1\n2 2", "output": "1" }, { "input": "3\n1 1\n2 2 2", "output": "1" }, { "input": "4\n1 2 1\n1 2 3 4", "output": "4" }, { ...
1,513,978,363
2,147,483,647
Python 3
OK
TESTS
50
92
7,987,200
class Node(object): def __init__(self, n, color): self.n = n self.color = color def main(): nv = int(input()) l = input() l = l.split(' ') l = [int(i) for i in l] g = [[] for i in range(0, nv+1)] c = 2 for v in l: g[v].append(c) c += 1 colors = inp...
Title: Coloring a Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1. Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0. ...
```python class Node(object): def __init__(self, n, color): self.n = n self.color = color def main(): nv = int(input()) l = input() l = l.split(' ') l = [int(i) for i in l] g = [[] for i in range(0, nv+1)] c = 2 for v in l: g[v].append(c) c += 1 co...
3
442
B
Andrey and Problem
PROGRAMMING
1,800
[ "greedy", "math", "probabilities" ]
null
null
Andrey needs one more problem to conduct a programming contest. He has *n* friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him. Help Andrey choo...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of Andrey's friends. The second line contains *n* real numbers *p**i* (0.0<=≤<=*p**i*<=≤<=1.0) — the probability that the *i*-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.
Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10<=-<=9.
[ "4\n0.1 0.2 0.3 0.8\n", "2\n0.1 0.2\n" ]
[ "0.800000000000\n", "0.260000000000\n" ]
In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one. In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.
1,500
[ { "input": "4\n0.1 0.2 0.3 0.8", "output": "0.800000000000" }, { "input": "2\n0.1 0.2", "output": "0.260000000000" }, { "input": "1\n0.217266", "output": "0.217266000000" }, { "input": "2\n0.608183 0.375030", "output": "0.608183000000" }, { "input": "3\n0.388818 0...
1,538,151,983
2,147,483,647
Python 3
OK
TESTS
60
155
409,600
from decimal import Decimal as fr ans = 0 n = int(input()) a = list(map(fr, input().split())) ans = max(a) def calc(lst): global ans prod = 1 for i in range(len(lst)): prod *= 1 - lst[i] cur = 0 for j in range(i + 1): cur += lst[j] * prod / (1 - lst[j]) # p...
Title: Andrey and Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrey needs one more problem to conduct a programming contest. He has *n* friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fie...
```python from decimal import Decimal as fr ans = 0 n = int(input()) a = list(map(fr, input().split())) ans = max(a) def calc(lst): global ans prod = 1 for i in range(len(lst)): prod *= 1 - lst[i] cur = 0 for j in range(i + 1): cur += lst[j] * prod / (1 - lst[j]) ...
3
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half...
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the...
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n...
1,635,835,104
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
22
92
4,505,600
n=int(input()) up=[] down=[] for i in range(n): a,b=map(int,input().split()) up.append(a) down.append(b) if sum(up)%2==0 and sum(down)%2==0: print(0) exit() time=0 for i in range(n): up[i],down[i]=down[i],up[i] time+=1 if sum(up)%2==0 and sum(down)%2==0: print(time...
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n...
```python n=int(input()) up=[] down=[] for i in range(n): a,b=map(int,input().split()) up.append(a) down.append(b) if sum(up)%2==0 and sum(down)%2==0: print(0) exit() time=0 for i in range(n): up[i],down[i]=down[i],up[i] time+=1 if sum(up)%2==0 and sum(down)%2==0: ...
0
932
A
Palindromic Supersequence
PROGRAMMING
800
[ "constructive algorithms" ]
null
null
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ...
First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*.
Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them.
[ "aba\n", "ab\n" ]
[ "aba", "aabaa" ]
In the first example, "aba" is a subsequence of "aba" which is a palindrome. In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.
500
[ { "input": "aba", "output": "abaaba" }, { "input": "ab", "output": "abba" }, { "input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk...
1,575,102,922
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
43
124
0
import math # y, x = list(map(int, input().split("\n"))) x = input().strip() def test_3(x): len_1 = len(x) if len_1 % 2 == 1: a = len_1//2 if x[:a] == x[-a:]: return x else: # print(x[(len_1-2)::-1]) return x + x[(len_1-2)::-1] else: a = ...
Title: Palindromic Supersequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co...
```python import math # y, x = list(map(int, input().split("\n"))) x = input().strip() def test_3(x): len_1 = len(x) if len_1 % 2 == 1: a = len_1//2 if x[:a] == x[-a:]: return x else: # print(x[(len_1-2)::-1]) return x + x[(len_1-2)::-1] else: ...
0
330
B
Road Construction
PROGRAMMING
1,300
[ "constructive algorithms", "graphs" ]
null
null
A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two...
The first line consists of two integers *n* and *m* . Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*....
You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*....
[ "4 1\n1 3\n" ]
[ "3\n1 2\n4 2\n2 3\n" ]
This is one possible solution of the example: These are examples of wrong solutions:
1,000
[ { "input": "4 1\n1 3", "output": "3\n1 2\n4 2\n2 3" }, { "input": "1000 0", "output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 ...
1,641,794,060
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
60
0
s = input().split() (n,m) = (int(i) for i in s) a = [i for i in range(1,n+1)] for i in range(m): s = input().split() a.remove(int(s[0])) a.remove(int(s[1])) k = a[0] print(n-1) for i in range(n): if(k == (i+1)): continue else: print(k,(i+1))
Title: Road Construction Time Limit: None seconds Memory Limit: None megabytes Problem Description: A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constru...
```python s = input().split() (n,m) = (int(i) for i in s) a = [i for i in range(1,n+1)] for i in range(m): s = input().split() a.remove(int(s[0])) a.remove(int(s[1])) k = a[0] print(n-1) for i in range(n): if(k == (i+1)): continue else: print(k,(i+1)) ```
-1
330
B
Road Construction
PROGRAMMING
1,300
[ "constructive algorithms", "graphs" ]
null
null
A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two...
The first line consists of two integers *n* and *m* . Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*....
You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*....
[ "4 1\n1 3\n" ]
[ "3\n1 2\n4 2\n2 3\n" ]
This is one possible solution of the example: These are examples of wrong solutions:
1,000
[ { "input": "4 1\n1 3", "output": "3\n1 2\n4 2\n2 3" }, { "input": "1000 0", "output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 ...
1,602,792,006
2,147,483,647
Python 3
OK
TESTS
43
248
409,600
#import resource import sys #resource.setrlimit(resource.RLIMIT_STACK, (2**29, -1)) sys.setrecursionlimit(10 ** 7) from collections import deque import math n, m = [int(x) for x in input().split()] root = 0 canberoot = [True] * (n+1) for _ in range(m): a, b = [int(x) for x in input().split()] c...
Title: Road Construction Time Limit: None seconds Memory Limit: None megabytes Problem Description: A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constru...
```python #import resource import sys #resource.setrlimit(resource.RLIMIT_STACK, (2**29, -1)) sys.setrecursionlimit(10 ** 7) from collections import deque import math n, m = [int(x) for x in input().split()] root = 0 canberoot = [True] * (n+1) for _ in range(m): a, b = [int(x) for x in input().split...
3
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,697,722,830
2,147,483,647
Python 3
OK
TESTS
36
46
0
t = int(input("")) x = 0 for i in range (0,t): statement = input("") if statement[1] == '+': x = x + 1 else: x = 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 t = int(input("")) x = 0 for i in range (0,t): statement = input("") if statement[1] == '+': x = x + 1 else: x = x - 1 print(x) ```
3
501
A
Contest
PROGRAMMING
900
[ "implementation" ]
null
null
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ...
The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round).
Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.
[ "500 1000 20 30\n", "1000 1000 1 1\n", "1500 1000 176 177\n" ]
[ "Vasya\n", "Tie\n", "Misha\n" ]
none
500
[ { "input": "500 1000 20 30", "output": "Vasya" }, { "input": "1000 1000 1 1", "output": "Tie" }, { "input": "1500 1000 176 177", "output": "Misha" }, { "input": "1500 1000 74 177", "output": "Misha" }, { "input": "750 2500 175 178", "output": "Vasya" }, { ...
1,698,997,438
2,147,483,647
Python 3
OK
TESTS
40
46
0
a_for_misha, b_for_vasya, c_for_misha, d_for_vasya = map( int, input().split() ) misha_score = max( (3*a_for_misha)//10, a_for_misha - (a_for_misha//250) * c_for_misha ) vasya_score = max( (3 * b_for_vasya) // 10, b_for_vasya - (b_for_vasya//250) * d_for_vasya ) if misha_score > vasya_score: print("Misha") ...
Title: Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t...
```python a_for_misha, b_for_vasya, c_for_misha, d_for_vasya = map( int, input().split() ) misha_score = max( (3*a_for_misha)//10, a_for_misha - (a_for_misha//250) * c_for_misha ) vasya_score = max( (3 * b_for_vasya) // 10, b_for_vasya - (b_for_vasya//250) * d_for_vasya ) if misha_score > vasya_score: print...
3
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,623,753,708
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
154
0
n=int(input()) a=0 b=1 c=1 s=2 while s<n: a=b b=c c=s s=c+b if s==n: print(a,b,b) else: print("I'm too stupid to solve this problem")
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 n=int(input()) a=0 b=1 c=1 s=2 while s<n: a=b b=c c=s s=c+b if s==n: print(a,b,b) else: print("I'm too stupid to solve this problem") ```
0
735
B
Urbanization
PROGRAMMING
1,100
[ "greedy", "number theory", "sortings" ]
null
null
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second ...
The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city. The second line conta...
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your ...
[ "2 1 1\n1 5\n", "4 2 1\n1 4 2 3\n" ]
[ "6.00000000\n", "6.50000000\n" ]
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second. In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class=...
1,000
[ { "input": "2 1 1\n1 5", "output": "6.00000000" }, { "input": "4 2 1\n1 4 2 3", "output": "6.50000000" }, { "input": "3 1 2\n1 2 3", "output": "4.50000000" }, { "input": "10 4 6\n3 5 7 9 12 25 67 69 83 96", "output": "88.91666667" }, { "input": "19 7 12\n1 2 4 8 1...
1,594,714,013
2,147,483,647
PyPy 3
OK
TESTS
37
218
30,412,800
n,n1,n2=map(int,input().split()) a=list(map(int,input().split())) a.sort() if(n1<=n2): a1=0 c1=0 for j in range(len(a)-1,-1,-1): if(c1>=n1): break else: a1=a1+a[j] c1=c1+1 a1=a1/n1 a2=0 c2=0 for i in range(j,-1,-1): if(c2>=n2): break else: a2=a2+a[i] c2=c2+1 a2=a2/...
Title: Urbanization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* o...
```python n,n1,n2=map(int,input().split()) a=list(map(int,input().split())) a.sort() if(n1<=n2): a1=0 c1=0 for j in range(len(a)-1,-1,-1): if(c1>=n1): break else: a1=a1+a[j] c1=c1+1 a1=a1/n1 a2=0 c2=0 for i in range(j,-1,-1): if(c2>=n2): break else: a2=a2+a[i] c2=c2+...
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,648,566,396
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
0
str=input() found,found1,found2,found3,found4=False,False,False,False,False for i in range(len(str)): if found==True: break if found4==True: if str[i]=='o': found=True if found3== True: if str[i]=='l': found4=True if found2==True: if st...
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 str=input() found,found1,found2,found3,found4=False,False,False,False,False for i in range(len(str)): if found==True: break if found4==True: if str[i]=='o': found=True if found3== True: if str[i]=='l': found4=True if found2==True: ...
3.969
430
B
Balls Game
PROGRAMMING
1,400
[ "brute force", "two pointers" ]
null
null
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at...
The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*. It is guaranteed th...
Print a single integer — the maximum number of balls Iahub can destroy.
[ "6 2 2\n1 1 2 2 1 1\n", "1 1 1\n1\n" ]
[ "6\n", "0\n" ]
none
1,000
[ { "input": "6 2 2\n1 1 2 2 1 1", "output": "6" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 2 1\n2 1 2 2 1 2 2 1 1 2", "output": "5" }, { "input": "50 2 1\n1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 1 1 2", "...
1,569,722,651
2,147,483,647
Python 3
OK
TESTS
18
124
0
#https://codeforces.com/problemset/problem/430/B ''' Comment ''' n = 0 k = 0 x = 0 balls = [] def cntBall(pos): l = r = pos cnt = 0 while balls[l] == balls[r]: tmp = 2 while l > 0 and balls[l - 1] == balls[l]: l -= 1 tmp += 1 while r < ...
Title: Balls Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more conti...
```python #https://codeforces.com/problemset/problem/430/B ''' Comment ''' n = 0 k = 0 x = 0 balls = [] def cntBall(pos): l = r = pos cnt = 0 while balls[l] == balls[r]: tmp = 2 while l > 0 and balls[l - 1] == balls[l]: l -= 1 tmp += 1 ...
3
911
B
Two Cakes
PROGRAMMING
1,200
[ "binary search", "brute force", "implementation" ]
null
null
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ...
The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
[ "5 2 3\n", "4 7 10\n" ]
[ "1\n", "3\n" ]
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
0
[ { "input": "5 2 3", "output": "1" }, { "input": "4 7 10", "output": "3" }, { "input": "100 100 100", "output": "2" }, { "input": "10 100 3", "output": "3" }, { "input": "2 9 29", "output": "9" }, { "input": "4 6 10", "output": "3" }, { "inp...
1,563,561,015
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
124
0
def f(n, a, b, x): m = min(a, b) // x return m < n and (n - m) * x <= max(a, b) n, a, b = map(int, input().split()) left, right = 0, a + b while left + 1 < right: mid = left + (right - left) // 2 if not f(n, a, b, mid): right = mid else: left = mid # print(left...
Title: Two Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Iv...
```python def f(n, a, b, x): m = min(a, b) // x return m < n and (n - m) * x <= max(a, b) n, a, b = map(int, input().split()) left, right = 0, a + b while left + 1 < right: mid = left + (right - left) // 2 if not f(n, a, b, mid): right = mid else: left = mid # ...
0
0
none
none
none
0
[ "none" ]
null
null
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert...
The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*...
Print a single integer number, the maximum number of letters that Nastya can remove.
[ "ababcba\nabb\n5 3 4 1 7 6 2\n", "bbbabb\nbb\n1 6 3 4 2 5\n" ]
[ "3", "4" ]
In the first sample test sequence of removing made by Nastya looks like this: "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https...
0
[ { "input": "ababcba\nabb\n5 3 4 1 7 6 2", "output": "3" }, { "input": "bbbabb\nbb\n1 6 3 4 2 5", "output": "4" }, { "input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2", "output": "9" }, { "input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1...
1,654,177,130
2,147,483,647
Python 3
OK
TESTS
43
967
16,281,600
start = list(input()) end = list(input()) nums = list(map(int, input().split())) def ifpossible(mid): temp = start.copy() for i in range(mid): temp[nums[i] - 1] = 0 ptr = 0 for i in range(len(temp)): if (temp[i] == end[ptr]): ptr += 1 if (ptr == len...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nas...
```python start = list(input()) end = list(input()) nums = list(map(int, input().split())) def ifpossible(mid): temp = start.copy() for i in range(mid): temp[nums[i] - 1] = 0 ptr = 0 for i in range(len(temp)): if (temp[i] == end[ptr]): ptr += 1 if (...
3
629
A
Far Relative’s Birthday Cake
PROGRAMMING
800
[ "brute force", "combinatorics", "constructive algorithms", "implementation" ]
null
null
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta...
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
[ "3\n.CC\nC..\nC.C\n", "4\nCC..\nC..C\n.CC.\n.CC.\n" ]
[ "4\n", "9\n" ]
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
500
[ { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9" }, { "input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "output": "46" }, { "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "output": "84" },...
1,662,771,407
2,147,483,647
Python 3
OK
TESTS
48
46
0
from math import factorial def n_pairs(n): return factorial(n) // (factorial(n-2) * 2) n = int(input()) cake_columns = [0 for i in range(n)] total_pairs = 0 for i in range(n): row = list(input()) for j in range(n): if row[j] == 'C': cake_columns[j] += 1 n_cs = row.count('C') if n_cs >= 2: to...
Title: Far Relative’s Birthday Cake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with s...
```python from math import factorial def n_pairs(n): return factorial(n) // (factorial(n-2) * 2) n = int(input()) cake_columns = [0 for i in range(n)] total_pairs = 0 for i in range(n): row = list(input()) for j in range(n): if row[j] == 'C': cake_columns[j] += 1 n_cs = row.count('C') if n_cs >=...
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,377,934,014
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
1,000
921,600
import sys from string import ascii_lowercase f = sys.stdin #f = open("input.txt", "r") a = f.readline().strip() dbs = [i*2 for i in ascii_lowercase] i = 0 while i < len(a)-1: for k in dbs: if a[i:i+2] == k: a = a.replace(k, "") i -= 2 i += 1 print(a)
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 import sys from string import ascii_lowercase f = sys.stdin #f = open("input.txt", "r") a = f.readline().strip() dbs = [i*2 for i in ascii_lowercase] i = 0 while i < len(a)-1: for k in dbs: if a[i:i+2] == k: a = a.replace(k, "") i -= 2 i += 1 print(a) ```
0
988
A
Diverse Team
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"...
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t...
[ "5 3\n15 13 15 15 12\n", "5 4\n15 13 15 15 12\n", "4 4\n20 10 40 30\n" ]
[ "YES\n1 2 5 \n", "NO\n", "YES\n1 2 3 4 \n" ]
All possible answers for the first example: - {1 2 5} - {2 3 5} - {2 4 5} Note that the order does not matter.
0
[ { "input": "5 3\n15 13 15 15 12", "output": "YES\n1 2 5 " }, { "input": "5 4\n15 13 15 15 12", "output": "NO" }, { "input": "4 4\n20 10 40 30", "output": "YES\n1 2 3 4 " }, { "input": "1 1\n1", "output": "YES\n1 " }, { "input": "100 53\n16 17 1 2 27 5 9 9 53 24 17...
1,653,738,622
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
77
0
n,k=map(int,input().split()) s=list(map(int,input().split())) x=set(s) x=list(x) if len(x)==k: print('YES') for i in range(len(x)): y=x[i] print(s.index(y)+1,end=' ') print() else: print('NO')
Title: Diverse Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct...
```python n,k=map(int,input().split()) s=list(map(int,input().split())) x=set(s) x=list(x) if len(x)==k: print('YES') for i in range(len(x)): y=x[i] print(s.index(y)+1,end=' ') print() else: print('NO') ```
0
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 ...
1,628,445,387
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
92
6,758,400
i = input() s = "" li = [] for l in i: s += l if l == " ": li.append(s) s = "" n = int(li[0]) a = int(li[1]) b = int(s) print((n - a))
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h...
```python i = input() s = "" li = [] for l in i: s += l if l == " ": li.append(s) s = "" n = int(li[0]) a = int(li[1]) b = int(s) print((n - a)) ```
0
710
B
Optimal Point on a Line
PROGRAMMING
1,400
[ "brute force", "sortings" ]
null
null
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line. The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
[ "4\n1 2 3 4\n" ]
[ "2\n" ]
none
0
[ { "input": "4\n1 2 3 4", "output": "2" }, { "input": "5\n-1 -10 2 6 7", "output": "2" }, { "input": "10\n-68 10 87 22 30 89 82 -97 -52 25", "output": "22" }, { "input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -...
1,472,199,687
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
4,608,000
import sys n=int(sys.stdin.readline().strip('\n')) points=sys.stdin.readline().strip('\n').split(" ") lengths=[] for i in range(0,len(points)-1): length=0 for j in range(0,len(points)-1): length+=abs(i-j) lengths.append(length) minimum=points[lengths.index(min(lengths))] sys.stdout.wri...
Title: Optimal Point on a Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=...
```python import sys n=int(sys.stdin.readline().strip('\n')) points=sys.stdin.readline().strip('\n').split(" ") lengths=[] for i in range(0,len(points)-1): length=0 for j in range(0,len(points)-1): length+=abs(i-j) lengths.append(length) minimum=points[lengths.index(min(lengths))] sys....
0
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,502,898,416
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
6
92
0
n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) i = 0 while a[i] < 0 and i + 1 <= m: i += 1 print(0 if i == 0 else -sum(a[:i]))
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) i = 0 while a[i] < 0 and i + 1 <= m: i += 1 print(0 if i == 0 else -sum(a[:i])) ```
-1
299
B
Ksusha the Squirrel
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ...
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters e...
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
[ "2 1\n..\n", "5 2\n.#.#.\n", "7 3\n.#.###.\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
1,000
[ { "input": "2 1\n..", "output": "YES" }, { "input": "5 2\n.#.#.", "output": "YES" }, { "input": "7 3\n.#.###.", "output": "NO" }, { "input": "2 200\n..", "output": "YES" }, { "input": "2 1\n..", "output": "YES" }, { "input": "2 2\n..", "output": "Y...
1,696,436,907
2,147,483,647
PyPy 3
OK
TESTS
33
216
3,686,400
n, k = map(int, input().split()) s = input().strip() def can_reach_end(n, k, s): i = 0 while i < n: found_empty = False for j in range(i + 1, min(i + k + 1, n)): if s[j] == ".": i = j found_empty = True break if n...
Title: Ksusha the Squirrel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to t...
```python n, k = map(int, input().split()) s = input().strip() def can_reach_end(n, k, s): i = 0 while i < n: found_empty = False for j in range(i + 1, min(i + k + 1, n)): if s[j] == ".": i = j found_empty = True break ...
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,685,137,017
2,147,483,647
Python 3
OK
TESTS
36
92
0
yakko_points, wakko_points = map(int, input().split()) higher_points_amount = yakko_points if yakko_points > wakko_points else wakko_points numerator = 6 - higher_points_amount + 1 denominator = 6 if numerator % 2 == 0: numerator //= 2 denominator //= 2 if numerator % 3 == 0: numerator //= 3 denominator...
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 yakko_points, wakko_points = map(int, input().split()) higher_points_amount = yakko_points if yakko_points > wakko_points else wakko_points numerator = 6 - higher_points_amount + 1 denominator = 6 if numerator % 2 == 0: numerator //= 2 denominator //= 2 if numerator % 3 == 0: numerator //= 3 d...
3.954
0
none
none
none
0
[ "none" ]
null
null
In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different fl...
The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively. The ...
Print $q$ integers, one per line — the answers for the queries.
[ "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n" ]
[ "7\n5\n4\n" ]
In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit. In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in th...
0
[ { "input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3", "output": "7\n5\n4" }, { "input": "2 2 0 1 1\n\n1\n1\n1 2 2 2", "output": "3" }, { "input": "4 4 1 0 1\n4\n\n5\n1 1 2 2\n1 3 2 2\n3 3 4 3\n3 2 2 2\n1 2 2 3", "output": "6\n4\n3\n5\n4" }, { "input": "10 10 1 8 4\n10\n...
1,525,157,895
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
14,336,000
from math import ceil def lower_bound(nums, target): low, high = 0, len(nums) - 1 pos = len(nums) while low < high: mid = (low + high) // 2 if nums[mid] < target: low = mid + 1 else: # >= high = mid pos = high return pos n, m, cl, ce, v = ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerat...
```python from math import ceil def lower_bound(nums, target): low, high = 0, len(nums) - 1 pos = len(nums) while low < high: mid = (low + high) // 2 if nums[mid] < target: low = mid + 1 else: # >= high = mid pos = high return pos n, m, cl...
0
934
B
A Prosperous Lot
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside. Big Banban is hesitating over the amount ...
The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops.
Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018.
[ "2\n", "6\n" ]
[ "462", "8080" ]
none
1,000
[ { "input": "2", "output": "8" }, { "input": "6", "output": "888" }, { "input": "3", "output": "86" }, { "input": "4", "output": "88" }, { "input": "5", "output": "886" }, { "input": "1000000", "output": "-1" }, { "input": "1", "output":...
1,601,405,897
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
202
2,150,400
n=int(input()) s='' if n==1: s+='4' elif n%2==0: for i in range(n//2): s+='8' elif n//2!=0 and n!=1: for i in range(n//2): s+='8' s+='4' if len(s)>0: print(s) else: print(-1)
Title: A Prosperous Lot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a...
```python n=int(input()) s='' if n==1: s+='4' elif n%2==0: for i in range(n//2): s+='8' elif n//2!=0 and n!=1: for i in range(n//2): s+='8' s+='4' if len(s)>0: print(s) else: print(-1) ```
0
251
A
Points on Line
PROGRAMMING
1,300
[ "binary search", "combinatorics", "two pointers" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen...
The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input stri...
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. 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 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
500
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "...
1,459,336,443
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
154
512,000
from collections import deque def cxx2(x): #print(x) if(x<=1): return 0 elif(x==2): return 1 else: sans=1 for i in range(2,x+1): sans*=i sans//=2 return sans def cxx3(x): #print(x) if(x<=2): return 0 elif(x=...
Title: Points on Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart...
```python from collections import deque def cxx2(x): #print(x) if(x<=1): return 0 elif(x==2): return 1 else: sans=1 for i in range(2,x+1): sans*=i sans//=2 return sans def cxx3(x): #print(x) if(x<=2): return 0 ...
0
48
A
Rock-paper-scissors
PROGRAMMING
900
[ "implementation", "schedules" ]
A. Rock-paper-scissors
2
256
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio...
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
[ "rock\nrock\nrock\n", "paper\nrock\nrock\n", "scissors\nrock\nrock\n", "scissors\npaper\nrock\n" ]
[ "?\n", "F\n", "?\n", "?\n" ]
none
0
[ { "input": "rock\nrock\nrock", "output": "?" }, { "input": "paper\nrock\nrock", "output": "F" }, { "input": "scissors\nrock\nrock", "output": "?" }, { "input": "scissors\npaper\nrock", "output": "?" }, { "input": "paper\npaper\nrock", "output": "?" }, { ...
1,564,299,875
2,147,483,647
PyPy 3
OK
TESTS
27
280
102,400
game = [] c = {0: 'F', 1: 'M', 2: 'S'} for i in range(3): game.append(input()[0]) if game.count('p') == 1 and game.count('r') == 2: print(c[game.index('p')]) elif game.count('s') == 1 and game.count('p') == 2: print(c[game.index('s')]) elif game.count('r') == 1 and game.count('s') == 2: print(c...
Title: Rock-paper-scissors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ...
```python game = [] c = {0: 'F', 1: 'M', 2: 'S'} for i in range(3): game.append(input()[0]) if game.count('p') == 1 and game.count('r') == 2: print(c[game.index('p')]) elif game.count('s') == 1 and game.count('p') == 2: print(c[game.index('s')]) elif game.count('r') == 1 and game.count('s') == 2: ...
3.929809
352
B
Jeff and Periods
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold: - *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th...
[ "1\n2\n", "8\n1 2 1 3 1 2 1 5\n" ]
[ "1\n2 0\n", "4\n1 2\n2 4\n3 0\n5 0\n" ]
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0.
1,000
[ { "input": "1\n2", "output": "1\n2 0" }, { "input": "8\n1 2 1 3 1 2 1 5", "output": "4\n1 2\n2 4\n3 0\n5 0" }, { "input": "3\n1 10 5", "output": "3\n1 0\n5 0\n10 0" }, { "input": "4\n9 9 3 5", "output": "3\n3 0\n5 0\n9 1" }, { "input": "6\n1 2 2 1 1 2", "outpu...
1,691,956,368
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
1,000
13,619,200
n = int(input()) a = list(map(int, input().split())) seen = [] m = dict() for i in range(n): if a.count(a[i]) == 1: seen.append([a[i], 0]) else: if a[i] not in m.keys(): m[a[i]] = [i] else: m[a[i]].append(i) for j in m: temp = m[j][1] - m[j][0] ...
Title: Jeff and Periods Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold: -...
```python n = int(input()) a = list(map(int, input().split())) seen = [] m = dict() for i in range(n): if a.count(a[i]) == 1: seen.append([a[i], 0]) else: if a[i] not in m.keys(): m[a[i]] = [i] else: m[a[i]].append(i) for j in m: temp = m[j][1] - ...
0
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10...
1,629,898,887
2,147,483,647
PyPy 3
OK
TESTS
35
608
22,835,200
def isPerfect(number): digit_sum = 0 while number > 0: digit_sum += number % 10 number //= 10 return digit_sum == 10 n = int(input()) nums = [] for i in range(1, 11000000): if isPerfect(i): nums.append(i) print(nums[n - 1])
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A singl...
```python def isPerfect(number): digit_sum = 0 while number > 0: digit_sum += number % 10 number //= 10 return digit_sum == 10 n = int(input()) nums = [] for i in range(1, 11000000): if isPerfect(i): nums.append(i) print(nums[n - 1]) ```
3
38
A
Army
PROGRAMMING
800
[ "implementation" ]
A. Army
2
256
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is...
The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated.
Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*.
[ "3\n5 6\n1 2\n", "3\n5 6\n1 3\n" ]
[ "5\n", "11\n" ]
none
0
[ { "input": "3\n5 6\n1 2", "output": "5" }, { "input": "3\n5 6\n1 3", "output": "11" }, { "input": "2\n55\n1 2", "output": "55" }, { "input": "3\n85 78\n1 3", "output": "163" }, { "input": "4\n63 4 49\n2 3", "output": "4" }, { "input": "5\n93 83 42 56\n...
1,665,547,505
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
92
0
n = int(input()) d = [int(num) for num in input().split(" ",n-2)] a,b = input().split() sum = 0 for c in range(1,n): if int(b)-int(a)==c: for i in range (c): sum=sum+d[i] print(sum)
Title: Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<...
```python n = int(input()) d = [int(num) for num in input().split(" ",n-2)] a,b = input().split() sum = 0 for c in range(1,n): if int(b)-int(a)==c: for i in range (c): sum=sum+d[i] print(sum) ```
0
720
A
Closing ceremony
PROGRAMMING
2,000
[ "greedy" ]
null
null
The closing ceremony of Squanch Code Cup is held in the big hall with *n*<=×<=*m* seats, arranged in *n* rows, *m* seats in a row. Each seat has two coordinates (*x*,<=*y*) (1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m*). There are two queues of people waiting to enter the hall: *k* people are standing at (0,<=0) and *n*·*m*<...
The first line of input contains two integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=104) — the size of the hall. The second line contains several integers. The first integer *k* (0<=≤<=*k*<=≤<=*n*·*m*) — the number of people at (0,<=0). The following *k* integers indicate stamina of each person there. The third line also co...
If it is possible to distribute tickets between people in the described manner print "YES", otherwise print "NO".
[ "2 2\n3 3 3 2\n1 3\n", "2 2\n3 2 3 3\n1 2\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "2 2\n3 3 3 2\n1 3", "output": "YES" }, { "input": "2 2\n3 2 3 3\n1 2", "output": "NO" }, { "input": "1 2\n2 2 3\n0", "output": "YES" }, { "input": "1 1\n1 2\n0", "output": "YES" }, { "input": "1 1\n0\n1 1", "output": "NO" } ]
1,688,061,557
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
for _ in range(int(input())): a,b=map(int,input().split()) if b==1: print('NO') else: print('YES') print(a,a*b,a*(b+1))
Title: Closing ceremony Time Limit: None seconds Memory Limit: None megabytes Problem Description: The closing ceremony of Squanch Code Cup is held in the big hall with *n*<=×<=*m* seats, arranged in *n* rows, *m* seats in a row. Each seat has two coordinates (*x*,<=*y*) (1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m*). The...
```python for _ in range(int(input())): a,b=map(int,input().split()) if b==1: print('NO') else: print('YES') print(a,a*b,a*(b+1)) ```
-1
552
B
Vanya and Books
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Print the number of digits needed to number all the books.
[ "13\n", "4\n" ]
[ "17\n", "4\n" ]
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
1,000
[ { "input": "13", "output": "17" }, { "input": "4", "output": "4" }, { "input": "100", "output": "192" }, { "input": "99", "output": "189" }, { "input": "1000000000", "output": "8888888899" }, { "input": "1000000", "output": "5888896" }, { "...
1,599,677,286
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
1,331,200
n=int(input()) ans=0 if(n<10): print(n) else: for i in range(1,n+1): j=str(i) ans+=len(j) print(ans)
Title: Vanya and Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig...
```python n=int(input()) ans=0 if(n<10): print(n) else: for i in range(1,n+1): j=str(i) ans+=len(j) print(ans) ```
0
466
A
Cheap Travel
PROGRAMMING
1,200
[ "implementation" ]
null
null
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu...
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Print a single integer — the minimum sum in rubles that Ann will need to spend.
[ "6 2 1 2\n", "5 2 2 3\n" ]
[ "6\n", "8\n" ]
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets.
500
[ { "input": "6 2 1 2", "output": "6" }, { "input": "5 2 2 3", "output": "8" }, { "input": "10 3 5 1", "output": "4" }, { "input": "1000 1 1000 1000", "output": "1000000" }, { "input": "1000 3 1000 1000", "output": "334000" }, { "input": "1 1 1 1", "...
1,694,340,872
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
14
62
614,400
n, m, a, b = map(int, input().split()) def check_rides(n, m, a, b): if n < m: if n <= 0: return 0 if n*a < b: return n*a + check_rides(n-1, m, a, b) return b + check_rides(n-m, m, a, b) print(check_rides(n, m, a, b))
Title: Cheap Travel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl...
```python n, m, a, b = map(int, input().split()) def check_rides(n, m, a, b): if n < m: if n <= 0: return 0 if n*a < b: return n*a + check_rides(n-1, m, a, b) return b + check_rides(n-m, m, a, b) print(check_rides(n, m, a, b)) ```
0
909
B
Segments
PROGRAMMING
1,300
[ "constructive algorithms", "math" ]
null
null
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoin...
The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100).
Output a single integer - the minimal number of layers required to draw the segments for the given *N*.
[ "2\n", "3\n", "4\n" ]
[ "2\n", "4\n", "6\n" ]
As an example, here are the segments and their optimal arrangement into layers for *N* = 4.
1,000
[ { "input": "2", "output": "2" }, { "input": "3", "output": "4" }, { "input": "4", "output": "6" }, { "input": "21", "output": "121" }, { "input": "100", "output": "2550" }, { "input": "1", "output": "1" }, { "input": "5", "output": "9" ...
1,514,398,442
5,942
Python 3
WRONG_ANSWER
PRETESTS
2
61
5,529,600
n = int(input()) n-=1 a = [0]*n for i in range(n): a[i] = n-i+1 k = 1 for i in range(n//2): if i != n-i-1: a[i]-= a[n-i-1] k+= a[n-i-1] a[n-i-1] = 0 if n%2 == 0: h = n//2-1 n = n//4 -1 else: h = n//2 n = n//4 k+= a[h] // 2 a[h] = a[h]% 2 j = 1 for i in...
Title: Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them. You want to draw these segments in se...
```python n = int(input()) n-=1 a = [0]*n for i in range(n): a[i] = n-i+1 k = 1 for i in range(n//2): if i != n-i-1: a[i]-= a[n-i-1] k+= a[n-i-1] a[n-i-1] = 0 if n%2 == 0: h = n//2-1 n = n//4 -1 else: h = n//2 n = n//4 k+= a[h] // 2 a[h] = a[h]% 2 j = 1...
0
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ...
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#...
1,685,381,447
2,147,483,647
PyPy 3-64
OK
TESTS
28
62
0
yl , xl = list(map(int,input().split())) pos = "right" for y in range(yl) : if y % 2 == 0 : print(xl * "#") elif pos == "right" : print((xl - 1) * "." + "#") pos = "left" else : print("#" + (xl - 1) * ".") pos = "right"
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*...
```python yl , xl = list(map(int,input().split())) pos = "right" for y in range(yl) : if y % 2 == 0 : print(xl * "#") elif pos == "right" : print((xl - 1) * "." + "#") pos = "left" else : print("#" + (xl - 1) * ".") pos = "right" ```
3
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,611,667,409
2,147,483,647
Python 3
OK
TESTS
42
124
307,200
r, c = map(int, input().split()) s = [[j for j in input().strip()] for i in range(r)] sr = set() sc = set() for i in range(r): for j in range(c): if s[i][j] == 'S': sr.add(i) sc.add(j) ans = 0 for i in range(r): for j in range(c): if s[i][j] == '.' and i not in sr or j n...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python r, c = map(int, input().split()) s = [[j for j in input().strip()] for i in range(r)] sr = set() sc = set() for i in range(r): for j in range(c): if s[i][j] == 'S': sr.add(i) sc.add(j) ans = 0 for i in range(r): for j in range(c): if s[i][j] == '.' and i not in...
3