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
412
A
Poster
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building. The slogan of the company consists of *n* characters, so the decorators hung a l...
The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or di...
In *t* lines, print the actions the programmers need to make. In the *i*-th line print: - "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th ac...
[ "2 2\nR1\n", "2 1\nR1\n", "6 4\nGO?GO!\n" ]
[ "PRINT 1\nLEFT\nPRINT R\n", "PRINT R\nRIGHT\nPRINT 1\n", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n" ]
Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
500
[ { "input": "2 2\nR1", "output": "PRINT 1\nLEFT\nPRINT R" }, { "input": "2 1\nR1", "output": "PRINT R\nRIGHT\nPRINT 1" }, { "input": "6 4\nGO?GO!", "output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G" }, { "input": "7 3\n...
1,397,838,629
1,229
Python 3
OK
TESTS
43
62
0
n,k=map(int,input('').split()) lozung=list(input()) if n-k<k: for i in range(k,n): print('RIGHT') for i in reversed(range(0,n)): print ('PRINT ',lozung[i]) if i!=0:print('LEFT') else: # print('2') for i in reversed(range(0,k-1)): print('LEFT')...
Title: Poster Time Limit: None seconds Memory Limit: None megabytes Problem Description: The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the...
```python n,k=map(int,input('').split()) lozung=list(input()) if n-k<k: for i in range(k,n): print('RIGHT') for i in reversed(range(0,n)): print ('PRINT ',lozung[i]) if i!=0:print('LEFT') else: # print('2') for i in reversed(range(0,k-1)): pri...
3
690
C1
Brain Network (easy)
PROGRAMMING
1,300
[]
null
null
One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite!...
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. E...
The output consists of one line, containing either yes or no depending on whether the nervous system is valid.
[ "4 4\n1 2\n2 3\n3 1\n4 1\n", "6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n" ]
[ "no\n", "yes\n" ]
none
0
[ { "input": "4 4\n1 2\n2 3\n3 1\n4 1", "output": "no" }, { "input": "6 5\n1 2\n2 3\n3 4\n4 5\n3 6", "output": "yes" }, { "input": "2 1\n1 2", "output": "yes" }, { "input": "3 3\n2 1\n1 3\n3 2", "output": "no" }, { "input": "3 2\n1 2\n2 3", "output": "yes" }, ...
1,573,560,299
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
109
0
n,m=map(int,input().split()) L=[] for k in range(n): L.append(0) for k in range(m): a,b=map(int,input().split()) L[a-1]+=1 L[b-1]+=1 if n!=m+1 or 0 in L: print("no") else: print("yes")
Title: Brain Network (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. I...
```python n,m=map(int,input().split()) L=[] for k in range(n): L.append(0) for k in range(m): a,b=map(int,input().split()) L[a-1]+=1 L[b-1]+=1 if n!=m+1 or 0 in L: print("no") else: print("yes") ```
0
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ...
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\...
1,512,552,313
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
5,529,600
n=int(input()) list1=[int(i) for i in input().split()] m=0 if n==1: print(list1[0]) elif n==2: print(sum(list1)*2) else: list1.sort() list1.reverse() for i in range(0,n,1): m=m+list1[i]*(n-i+1) print(m-list1[0])
Title: Appleman and Toastman Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all...
```python n=int(input()) list1=[int(i) for i in input().split()] m=0 if n==1: print(list1[0]) elif n==2: print(sum(list1)*2) else: list1.sort() list1.reverse() for i in range(0,n,1): m=m+list1[i]*(n-i+1) print(m-list1[0]) ```
0
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY...
1,697,015,876
2,147,483,647
Python 3
OK
TESTS
59
46
0
n=int(input()) ch=input() m=0 letter='abcdefghijklmnopqrstuvwxyz' for i in letter: if i not in ch.lower(): m=1 if m==1: print("No") else: print("Yes")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. ...
```python n=int(input()) ch=input() m=0 letter='abcdefghijklmnopqrstuvwxyz' for i in letter: if i not in ch.lower(): m=1 if m==1: print("No") else: print("Yes") ```
3
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,696,038,581
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
exit = 0 while (exit != 1): problemInput = input() if problemInput >= 1 and problemInput <= 1000: n = 0 output = 0 while (n <= problemInput): checkSolution = input() splitCheck = int(checkSolution.split()) print(splitCheck) posSol...
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python exit = 0 while (exit != 1): problemInput = input() if problemInput >= 1 and problemInput <= 1000: n = 0 output = 0 while (n <= problemInput): checkSolution = input() splitCheck = int(checkSolution.split()) print(splitCheck) ...
-1
182
B
Vasya's Calendar
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n...
The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106). The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000). The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — th...
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
[ "4\n2\n2 2\n", "5\n3\n3 4 3\n", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n" ]
[ "2\n", "3\n", "7\n" ]
In the first sample the situation is like this: - Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by ...
500
[ { "input": "4\n2\n2 2", "output": "2" }, { "input": "5\n3\n3 4 3", "output": "3" }, { "input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "output": "7" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n1 1", "output": "0" }, { "input": "2...
1,576,850,029
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
404
2,355,200
#234B with open('input.txt',"r") as file: n , k = map(int, file.readline().split(" ")) a = list(map(int, file.readline().split(" "))) b = a.copy() b.sort(reverse=True) b = b[:k] ans = [] for i in b: ans.append(a.index(i)+ 1) with open('output.txt',"w") as writefile: ...
Title: Vasya's Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any ...
```python #234B with open('input.txt',"r") as file: n , k = map(int, file.readline().split(" ")) a = list(map(int, file.readline().split(" "))) b = a.copy() b.sort(reverse=True) b = b[:k] ans = [] for i in b: ans.append(a.index(i)+ 1) with open('output.txt',"w") as writ...
-1
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It...
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, ...
1,568,028,194
2,147,483,647
Python 3
OK
TESTS
46
218
0
import sys n = int(input()) s = input() i = 0 for ch in s: if(ch != '4' and ch != '7'): print('NO') sys.exit(0) n = int(n/2) if(sum(map(int,s[:n])) == sum(map(int, s[-n:]))): print("YES") else: print('NO')
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python import sys n = int(input()) s = input() i = 0 for ch in s: if(ch != '4' and ch != '7'): print('NO') sys.exit(0) n = int(n/2) if(sum(map(int,s[:n])) == sum(map(int, s[-n:]))): print("YES") else: print('NO') ```
3
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,642,180,712
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
512,000
a = [] res = [] for i in range(3): b = list(map(int, input().split())) a.append(b) temp = [0]*3 res.append(temp) for i in range(3): for j in range(3): number_of_times_toggled = 0 number_of_times_toggled += a[i][j] if j>0: number_of_times_toggled += a[i][j-1] if j<2: number_of_times_...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python a = [] res = [] for i in range(3): b = list(map(int, input().split())) a.append(b) temp = [0]*3 res.append(temp) for i in range(3): for j in range(3): number_of_times_toggled = 0 number_of_times_toggled += a[i][j] if j>0: number_of_times_toggled += a[i][j-1] if j<2: number...
0
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea...
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *...
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "outpu...
1,698,452,541
2,147,483,647
Python 3
OK
TESTS
44
92
0
q, r = map(int, input().split()) t1 = input() t = [] for o in t1: t.append(o) for j in range(r): i = 0 while i < len(t)-1: if t[i] == 'B' and t[i + 1] == 'G': t[i], t[i + 1] = t[i + 1], t[i] i += 2 else: i += 1 t1 = ''.join(t) print(t1)
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a...
```python q, r = map(int, input().split()) t1 = input() t = [] for o in t1: t.append(o) for j in range(r): i = 0 while i < len(t)-1: if t[i] == 'B' and t[i + 1] == 'G': t[i], t[i + 1] = t[i + 1], t[i] i += 2 else: i += 1 t1 = ''.join(t) print...
3
1
B
Spreadsheet
PROGRAMMING
1,600
[ "implementation", "math" ]
B. Spreadsheets
10
64
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th...
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
Write *n* lines, each line should contain a cell coordinates in the other numeration system.
[ "2\nR23C55\nBC23\n" ]
[ "BC23\nR23C55\n" ]
none
0
[ { "input": "2\nR23C55\nBC23", "output": "BC23\nR23C55" }, { "input": "1\nA1", "output": "R1C1" }, { "input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9", "output": "C8\nR1C4\nB7\nI8\nI8" }, { "input": "4\nR4C25\nR90C35\nAP55\nX83", "output": "Y4\nAI90\nR55C42\nR83C24" }, { "i...
1,682,847,065
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
92
0
# Hydro submission #644e355674221a4e24c95e98@1682847063427 def transform_string1(s): r = '' c = '' i = 1 while s[i].isdigit(): r += s[i] i += 1 i += 1 while i < len(s) and s[i].isdigit(): c += s[i] i += 1 c = int(c) res = '' stack = [] while c: ...
Title: Spreadsheet Time Limit: 10 seconds Memory Limit: 64 megabytes Problem Description: In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter n...
```python # Hydro submission #644e355674221a4e24c95e98@1682847063427 def transform_string1(s): r = '' c = '' i = 1 while s[i].isdigit(): r += s[i] i += 1 i += 1 while i < len(s) and s[i].isdigit(): c += s[i] i += 1 c = int(c) res = '' stack = [] wh...
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,660,282,872
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
numeros = input().split() output = 0 lado = 0 cociente = 0 n = numeros[0] m = numeros[1] a = numeros[2] if(n<m): lado = n else: lado = m cociente = int(lado/a) output = (cociente + 2) * cociente + 1 print(output)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python numeros = input().split() output = 0 lado = 0 cociente = 0 n = numeros[0] m = numeros[1] a = numeros[2] if(n<m): lado = n else: lado = m cociente = int(lado/a) output = (cociente + 2) * cociente + 1 print(output) ```
-1
912
B
New Year's Eve
PROGRAMMING
1,300
[ "bitmasks", "constructive algorithms", "number theory" ]
null
null
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a d...
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output one number — the largest possible xor-sum.
[ "4 3\n", "6 6\n" ]
[ "7\n", "7\n" ]
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
1,000
[ { "input": "4 3", "output": "7" }, { "input": "6 6", "output": "7" }, { "input": "2 2", "output": "3" }, { "input": "1022 10", "output": "1023" }, { "input": "415853337373441 52", "output": "562949953421311" }, { "input": "75 12", "output": "127" ...
1,516,725,943
2,147,483,647
Python 3
OK
TESTS
58
77
5,632,000
n , k = map(int , input().split()) l = list(bin(n))[2:] if k == 1: print(n) else: print ((1 << len(l)) -1)
Title: New Year's Eve Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co...
```python n , k = map(int , input().split()) l = list(bin(n))[2:] if k == 1: print(n) else: print ((1 << len(l)) -1) ```
3
803
A
Maximal Binary Matrix
PROGRAMMING
1,400
[ "constructive algorithms" ]
null
null
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicograph...
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
If the answer exists then output resulting matrix. Otherwise output -1.
[ "2 1\n", "3 2\n", "2 5\n" ]
[ "1 0 \n0 0 \n", "1 0 0 \n0 1 0 \n0 0 0 \n", "-1\n" ]
none
0
[ { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "2 5", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "20 398", "output": "1 1 1 1 ...
1,698,547,208
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
12
46
1,843,200
(n,k) = map(int,input().split()) matrix = [[0] * n for i in range(n)] if k > n*n: print(-1) else: i = n while 2 * i - 1 < k: for m in range(n-i,n): matrix[m][n-i] = 1 matrix[n-i][m] = 1 k -= 2*i -1 i -= 1 if k == 2: matrix[n-i][n-i] = ...
Title: Maximal Binary Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes...
```python (n,k) = map(int,input().split()) matrix = [[0] * n for i in range(n)] if k > n*n: print(-1) else: i = n while 2 * i - 1 < k: for m in range(n-i,n): matrix[m][n-i] = 1 matrix[n-i][m] = 1 k -= 2*i -1 i -= 1 if k == 2: matrix[n-...
0
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S...
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and...
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second...
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1...
1,620,651,049
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
124
7,065,600
import random limit=0 n = int(input()) read=list(map(int,input().split())) for i in range(len(read)): limit+=read[i] if limit >=n: print(i+1) break else: print(1)
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s...
```python import random limit=0 n = int(input()) read=list(map(int,input().split())) for i in range(len(read)): limit+=read[i] if limit >=n: print(i+1) break else: print(1) ```
0
478
B
Random Teams
PROGRAMMING
1,300
[ "combinatorics", "constructive algorithms", "greedy", "math" ]
null
null
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul...
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
[ "5 1\n", "3 2\n", "6 3\n" ]
[ "10 10\n", "1 1\n", "3 6\n" ]
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. ...
1,000
[ { "input": "5 1", "output": "10 10" }, { "input": "3 2", "output": "1 1" }, { "input": "6 3", "output": "3 6" }, { "input": "5 3", "output": "2 3" }, { "input": "10 2", "output": "20 36" }, { "input": "10 6", "output": "4 10" }, { "input": ...
1,666,021,089
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
62
0
items = input().split(" ") n = int(items[0]) m = int(items[1]) def get_res(k): return k * (k-1) // 2 if m == 1: k_min = get_res(n) k_max = get_res(n) print(k_min, k_max) else: if n % m == 0: k_min = get_res(n//m) else: k_min = get_res(n//m + 1) k_max = get_r...
Title: Random Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is ...
```python items = input().split(" ") n = int(items[0]) m = int(items[1]) def get_res(k): return k * (k-1) // 2 if m == 1: k_min = get_res(n) k_max = get_res(n) print(k_min, k_max) else: if n % m == 0: k_min = get_res(n//m) else: k_min = get_res(n//m + 1) k_m...
0
427
B
Prison Transfer
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city. For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of th...
The first line of input will contain three space separated integers *n* (1<=≤<=*n*<=≤<=2·105), *t* (0<=≤<=*t*<=≤<=109) and *c* (1<=≤<=*c*<=≤<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative an...
Print a single integer — the number of ways you can choose the *c* prisoners.
[ "4 3 3\n2 3 1 1\n", "1 1 1\n2\n", "11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n" ]
[ "2\n", "0\n", "6\n" ]
none
1,000
[ { "input": "4 3 3\n2 3 1 1", "output": "2" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4", "output": "6" }, { "input": "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 ...
1,685,812,159
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
5
139
25,600,000
n,t,c=map(int,input().strip().split()) li=list(map(int,input().strip().split())) di={} # i=0 # # fli=[] # while i<n: # ct=0 # si=i # maxi=li[i] # while ct<c and i<n: # if li[i]>maxi: # maxi=li[i] # ct+=1 # i+=1 # # lii=[maxi]*c # # fli=fli+lii ...
Title: Prison Transfer Time Limit: None seconds Memory Limit: None megabytes Problem Description: The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city. For this reason, he made the *n* ...
```python n,t,c=map(int,input().strip().split()) li=list(map(int,input().strip().split())) di={} # i=0 # # fli=[] # while i<n: # ct=0 # si=i # maxi=li[i] # while ct<c and i<n: # if li[i]>maxi: # maxi=li[i] # ct+=1 # i+=1 # # lii=[maxi]*c # # fli...
-1
225
C
Barcode
PROGRAMMING
1,700
[ "dp", "matrices" ]
null
null
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture. A picture is a barcode if the following conditions are fulfilled: - All pixels in each column are of the same color. - The width of each monochrome ...
The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*). Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The pictur...
In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists.
[ "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n", "2 5 1 1\n#####\n.....\n" ]
[ "11\n", "5\n" ]
In the first test sample the picture after changing some colors can looks as follows: In the second test sample the picture after changing some colors can looks as follows:
1,500
[ { "input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..", "output": "11" }, { "input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#", "output": "24" }, { "input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#", "output": "6" }, { "input": "5 ...
1,615,372,684
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
154
0
from math import inf n,m,x,y=map(int,input().split()) matx=[] for i in range(n): matx.append(list(input().strip())) d=[[0,0]] for i in range(m): c=0 for j in range(n): if matx[j][i]=='.': c+=1 d.append([c,n-c]) print(d) for i in range(1,m+1): d[i][0]+=d[i-1][0...
Title: Barcode Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture. A picture is a barcode if the following conditions are fulf...
```python from math import inf n,m,x,y=map(int,input().split()) matx=[] for i in range(n): matx.append(list(input().strip())) d=[[0,0]] for i in range(m): c=0 for j in range(n): if matx[j][i]=='.': c+=1 d.append([c,n-c]) print(d) for i in range(1,m+1): d[i][0]...
0
984
B
Minesweeper
PROGRAMMING
1,100
[ "implementation" ]
null
null
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won. Alex has grown up since then, so he easily wins the most difficu...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field. The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive.
Print "YES", if the field is valid and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrarily.
[ "3 3\n111\n1*1\n111\n", "2 4\n*.*.\n1211\n" ]
[ "YES", "NO" ]
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1. You can read more about Minesweeper in [Wikipedia's article](https://en.wikipedia.org/wiki/Minesweeper_(video_game)).
1,000
[ { "input": "3 3\n111\n1*1\n111", "output": "YES" }, { "input": "2 4\n*.*.\n1211", "output": "NO" }, { "input": "1 10\n.....1*1..", "output": "YES" }, { "input": "1 1\n4", "output": "NO" }, { "input": "10 10\n..........\n...111111.\n..13*21*1.\n.12**2111.\n.1*542.....
1,662,002,040
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
import sys,os,io input = sys.stdin.readlines def inlt(): return(list(map(int,input().split()))) grid = input()[1:] for i in range(len(grid)): grid[i] = list(grid[i][:-1]) print(grid) def check(grid,i,j): count = 0 if 0 <= i - 1 < len(grid): if 0 <= j + 1 < len(grid[i]): ...
Title: Minesweeper Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by...
```python import sys,os,io input = sys.stdin.readlines def inlt(): return(list(map(int,input().split()))) grid = input()[1:] for i in range(len(grid)): grid[i] = list(grid[i][:-1]) print(grid) def check(grid,i,j): count = 0 if 0 <= i - 1 < len(grid): if 0 <= j + 1 < len(grid...
0
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea...
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n...
1,673,285,663
2,147,483,647
Python 3
OK
TESTS
31
92
0
teams = int(input()) homeKit = [None] * teams guestKit = [None] * teams for i in range(teams): homeKit[i], guestKit[i] = map(int, input().split()) guestUni = 0 for i in range(teams): for j in range(teams): if i == j: continue if homeKit[i] == guestKit[j]: guestUni += 1 print(guestUni) ...
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W...
```python teams = int(input()) homeKit = [None] * teams guestKit = [None] * teams for i in range(teams): homeKit[i], guestKit[i] = map(int, input().split()) guestUni = 0 for i in range(teams): for j in range(teams): if i == j: continue if homeKit[i] == guestKit[j]: guestUni += 1 print(guestUni) ...
3
1,009
A
Game Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy ...
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the inp...
Print a single integer — the number of games Maxim will buy.
[ "5 4\n2 4 5 2 4\n5 3 4 6\n", "5 2\n20 40 50 20 40\n19 20\n", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n" ]
[ "3\n", "0\n", "4\n" ]
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
0
[ { "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3" }, { "input": "5 2\n20 40 50 20 40\n19 20", "output": "0" }, { "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4" }, { "input": "5 1\n1 1 1 1 1\n5", "output": "1" }, { "input": "5 1\n10 1 1 1 1\n...
1,555,662,827
2,147,483,647
Python 3
OK
TESTS
19
124
307,200
def main(): [n_games, n_bills] = [int(_) for _ in input().split()] game_prices = [0] + [int(_) for _ in input().split()] bills = [0] + [int(_) for _ in input().split()] last_game = 0 last_bill = 0 count_games_bought = 0 while last_game < n_games and last_bill < n_bills: last_bill +...
Title: Game Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ...
```python def main(): [n_games, n_bills] = [int(_) for _ in input().split()] game_prices = [0] + [int(_) for _ in input().split()] bills = [0] + [int(_) for _ in input().split()] last_game = 0 last_bill = 0 count_games_bought = 0 while last_game < n_games and last_bill < n_bills: l...
3
863
B
Kayaking
PROGRAMMING
1,500
[ "brute force", "greedy", "sortings" ]
null
null
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact...
The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000).
Print minimum possible total instability.
[ "2\n1 2 3 4\n", "4\n1 3 4 6 3 4 100 200\n" ]
[ "1\n", "5\n" ]
none
0
[ { "input": "2\n1 2 3 4", "output": "1" }, { "input": "4\n1 3 4 6 3 4 100 200", "output": "5" }, { "input": "3\n305 139 205 406 530 206", "output": "102" }, { "input": "3\n610 750 778 6 361 407", "output": "74" }, { "input": "5\n97 166 126 164 154 98 221 7 51 47", ...
1,641,669,877
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
93
0
n = int(input().strip()) weights = [int(i) for i in input().strip().split()] weights.sort() max_dif = 0 f, s = None, None for i in range(n*2-1): if weights[i+1] - weights[i] > max_dif: max_dif = weights[i+1] - weights[i] f = i+1 s = i weights.pop(i+1) weights.pop(i) ans = 0 fo...
Title: Kayaking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they hav...
```python n = int(input().strip()) weights = [int(i) for i in input().strip().split()] weights.sort() max_dif = 0 f, s = None, None for i in range(n*2-1): if weights[i+1] - weights[i] > max_dif: max_dif = weights[i+1] - weights[i] f = i+1 s = i weights.pop(i+1) weights.pop(i) a...
0
837
A
Text Volume
PROGRAMMING
800
[ "implementation" ]
null
null
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Print one integer number — volume of text.
[ "7\nNonZERO\n", "24\nthis is zero answer text\n", "24\nHarbour Space University\n" ]
[ "5\n", "0\n", "1\n" ]
In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
0
[ { "input": "7\nNonZERO", "output": "5" }, { "input": "24\nthis is zero answer text", "output": "0" }, { "input": "24\nHarbour Space University", "output": "1" }, { "input": "2\nWM", "output": "2" }, { "input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd...
1,538,606,067
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
108
0
n=int(input()) ch=input() i=0 l=[] k=0 while((i<=n)): if (ch[i].isupper()): k+=1 if (ch[i]==' '): l.append(k) k=0 i+=1 l.append(k) v=max(l)
Title: Text Volume Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex...
```python n=int(input()) ch=input() i=0 l=[] k=0 while((i<=n)): if (ch[i].isupper()): k+=1 if (ch[i]==' '): l.append(k) k=0 i+=1 l.append(k) v=max(l) ```
-1
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single s...
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "...
1,631,557,116
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
184
20,172,800
n = int(input()) l = list(map(int,input().split())) s = sum(l) a = ((sum(l)-2)//(n+1)) + 1 if a<=0: print(a+4) else: print(a)
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the...
```python n = int(input()) l = list(map(int,input().split())) s = sum(l) a = ((sum(l)-2)//(n+1)) + 1 if a<=0: print(a+4) else: print(a) ```
0
979
A
Pizza, Pizza, Pizza!!!
PROGRAMMING
1,000
[ "math" ]
null
null
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele...
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
A single integer — the number of straight cuts Shiro needs.
[ "3\n", "4\n" ]
[ "2", "5" ]
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
500
[ { "input": "3", "output": "2" }, { "input": "4", "output": "5" }, { "input": "10", "output": "11" }, { "input": "10000000000", "output": "10000000001" }, { "input": "1234567891", "output": "617283946" }, { "input": "7509213957", "output": "37546069...
1,558,537,146
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
108
0
N = int(input()) + 1 if (N % 2 == 0): print(int(N / 2)) else: print(N)
Title: Pizza, Pizza, Pizza!!! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthd...
```python N = int(input()) + 1 if (N % 2 == 0): print(int(N / 2)) else: print(N) ```
0
811
B
Vladik and Complicated Book
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn. So...
First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in p...
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
[ "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n" ]
[ "Yes\nNo\nYes\nYes\nNo\n", "Yes\nNo\nYes\nNo\nYes\n" ]
Explanation of first test case: 1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Ye...
1,000
[ { "input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "output": "Yes\nNo\nYes\nYes\nNo" }, { "input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3", "output": "Yes\nNo\nYes\nNo\nYes" }, { "input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6...
1,570,469,959
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
9,113,600
n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(m): l, r, x = map(int, input().split()) b = a[l - 1: r] b.sort() if a[x - 1] == b[x - l]: print("Yes") else: print("No")
Title: Vladik and Complicated Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<...
```python n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(m): l, r, x = map(int, input().split()) b = a[l - 1: r] b.sort() if a[x - 1] == b[x - l]: print("Yes") else: print("No") ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,610,520,845
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
204,800
n = input() s = input() s1 = s.split() odd = 0 even = 0 for i in range(int(n)): if int(s1[i]) % 2 == 0: even = even + 1 else: odd = odd + 1 if odd > even: for i in range(int(n)): if int(s1[i]) % 2 == 0: print(i) elif even > odd: ...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n = input() s = input() s1 = s.split() odd = 0 even = 0 for i in range(int(n)): if int(s1[i]) % 2 == 0: even = even + 1 else: odd = odd + 1 if odd > even: for i in range(int(n)): if int(s1[i]) % 2 == 0: print(i) elif even...
0
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input":...
1,695,174,378
2,147,483,647
Python 3
OK
TESTS
53
92
0
a = input().lower() b = input().lower() abi = True for i in range(len(a)): if a[i] > b[i]: print('1') abi = False break elif a[i] < b[i]: print('-1') abi = False break if abi: print('0')
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ...
```python a = input().lower() b = input().lower() abi = True for i in range(len(a)): if a[i] > b[i]: print('1') abi = False break elif a[i] < b[i]: print('-1') abi = False break if abi: print('0') ```
3.977
847
M
Weather Tomorrow
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known. The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day.
Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.
[ "5\n10 5 0 -5 -10\n", "4\n1 1 1 1\n", "3\n5 1 -5\n", "2\n900 1000\n" ]
[ "-15\n", "1\n", "-5\n", "1100\n" ]
In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is  - 10 - 5 =  - 15. In the second example the sequence of the average temperatures is an arithmetic pro...
0
[ { "input": "5\n10 5 0 -5 -10", "output": "-15" }, { "input": "4\n1 1 1 1", "output": "1" }, { "input": "3\n5 1 -5", "output": "-5" }, { "input": "2\n900 1000", "output": "1100" }, { "input": "2\n1 2", "output": "3" }, { "input": "3\n2 5 8", "output...
1,680,878,020
2,147,483,647
Python 3
OK
TESTS
26
46
0
n = int(input()) vals = list(map(int,(input().split()))) arith = True diff = vals[0]-vals[1] for i in range(n-1): if vals[i]-vals[i+1]!=diff: arith = False break if arith: print(vals[-1]-diff) else: print(vals[-1])
Title: Weather Tomorrow Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral. Vasya ...
```python n = int(input()) vals = list(map(int,(input().split()))) arith = True diff = vals[0]-vals[1] for i in range(n-1): if vals[i]-vals[i+1]!=diff: arith = False break if arith: print(vals[-1]-diff) else: print(vals[-1]) ```
3
129
A
Cookies
PROGRAMMING
900
[ "implementation" ]
null
null
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan...
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
[ "1\n1\n", "10\n1 2 2 3 4 4 4 2 2 2\n", "11\n2 2 2 2 2 2 2 2 2 2 99\n" ]
[ "1\n", "8\n", "1\n" ]
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, t...
500
[ { "input": "1\n1", "output": "1" }, { "input": "10\n1 2 2 3 4 4 4 2 2 2", "output": "8" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 99", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 2", "output": "2" }, { "input": "2\n1 2", "o...
1,638,820,906
2,147,483,647
Python 3
OK
TESTS
52
122
0
n=int(input()) l=list(map(int,input().split())) Sum=sum(l) if(Sum%2==0): print(len([i for i in l if i%2==0])) else: print(len([i for i in l if(i%2==1)]))
Title: Cookies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan...
```python n=int(input()) l=list(map(int,input().split())) Sum=sum(l) if(Sum%2==0): print(len([i for i in l if i%2==0])) else: print(len([i for i in l if(i%2==1)])) ```
3
0
none
none
none
0
[ "none" ]
null
null
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the...
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
[ "fixprefixsuffix\n", "abcdabc\n" ]
[ "fix", "Just a legend" ]
none
0
[ { "input": "fixprefixsuffix", "output": "fix" }, { "input": "abcdabc", "output": "Just a legend" }, { "input": "qwertyqwertyqwerty", "output": "qwerty" }, { "input": "papapapap", "output": "papap" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaa" }, { "...
1,465,217,867
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
4,608,000
s=input() ins=s[1:-1] ans="Just a legend" for i in range(len(s)): if s[:i]==s[-i:] and ins.find(s[:i])!=-1: ans=s[:i] break print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on...
```python s=input() ins=s[1:-1] ans="Just a legend" for i in range(len(s)): if s[:i]==s[-i:] and ins.find(s[:i])!=-1: ans=s[:i] break print(ans) ```
0
771
A
Bear and Friendship Condition
PROGRAMMING
1,500
[ "dfs and similar", "dsu", "graphs" ]
null
null
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that...
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and ...
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
[ "4 3\n1 3\n3 4\n1 4\n", "4 4\n3 1\n2 3\n3 4\n1 2\n", "10 4\n4 3\n5 10\n8 9\n1 2\n", "3 2\n1 2\n2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
250
[ { "input": "4 3\n1 3\n3 4\n1 4", "output": "YES" }, { "input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO" }, { "input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 0", "output": "YES" }, { ...
1,694,517,068
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
46
0
mod = int(1e9+7) def solve(): n,m = map(int,input().split()) adj = [[]for i in range(n)] for i in range(m): a,b = map(int,input().split()) adj[a-1].append(b-1) adj[b-1].append(a-1) def dfs(s,par,gpar): visited[s] = True strue = False atrue = True for i in adj[s]: if not visited[i]: atrue&=dfs(i...
Title: Bear and Friendship Condition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through...
```python mod = int(1e9+7) def solve(): n,m = map(int,input().split()) adj = [[]for i in range(n)] for i in range(m): a,b = map(int,input().split()) adj[a-1].append(b-1) adj[b-1].append(a-1) def dfs(s,par,gpar): visited[s] = True strue = False atrue = True for i in adj[s]: if not visited[i]: at...
0
260
B
Ancient Prophesy
PROGRAMMING
1,600
[ "brute force", "implementation", "strings" ]
null
null
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha...
The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.
In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.
[ "777-444---21-12-2013-12-2013-12-2013---444-777\n" ]
[ "13-12-2013" ]
none
1,000
[ { "input": "777-444---21-12-2013-12-2013-12-2013---444-777", "output": "13-12-2013" }, { "input": "30-12-201429-15-208830-12-2014", "output": "30-12-2014" }, { "input": "14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013", "output": "...
1,535,796,221
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
24
546
1,536,000
import re s = input() a = [] days = [0,31,28,31,30,31,30,30,31,30,31,30,31]; regex = r'(0[1-9])?(1[0-9])?(2[0-9])?(3[0-1])?-(0[1-9])?(1[0-2])?[-]201[3-5]' for i in range(0,len(s)-9): if(s[i]!='-' and s[i+9]!='-'): if(re.search(regex,s[i:i+10])!=None): a.append(s[i:i+10]) st = set(a) b = [[a.count(i),i] ...
Title: Ancient Prophesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if th...
```python import re s = input() a = [] days = [0,31,28,31,30,31,30,30,31,30,31,30,31]; regex = r'(0[1-9])?(1[0-9])?(2[0-9])?(3[0-1])?-(0[1-9])?(1[0-2])?[-]201[3-5]' for i in range(0,len(s)-9): if(s[i]!='-' and s[i+9]!='-'): if(re.search(regex,s[i:i+10])!=None): a.append(s[i:i+10]) st = set(a) b = [[a.co...
-1
656
A
Da Vinci Powers
PROGRAMMING
1,900
[ "*special" ]
null
null
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output a single integer.
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
[ "3\n", "10\n" ]
[ "8\n", "1024\n" ]
none
0
[ { "input": "3", "output": "8" }, { "input": "10", "output": "1024" }, { "input": "35", "output": "33940307968" }, { "input": "0", "output": "1" }, { "input": "1", "output": "2" }, { "input": "2", "output": "4" }, { "input": "4", "output...
1,496,787,250
2,147,483,647
Python 3
OK
TESTS
36
62
0
if __name__ == "__main__": a = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208, 16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 1060634624, 21212...
Title: Da Vinci Powers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output a single integer. Input Specification: The input contains a single integer *a* (0<=≤<=*a*<=≤<=35). Output Specification: Output a single integer. De...
```python if __name__ == "__main__": a = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208, 16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 106063462...
3
757
A
Gotta Catch Em' All!
PROGRAMMING
1,000
[ "implementation" ]
null
null
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*. The string *s* contains lowercase and uppercase English letters, i.e. .
Output a single integer, the answer to the problem.
[ "Bulbbasaur\n", "F\n", "aBddulbasaurrgndgbualdBdsagaurrgndbb\n" ]
[ "1\n", "0\n", "2\n" ]
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
500
[ { "input": "Bulbbasaur", "output": "1" }, { "input": "F", "output": "0" }, { "input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2" }, { "input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr", "output": "5" }, { "input": "BBBBBBB...
1,617,756,999
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
def solve(s): d = { 'B': 0, 'u':0, 'l':0, 'b':0, 'a':0, 'u':0, 'r':0, 's':0 } for c in s: if c in 'Bulbbasaur': d[c]+=1 min_val = 1000000000 for i in d: if not d[i]: return 0 if d['a'] < 2 or d['u'] < 2: return 0 if d[i] < min_val: if i i...
Title: Gotta Catch Em' All! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsess...
```python def solve(s): d = { 'B': 0, 'u':0, 'l':0, 'b':0, 'a':0, 'u':0, 'r':0, 's':0 } for c in s: if c in 'Bulbbasaur': d[c]+=1 min_val = 1000000000 for i in d: if not d[i]: return 0 if d['a'] < 2 or d['u'] < 2: return 0 if d[i] < min_val: ...
0
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"...
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string — the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht...
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n100000...
1,694,614,508
2,147,483,647
Python 3
OK
TESTS
14
46
0
def solve(): size = input() s = input() print('1' * ('1' in s) + '0' * s.count('0')) if __name__ == "__main__": solve()
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two...
```python def solve(): size = input() s = input() print('1' * ('1' in s) + '0' * s.count('0')) if __name__ == "__main__": solve() ```
3
0
none
none
none
0
[ "none" ]
null
null
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to...
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=...
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
[ "4 2\n1 3\n3 4\n", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n" ]
[ "2\n", "-1\n", "3\n" ]
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codefo...
0
[ { "input": "4 2\n1 3\n3 4", "output": "2" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "-1" }, { "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "output": "3" }, { "input": "5 4\n1 2\n3 2\n3 4\n5 4", "output": "4" }, { "input": "3 1\n1 2", "output": "...
1,697,337,545
2,147,483,647
PyPy 3-64
OK
TESTS
59
482
8,192,000
n, m = map(int, input().split()) a = [[0] * (n + 1) for _ in range(n + 1)] for _ in range(m): u, v = map(int, input().split()) a[u][v] = 1 a[v][u] = 1 def bfs(x): fila = [(1, 0)] visitados = [0] * (n + 1) while fila: u, v = fila.pop(0) for i in range(1, n + 1):...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns...
```python n, m = map(int, input().split()) a = [[0] * (n + 1) for _ in range(n + 1)] for _ in range(m): u, v = map(int, input().split()) a[u][v] = 1 a[v][u] = 1 def bfs(x): fila = [(1, 0)] visitados = [0] * (n + 1) while fila: u, v = fila.pop(0) for i in range(...
3
721
C
Journey
PROGRAMMING
1,800
[ "dp", "graphs" ]
null
null
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially I...
The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively. The next *m* lines describes roads in Berlatov. *i*-th of them cont...
Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line. Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in t...
[ "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n", "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n" ]
[ "3\n1 2 4 \n", "4\n1 2 4 6 \n", "3\n1 3 5 \n" ]
none
1,500
[ { "input": "4 3 13\n1 2 5\n2 3 7\n2 4 8", "output": "3\n1 2 4 " }, { "input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1", "output": "4\n1 2 4 6 " }, { "input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2", "output": "3\n1 3 5 " }, { "input": "10 10 100\n1 4 1\n6 4 1\n9 3...
1,645,218,883
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
102,400
import collections from functools import lru_cache from collections import deque n, m, T = map(int, input().split()) g = collections.defaultdict(list) rev_g = collections.defaultdict(list) indegree = [0] * (n + 1) for _ in range(m): u, v, t = map(int, input().split()) g[u].append(v) rev_g[v]...
Title: Journey Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlato...
```python import collections from functools import lru_cache from collections import deque n, m, T = map(int, input().split()) g = collections.defaultdict(list) rev_g = collections.defaultdict(list) indegree = [0] * (n + 1) for _ in range(m): u, v, t = map(int, input().split()) g[u].append(v) ...
0
918
B
Radio Station
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o...
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase...
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
1,000
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3...
1,660,735,474
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n, m = map(int, input().split()) server = [] serverip = [] c_name = [] c_ip = [] for i in range(n): name, ip = input().split() ip = ip + ";" server.append(name) serverip.append(ip) for i in range(m): command, commandip = input().split() for x in range(n): if serverip[x] == c...
Title: Radio Station Time Limit: None seconds Memory Limit: None megabytes Problem Description: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ...
```python n, m = map(int, input().split()) server = [] serverip = [] c_name = [] c_ip = [] for i in range(n): name, ip = input().split() ip = ip + ";" server.append(name) serverip.append(ip) for i in range(m): command, commandip = input().split() for x in range(n): if server...
0
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,664,426,483
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
t=int(input()) arr=[] for i in range(t): x=int(input()) arr.append(x) a,b=0,0 a=int(input()) b=int(input()) s=0 ind=a-1 while(ind<b): s+=arr[ind] ind+=1 print(s)
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 t=int(input()) arr=[] for i in range(t): x=int(input()) arr.append(x) a,b=0,0 a=int(input()) b=int(input()) s=0 ind=a-1 while(ind<b): s+=arr[ind] ind+=1 print(s) ```
-1
336
C
Vasily the Bear and Sequence
PROGRAMMING
1,800
[ "brute force", "greedy", "implementation", "number theory" ]
null
null
Vasily the bear has got a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers *b*1,<=*b*2,<=...,<=*b**k* is such maximum non-negative integer *...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=109).
In the first line print a single integer *k* (*k*<=&gt;<=0), showing how many numbers to write out. In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the numbers to write out. You are allowed to print numbers *b*1,<=*b*2,<=...,<=*b**k* in any order, but all of them must be distinct. If there are multip...
[ "5\n1 2 3 4 5\n", "3\n1 2 4\n" ]
[ "2\n4 5\n", "1\n4\n" ]
none
1,500
[ { "input": "5\n1 2 3 4 5", "output": "2\n4 5" }, { "input": "3\n1 2 4", "output": "1\n4" }, { "input": "3\n1 20 22", "output": "2\n20 22" }, { "input": "10\n109070199 215498062 361633800 406156967 452258663 530571268 670482660 704334662 841023955 967424642", "output": "6\...
1,627,640,042
3,542
Python 3
WRONG_ANSWER
TESTS
3
61
6,963,200
import math n = int(input()) l = list(map(int,input().split())) c=d=0 a = [] l.sort(reverse=True) for i in l: while i%(math.pow(2,d))==0: d+=1 if i not in a: c+=1 a.append(i) print(c) print(*a)
Title: Vasily the Bear and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the bear has got a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was ...
```python import math n = int(input()) l = list(map(int,input().split())) c=d=0 a = [] l.sort(reverse=True) for i in l: while i%(math.pow(2,d))==0: d+=1 if i not in a: c+=1 a.append(i) print(c) print(*a) ```
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,558,280,225
2,147,483,647
Python 3
OK
TESTS
37
109
0
import math r, x, y, x1, y1 = map(int, input().split()) print(math.ceil(math.sqrt((x-x1)**2 + (y-y1)**2)/(2*r)))
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 math r, x, y, x1, y1 = map(int, input().split()) print(math.ceil(math.sqrt((x-x1)**2 + (y-y1)**2)/(2*r))) ```
3
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the...
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ...
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1....
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,595,099,463
2,147,483,647
Python 3
OK
TESTS
34
109
6,758,400
n,x = map(int,input().split()) count=0 for _ in range(n): c,v = input().split() v=int(v) if(c=='+'): x=x+v if(c=='-'): if(v<=x): x=x-v else: count += 1 print(x,count)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, p...
```python n,x = map(int,input().split()) count=0 for _ in range(n): c,v = input().split() v=int(v) if(c=='+'): x=x+v if(c=='-'): if(v<=x): x=x-v else: count += 1 print(x,count) ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,644,814,193
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
for t in range(int(input())): a=list(map(int,input().split())) even=0 evencount=0 oddcount=0 for i in range(len(a)): if a[i]%2==0: even=i evencount+=1 else: odd=i oddcount+=1 if evencount>oddcount: print(odd+1) ...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python for t in range(int(input())): a=list(map(int,input().split())) even=0 evencount=0 oddcount=0 for i in range(len(a)): if a[i]%2==0: even=i evencount+=1 else: odd=i oddcount+=1 if evencount>oddcount: pri...
-1
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co...
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "ou...
1,505,300,205
1,305
Python 3
WRONG_ANSWER
TESTS
3
61
0
n = int(input()) def easyest(a, b): while a != 0 and b != 0: if a > b: a %= b else: b %= a if (a + b) == 1: return True else: return False x = 0 for j in range(n, 1, -1): if easyest(n - j, j): if (n - j) / j > x: ...
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is cal...
```python n = int(input()) def easyest(a, b): while a != 0 and b != 0: if a > b: a %= b else: b %= a if (a + b) == 1: return True else: return False x = 0 for j in range(n, 1, -1): if easyest(n - j, j): if (n - j) / j > x: ...
0
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,697,712,626
2,147,483,647
Python 3
OK
TESTS
21
92
0
n = int(input()) count = 0 for i in range(n): m = list(map(int,input().split())) k = m.count(1) if k >= 2: count += 1 print(count)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python n = int(input()) count = 0 for i in range(n): m = list(map(int,input().split())) k = m.count(1) if k >= 2: count += 1 print(count) ```
3
75
C
Modified GCD
PROGRAMMING
1,600
[ "binary search", "number theory" ]
C. Modified GCD
2
256
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are divisible by. But your teacher wants to give you a harder task, in this task...
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=...
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
[ "9 27\n3\n1 5\n10 11\n9 11\n" ]
[ "3\n-1\n9\n" ]
none
1,500
[ { "input": "9 27\n3\n1 5\n10 11\n9 11", "output": "3\n-1\n9" }, { "input": "48 72\n2\n8 29\n29 37", "output": "24\n-1" }, { "input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90", "output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1" }, { "input...
1,539,538,075
2,147,483,647
Python 3
OK
TESTS
60
592
614,400
def gcd(a,b): while a>0: x=a a=b%a b=x return(x) def Bsearch1(L,x): beg=0 last=len(L)-1 while beg<=last: mid=(beg+last)//2 if x==L[mid]: return(mid) elif(x>L[mid]): beg=mid+1 else: last=mid-1 ...
Title: Modified GCD Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which ...
```python def gcd(a,b): while a>0: x=a a=b%a b=x return(x) def Bsearch1(L,x): beg=0 last=len(L)-1 while beg<=last: mid=(beg+last)//2 if x==L[mid]: return(mid) elif(x>L[mid]): beg=mid+1 else: l...
3.850856
839
A
Arya and Bran
PROGRAMMING
900
[ "implementation" ]
null
null
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day.
[ "2 3\n1 2\n", "3 17\n10 10 10\n", "1 9\n10\n" ]
[ "2", "3", "-1" ]
In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with...
500
[ { "input": "2 3\n1 2", "output": "2" }, { "input": "3 17\n10 10 10", "output": "3" }, { "input": "1 9\n10", "output": "-1" }, { "input": "10 70\n6 5 2 3 3 2 1 4 3 2", "output": "-1" }, { "input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",...
1,590,758,583
183
PyPy 3
WRONG_ANSWER
TESTS
4
202
2,355,200
import math as mt import sys,string input=sys.stdin.readline from collections import defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) n,k=M() l=L() g=0 f=0 for i in range(n): g+=min(8,l[i]) if(g>=k): pri...
Title: Arya and Bran Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**...
```python import math as mt import sys,string input=sys.stdin.readline from collections import defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) n,k=M() l=L() g=0 f=0 for i in range(n): g+=min(8,l[i]) if(g>=k): ...
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,678,625,050
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
0
def stringcheck(s): word="hello" req="h" c=0 for ch in s: if c==5: break if ch==req: c+=1 if c<5: req=word[c] if c==5: print("YES") else: print("NO") s=input() stringcheck(s)
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python def stringcheck(s): word="hello" req="h" c=0 for ch in s: if c==5: break if ch==req: c+=1 if c<5: req=word[c] if c==5: print("YES") else: print("NO") s=input() stringch...
3.969
862
A
Mahmoud and Ehab and the MEX
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX...
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX. The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
[ "5 3\n0 4 5 6 7\n", "1 0\n0\n", "5 0\n1 2 3 4 5\n" ]
[ "2\n", "1\n", "0\n" ]
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations. For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0. In the third test case the set is already evil.
500
[ { "input": "5 3\n0 4 5 6 7", "output": "2" }, { "input": "1 0\n0", "output": "1" }, { "input": "5 0\n1 2 3 4 5", "output": "0" }, { "input": "10 5\n57 1 47 9 93 37 76 70 78 15", "output": "4" }, { "input": "10 5\n99 98 93 97 95 100 92 94 91 96", "output": "5" ...
1,507,791,499
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n, x = map(int, input().split()) set1 = set(map(int, input().split())) ''' if x == 0 and x in set1: for e in set1: print(e) break else: ''' set2 = set() for i in range(0, x + 1): set2.add(i) set3 = set2 - set1 print(set1) print(set2) print(set3) if x in set3: #print(1) print(len(set3) - 1) ...
Title: Mahmoud and Ehab and the MEX Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in ...
```python n, x = map(int, input().split()) set1 = set(map(int, input().split())) ''' if x == 0 and x in set1: for e in set1: print(e) break else: ''' set2 = set() for i in range(0, x + 1): set2.add(i) set3 = set2 - set1 print(set1) print(set2) print(set3) if x in set3: #print(1) print(len(se...
0
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for...
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhe...
1,503,595,172
2,672
Python 3
OK
TESTS
41
77
0
s = input() x = int(input()) if x > len(s): print('impossible') elif x < len(set(s)): print(0) else: print(x - len(set(s)))
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it...
```python s = input() x = int(input()) if x > len(s): print('impossible') elif x < len(set(s)): print(0) else: print(x - len(set(s))) ```
3
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,688,667,351
2,147,483,647
PyPy 3-64
OK
TESTS
19
124
0
s = input() t = input() count=1 si=0 for i in range(len(t)): if t[i] == s[si]: count+=1 si+=1 print(count)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python s = input() t = input() count=1 si=0 for i in range(len(t)): if t[i] == s[si]: count+=1 si+=1 print(count) ```
3
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,699,242,148
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
n=int(input()) lst1=[] for i in range(1,6): if n%i==0: lst1.append([n//i,i]) lst2=[elem for row in lst1 for elem in row] print(min(lst2))
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python n=int(input()) lst1=[] for i in range(1,6): if n%i==0: lst1.append([n//i,i]) lst2=[elem for row in lst1 for elem in row] print(min(lst2)) ```
0
92
B
Binary Number
PROGRAMMING
1,300
[ "greedy" ]
B. Binary Number
1
256
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divide...
The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106.
Print the required number of actions.
[ "1\n", "1001001\n", "101110\n" ]
[ "0\n", "12\n", "8\n" ]
Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide...
1,000
[ { "input": "1", "output": "0" }, { "input": "1001001", "output": "12" }, { "input": "101110", "output": "8" }, { "input": "11", "output": "3" }, { "input": "11110001101", "output": "16" }, { "input": "101010100100111100011111001111100001010101111110101...
1,581,787,625
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
155
0
n = int(input(), 2) steps = 0 while n != 1: if n % 2 == 1: n += 1 else: n /= 2 steps += 1 print(steps)
Title: Binary Number Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to ...
```python n = int(input(), 2) steps = 0 while n != 1: if n % 2 == 1: n += 1 else: n /= 2 steps += 1 print(steps) ```
0
371
D
Vessels
PROGRAMMING
1,800
[ "data structures", "dsu", "implementation", "trees" ]
null
null
There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters. Initially, all the vessels are empty. In some vessels water is poured. All the w...
The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The t...
For each query, print on a single line the number of liters of water in the corresponding vessel.
[ "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n", "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n" ]
[ "4\n5\n8\n", "7\n10\n5\n" ]
none
2,000
[ { "input": "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2", "output": "4\n5\n8" }, { "input": "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3", "output": "7\n10\n5" }, { "input": "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n...
1,616,029,501
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
7
529
18,739,200
n = int(input()) capacidades = list(map(int, input().split())) copos = [0 for x in range(n)] m = int(input()) consultas = [tuple(map(int, input().split())) for x in range(m)] def atualizar(p, x): if len(copos) <= p: return if capacidades[p] - copos[p] < x: cheio = capacidades[p] -...
Title: Vessels Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a*...
```python n = int(input()) capacidades = list(map(int, input().split())) copos = [0 for x in range(n)] m = int(input()) consultas = [tuple(map(int, input().split())) for x in range(m)] def atualizar(p, x): if len(copos) <= p: return if capacidades[p] - copos[p] < x: cheio = capaci...
-1
137
C
History
PROGRAMMING
1,500
[ "sortings" ]
null
null
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the Wo...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th...
Print the only integer — the answer to the problem.
[ "5\n1 10\n2 9\n3 8\n4 7\n5 6\n", "5\n1 100\n2 50\n51 99\n52 98\n10 60\n", "1\n1 1000000000\n" ]
[ "4\n", "4\n", "0\n" ]
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first. In the second example all events except the first one are contained in the first. In the third example only one event, so the answer is 0.
1,500
[ { "input": "5\n1 10\n2 9\n3 8\n4 7\n5 6", "output": "4" }, { "input": "5\n1 100\n2 50\n51 99\n52 98\n10 60", "output": "4" }, { "input": "1\n1 1000000000", "output": "0" }, { "input": "2\n100 1000\n500 1500", "output": "0" }, { "input": "4\n1 100\n50 150\n120 200\...
1,588,083,198
2,147,483,647
PyPy 3
OK
TESTS
75
872
78,950,400
import sys from math import log2,floor,ceil,sqrt,gcd import bisect # from collections import deque sys.setrecursionlimit(10**5) Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return...
Title: History Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other ...
```python import sys from math import log2,floor,ceil,sqrt,gcd import bisect # from collections import deque sys.setrecursionlimit(10**5) Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, ...
3
568
A
Primes or Palindromes?
PROGRAMMING
1,600
[ "brute force", "implementation", "math", "number theory" ]
null
null
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this! Let us remind you...
The input consists of two positive integers *p*, *q*, the numerator and denominator of the fraction that is the value of *A* (, ).
If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).
[ "1 1\n", "1 42\n", "6 4\n" ]
[ "40\n", "1\n", "172\n" ]
none
500
[ { "input": "1 1", "output": "40" }, { "input": "1 42", "output": "1" }, { "input": "6 4", "output": "172" }, { "input": "3 1", "output": "2530" }, { "input": "42 1", "output": "1179858" }, { "input": "10000 239", "output": "1168638" }, { "i...
1,538,431,189
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
3,000
29,081,600
def is_palindrome(num): copia = num if num < 10: return True nums = [] while(True): nums.append(copia % 10) copia //= 10 if copia == 0: break digitos = len(nums) // 2 j = len(nums) - 1 for i in range(digitos): if num...
Title: Primes or Palindromes? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a nu...
```python def is_palindrome(num): copia = num if num < 10: return True nums = [] while(True): nums.append(copia % 10) copia //= 10 if copia == 0: break digitos = len(nums) // 2 j = len(nums) - 1 for i in range(digitos): ...
0
520
B
Two Buttons
PROGRAMMING
1,400
[ "dfs and similar", "graphs", "greedy", "implementation", "math", "shortest paths" ]
null
null
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so...
The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space .
Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*.
[ "4 6\n", "10 1\n" ]
[ "2\n", "9\n" ]
In the first example you need to push the blue button once, and then push the red button once. In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
1,000
[ { "input": "4 6", "output": "2" }, { "input": "10 1", "output": "9" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "1 3", "output": "3" }, { "input": "3 1", "output": "2" }, { "input": "2 10", "outpu...
1,698,290,071
2,147,483,647
Python 3
OK
TESTS
51
61
1,228,800
from collections import deque n, m = map(int, input().split()) queue = deque([(n, 0)]) visited = set() while queue: current, clicks = queue.popleft() if current == m: print(clicks) break if current * 2 not in visited and current * 2 <= 10**4: queue.append((cur...
Title: Two Buttons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by t...
```python from collections import deque n, m = map(int, input().split()) queue = deque([(n, 0)]) visited = set() while queue: current, clicks = queue.popleft() if current == m: print(clicks) break if current * 2 not in visited and current * 2 <= 10**4: queue.a...
3
336
A
Vasily the Bear and Triangle
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he...
The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0).
Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points.
[ "10 5\n", "-10 5\n" ]
[ "0 15 15 0\n", "-15 0 0 15\n" ]
<img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/> Figure to the first sample
500
[ { "input": "10 5", "output": "0 15 15 0" }, { "input": "-10 5", "output": "-15 0 0 15" }, { "input": "20 -10", "output": "0 -30 30 0" }, { "input": "-10 -1000000000", "output": "-1000000010 0 0 -1000000010" }, { "input": "-1000000000 -1000000000", "output": "-...
1,602,661,831
2,147,483,647
Python 3
OK
TESTS
30
186
0
n=input().split() x,y=int(n[0]),int(n[1]) if x>0 and y>0: print(0,x+y,x+y,0) elif x>0 and y<0: print(0,y-x,x-y,0) elif x<0 and y>0: print(x-y,0,0,y-x) else: print(x+y,0,0,x+y)
Title: Vasily the Bear and Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ...
```python n=input().split() x,y=int(n[0]),int(n[1]) if x>0 and y>0: print(0,x+y,x+y,0) elif x>0 and y<0: print(0,y-x,x-y,0) elif x<0 and y>0: print(x-y,0,0,y-x) else: print(x+y,0,0,x+y) ```
3
898
C
Phone Numbers
PROGRAMMING
1,400
[ "implementation", "strings" ]
null
null
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a f...
First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books. The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase E...
Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books. The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each...
[ "2\nivan 1 00123\nmasha 1 00123\n", "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n", "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n" ]
[ "2\nmasha 1 00123 \nivan 1 00123 \n", "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n", "2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n" ]
none
1,500
[ { "input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123 \nivan 1 00123 " }, { "input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 " }, { "input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndash...
1,597,843,771
1,771
PyPy 3
WRONG_ANSWER
TESTS
0
170
307,200
import sys input = sys.stdin.readline from collections import * def judge(s, t): return s[len(s)-len(t):]==t d = defaultdict(set) for _ in range(int(input())): l = list(input().split()) for num in l[2:]: d[l[0]].add(num) for k in d.keys(): ans = [] for num1 in...
Title: Phone Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friend...
```python import sys input = sys.stdin.readline from collections import * def judge(s, t): return s[len(s)-len(t):]==t d = defaultdict(set) for _ in range(int(input())): l = list(input().split()) for num in l[2:]: d[l[0]].add(num) for k in d.keys(): ans = [] f...
0
0
none
none
none
0
[ "none" ]
null
null
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t...
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ...
Print one integer — the number of good positions for placing the spotlight.
[ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ]
[ "9\n", "20\n" ]
In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and...
0
[ { "input": "2 4\n0 1 0 0\n1 0 1 0", "output": "9" }, { "input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "output": "20" }, { "input": "1 5\n1 1 0 0 0", "output": "3" }, { "input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "3 ...
1,479,658,039
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
5,939,200
n, m=map(int, input().split()) a=[list(map(int, input().split())) for _ in range(n)] ans=p=0 def f(x): global ans, p if x==0: ans+=p else: p=1 for i in range(n): p=0 for j in range(m): f(a[i][j]) p=0 for j in range(m-1, -1, -1): f(a[i][j]) ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a ...
```python n, m=map(int, input().split()) a=[list(map(int, input().split())) for _ in range(n)] ans=p=0 def f(x): global ans, p if x==0: ans+=p else: p=1 for i in range(n): p=0 for j in range(m): f(a[i][j]) p=0 for j in range(m-1, -1, -1): f(...
0
862
A
Mahmoud and Ehab and the MEX
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX...
The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX. The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set.
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
[ "5 3\n0 4 5 6 7\n", "1 0\n0\n", "5 0\n1 2 3 4 5\n" ]
[ "2\n", "1\n", "0\n" ]
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations. For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0. In the third test case the set is already evil.
500
[ { "input": "5 3\n0 4 5 6 7", "output": "2" }, { "input": "1 0\n0", "output": "1" }, { "input": "5 0\n1 2 3 4 5", "output": "0" }, { "input": "10 5\n57 1 47 9 93 37 76 70 78 15", "output": "4" }, { "input": "10 5\n99 98 93 97 95 100 92 94 91 96", "output": "5" ...
1,671,815,291
191
PyPy 3
OK
TESTS
39
93
0
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, x = map(int, input().split()) a = list(map(int, input().split())) l = 105 cnt = [0] * l for i in a: cnt[i] += 1 ans = 0 for i in range(x): if not cnt[i]: ans += 1 ans += cnt[x] print(ans)
Title: Mahmoud and Ehab and the MEX Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in ...
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, x = map(int, input().split()) a = list(map(int, input().split())) l = 105 cnt = [0] * l for i in a: cnt[i] += 1 ans = 0 for i in range(x): if not cnt[i]: ans += 1 ans += cnt[x] print(ans) ```
3
327
A
Flipping Game
PROGRAMMING
1,200
[ "brute force", "dp", "implementation" ]
null
null
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
[ "5\n1 0 0 1 0\n", "4\n1 0 0 1\n" ]
[ "4\n", "4\n" ]
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all nu...
500
[ { "input": "5\n1 0 0 1 0", "output": "4" }, { "input": "4\n1 0 0 1", "output": "4" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "8\n1 0 0 0 1 0 0 0", "output": "7" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1,692,787,446
2,147,483,647
PyPy 3-64
OK
TESTS
21
154
1,740,800
n = int(input()) a = list(map(int, input().split())) max_ones = 0 for i in range(n): for j in range(i, n): temp = a.copy() for k in range(i, j+1): temp[k] = 1 - temp[k] max_ones = max(max_ones, temp.count(1)) print(max_ones)
Title: Flipping Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *...
```python n = int(input()) a = list(map(int, input().split())) max_ones = 0 for i in range(n): for j in range(i, n): temp = a.copy() for k in range(i, j+1): temp[k] = 1 - temp[k] max_ones = max(max_ones, temp.count(1)) print(max_ones) ```
3
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single s...
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "...
1,591,859,419
2,147,483,647
PyPy 3
OK
TESTS
30
280
0
n = int(input()) l = list(map(int,input().split())) if n<3: if n%2==0: if sum(l)%2==0: print(3) else: print(2) else: if sum(l)%2==0: print(2) else: print(3) else: mod = sum(l)%(n+1) mod = n+1-mod if mod>=...
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the...
```python n = int(input()) l = list(map(int,input().split())) if n<3: if n%2==0: if sum(l)%2==0: print(3) else: print(2) else: if sum(l)%2==0: print(2) else: print(3) else: mod = sum(l)%(n+1) mod = n+1-mod ...
3
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st...
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "...
1,697,552,758
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
''' 刘思瑞 2100017810 ''' def search(num): if int(int(num**(0.5))**2) != num: return 'NO' for i in range(2,int(num**(0.5)+1)): if num % i == 0: if i**2 != num: return 'NO' return 'YES' n = int(input()) num = list(map(int,input().split())) for i in num:...
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an ar...
```python ''' 刘思瑞 2100017810 ''' def search(num): if int(int(num**(0.5))**2) != num: return 'NO' for i in range(2,int(num**(0.5)+1)): if num % i == 0: if i**2 != num: return 'NO' return 'YES' n = int(input()) num = list(map(int,input().split())) for...
0
4
C
Registration System
PROGRAMMING
1,300
[ "data structures", "hashing", "implementation" ]
C. Registration system
5
64
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. ...
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
[ "4\nabacaba\nacaba\nabacaba\nacab\n", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n" ]
[ "OK\nOK\nabacaba1\nOK\n", "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n" ]
none
0
[ { "input": "4\nabacaba\nacaba\nabacaba\nacab", "output": "OK\nOK\nabacaba1\nOK" }, { "input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1" }, { "input": "1\nn", "output": "OK" }, { "input": "2\nu\nu", "output": "OK\nu1" ...
1,689,152,254
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
92
0
n = int(input()) mydict = [] for _ in range(n): text = input() if text in mydict: print(text + "1") else: print("OK") mydict.append(text) quit()
Title: Registration System Time Limit: 5 seconds Memory Limit: 64 megabytes Problem Description: A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to imple...
```python n = int(input()) mydict = [] for _ in range(n): text = input() if text in mydict: print(text + "1") else: print("OK") mydict.append(text) quit() ```
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,670,745,762
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import sys inputs = sys.stdin.readline().split() print min(int(inputs[0])-int(inputs[1]),int(inputs[2])+1)
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 import sys inputs = sys.stdin.readline().split() print min(int(inputs[0])-int(inputs[1]),int(inputs[2])+1) ```
-1
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,697,475,674
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
data = list(map(int, input().split())) a,b,c = data max_problems = max(a, b, c) if a+b+c - max_problems >= 2: print(max_problems + 1) else: print(a + b + c)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python data = list(map(int, input().split())) a,b,c = data max_problems = max(a, b, c) if a+b+c - max_problems >= 2: print(max_problems + 1) else: print(a + b + c) ```
-1
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,537,700,196
2,147,483,647
Python 3
OK
TESTS
81
248
0
n = int(input()) xs, ys, zs = 0, 0, 0 for i in range(n): l = [int(k) for k in input().split(' ')] x, y, z = l[0], l[1], l[2] xs, ys, zs = xs+x, ys+y, zs+z if (xs==0) and (ys==0) and (zs==0): print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n = int(input()) xs, ys, zs = 0, 0, 0 for i in range(n): l = [int(k) for k in input().split(' ')] x, y, z = l[0], l[1], l[2] xs, ys, zs = xs+x, ys+y, zs+z if (xs==0) and (ys==0) and (zs==0): print('YES') else: print('NO') ```
3.938
336
B
Vasily the Bear and Fly
PROGRAMMING
1,900
[ "math" ]
null
null
One beautiful day Vasily the bear painted 2*m* circles of the same radius *R* on a coordinate plane. Circles with numbers from 1 to *m* had centers at points (2*R*<=-<=*R*,<=0), (4*R*<=-<=*R*,<=0), ..., (2*Rm*<=-<=*R*,<=0), respectively. Circles with numbers from *m*<=+<=1 to 2*m* had centers at points (2*R*<=-<=*R*,<=...
The first line contains two integers *m*,<=*R* (1<=≤<=*m*<=≤<=105, 1<=≤<=*R*<=≤<=10).
In a single line print a single real number — the answer to the problem. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "1 1\n", "2 2\n" ]
[ "2.0000000000\n", "5.4142135624\n" ]
<img class="tex-graphics" src="https://espresso.codeforces.com/9fe384073741e20965ddc4bf162afd3a604b6b39.png" style="max-width: 100.0%;max-height: 100.0%;"/> Figure to the second sample
1,000
[ { "input": "1 1", "output": "2.0000000000" }, { "input": "2 2", "output": "5.4142135624" }, { "input": "100000 3", "output": "200002.4853316681" }, { "input": "2344 5", "output": "7817.4790439982" }, { "input": "999 10", "output": "6668.3010410807" }, { ...
1,377,735,208
2,147,483,647
Python 3
OK
TESTS
31
686
0
import math m,R = map (int,input().split()) D = math.sqrt (2) * R result = 0 def sum_dist (n): return n*(n+1)*R + 2*D*n for i in range (1,m+1): result += 2*R if i-1 > 0: result += 2*R + D if m-i > 0: result += 2*R + D if i-2 > 0: result += sum_dist (i-2) if m-i-1 > 0: result += sum_dist (m-i-1) p...
Title: Vasily the Bear and Fly Time Limit: None seconds Memory Limit: None megabytes Problem Description: One beautiful day Vasily the bear painted 2*m* circles of the same radius *R* on a coordinate plane. Circles with numbers from 1 to *m* had centers at points (2*R*<=-<=*R*,<=0), (4*R*<=-<=*R*,<=0), ..., (2*Rm*<=...
```python import math m,R = map (int,input().split()) D = math.sqrt (2) * R result = 0 def sum_dist (n): return n*(n+1)*R + 2*D*n for i in range (1,m+1): result += 2*R if i-1 > 0: result += 2*R + D if m-i > 0: result += 2*R + D if i-2 > 0: result += sum_dist (i-2) if m-i-1 > 0: result += sum_dist ...
3
427
B
Prison Transfer
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city. For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of th...
The first line of input will contain three space separated integers *n* (1<=≤<=*n*<=≤<=2·105), *t* (0<=≤<=*t*<=≤<=109) and *c* (1<=≤<=*c*<=≤<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative an...
Print a single integer — the number of ways you can choose the *c* prisoners.
[ "4 3 3\n2 3 1 1\n", "1 1 1\n2\n", "11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n" ]
[ "2\n", "0\n", "6\n" ]
none
1,000
[ { "input": "4 3 3\n2 3 1 1", "output": "2" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4", "output": "6" }, { "input": "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 ...
1,696,006,223
2,147,483,647
PyPy 3-64
OK
TESTS
80
109
22,630,400
import sys n, t, c = map(int, input().split()) vec = [-1] for i, temp in enumerate(map(int, sys.stdin.readline().split())): if temp > t: vec.append(i) vec.append(n) ans = 0 for i in range(1, len(vec)): diff = vec[i] - vec[i - 1] - 1 ans += max(diff - c + 1, 0) sys.stdout.write(s...
Title: Prison Transfer Time Limit: None seconds Memory Limit: None megabytes Problem Description: The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city. For this reason, he made the *n* ...
```python import sys n, t, c = map(int, input().split()) vec = [-1] for i, temp in enumerate(map(int, sys.stdin.readline().split())): if temp > t: vec.append(i) vec.append(n) ans = 0 for i in range(1, len(vec)): diff = vec[i] - vec[i - 1] - 1 ans += max(diff - c + 1, 0) sys.stdo...
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,635,769,339
2,147,483,647
Python 3
OK
TESTS
102
46
4,300,800
a=input() b=input() res=[] for i in range(len(a)): if a[i]!=b[i]: res.append('1') else: res.append('0') print(*res,sep='')
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a=input() b=input() res=[] for i in range(len(a)): if a[i]!=b[i]: res.append('1') else: res.append('0') print(*res,sep='') ```
3.980489
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis...
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla...
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "11101001...
1,618,995,477
2,147,483,647
PyPy 3
OK
TESTS
37
218
2,355,200
s = input() for idx in range(len(s)): if s[idx] == "0": break print(s[:idx]+s[idx+1:])
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought...
```python s = input() for idx in range(len(s)): if s[idx] == "0": break print(s[:idx]+s[idx+1:]) ```
3
981
C
Useful Decomposition
PROGRAMMING
1,400
[ "implementation", "trees" ]
null
null
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree. Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree.
If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$. Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of ...
[ "4\n1 2\n2 3\n3 4\n", "6\n1 2\n2 3\n3 4\n2 5\n3 6\n", "5\n1 2\n1 3\n1 4\n1 5\n" ]
[ "Yes\n1\n1 4\n", "No\n", "Yes\n4\n1 2\n1 3\n1 4\n1 5\n" ]
The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see ...
1,250
[ { "input": "4\n1 2\n2 3\n3 4", "output": "Yes\n1\n1 4" }, { "input": "6\n1 2\n2 3\n3 4\n2 5\n3 6", "output": "No" }, { "input": "5\n1 2\n1 3\n1 4\n1 5", "output": "Yes\n4\n1 2\n1 3\n1 4\n1 5" }, { "input": "2\n1 2", "output": "Yes\n1\n1 2" }, { "input": "8\n1 2\n1...
1,527,500,902
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
187
4,710,400
#!/usr/bin/env python # -*- coding: utf-8 -*- def local_input(): from pcm.utils import set_stdin import sys if len(sys.argv) == 1: set_stdin(os.path.dirname(__file__) + '/test/' + 'sample-1.in') import sys import os from sys import stdin, stdout import time import re from pydoc imp...
Title: Useful Decomposition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! Th...
```python #!/usr/bin/env python # -*- coding: utf-8 -*- def local_input(): from pcm.utils import set_stdin import sys if len(sys.argv) == 1: set_stdin(os.path.dirname(__file__) + '/test/' + 'sample-1.in') import sys import os from sys import stdin, stdout import time import re from...
-1
469
A
I Wanna Be the Guy
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can...
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100). The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels...
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
[ "4\n3 1 2 3\n2 2 4\n", "4\n3 1 2 3\n2 2 3\n" ]
[ "I become the guy.\n", "Oh, my keyboard!\n" ]
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
500
[ { "input": "4\n3 1 2 3\n2 2 4", "output": "I become the guy." }, { "input": "4\n3 1 2 3\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6", "output": "Oh, my keyboard!" }, { "input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8", "output":...
1,695,287,260
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
#469A - I Wanna Be the Guy n = int(input()) p = list(map(int, input().split())) q = list(map(int, input().split())) lvls = [] for ele in p: lvls.append(ele) for ele in q: lvls.append(ele) lvls = set(lvls) if len(lvls) == 4: print("I become the guy") else: print("Oh, my keyboard!")
Title: I Wanna Be the Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the g...
```python #469A - I Wanna Be the Guy n = int(input()) p = list(map(int, input().split())) q = list(map(int, input().split())) lvls = [] for ele in p: lvls.append(ele) for ele in q: lvls.append(ele) lvls = set(lvls) if len(lvls) == 4: print("I become the guy") else: print("Oh, my keyboard!") ```
0
468
C
Hack it!
PROGRAMMING
2,500
[ "binary search", "constructive algorithms", "math" ]
null
null
Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen...
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018).
Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=&lt;<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
[ "46\n", "126444381000032\n" ]
[ "1 10\n", "2333333 2333333333333\n" ]
none
1,500
[ { "input": "46", "output": "1 10" }, { "input": "126444381000032", "output": "2333333 2333333333333" }, { "input": "69645082595", "output": "613752823618441225798858488535 713259406474207764329704856394" }, { "input": "70602205995", "output": "11 2492213340204320744986569...
1,424,004,438
2,147,483,647
Python 3
OK
TESTS
51
62
0
a=int(input()) x=a-((10**20)*45*21+1)%a print(1+x,10**21+x)
Title: Hack it! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X ...
```python a=int(input()) x=a-((10**20)*45*21+1)%a print(1+x,10**21+x) ```
3
534
B
Covered Path
PROGRAMMING
1,400
[ "dp", "greedy", "math" ]
null
null
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass. Assuming that at each of the seconds the speed is constan...
The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<...
Print the maximum possible length of the path segment in meters.
[ "5 6\n4 2\n", "10 10\n10 0\n" ]
[ "26", "100" ]
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters. In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters.
1,000
[ { "input": "5 6\n4 2", "output": "26" }, { "input": "10 10\n10 0", "output": "100" }, { "input": "87 87\n2 10", "output": "174" }, { "input": "1 11\n6 2", "output": "36" }, { "input": "100 10\n10 10", "output": "550" }, { "input": "1 1\n100 10", "o...
1,603,526,499
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
108
0
v1, v2 = map(int,input().split()) t,d = map(int,input().split()) if v1 > v2: p=0 l= v1 for k in range(t): if k==0: p+=v1 elif k==t-1: p+=v2 else: if l > v2+d: l-=d p+=l ...
Title: Covered Path Time Limit: None seconds Memory Limit: None megabytes Problem Description: The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the ...
```python v1, v2 = map(int,input().split()) t,d = map(int,input().split()) if v1 > v2: p=0 l= v1 for k in range(t): if k==0: p+=v1 elif k==t-1: p+=v2 else: if l > v2+d: l-=d p+...
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,692,485,672
2,147,483,647
Python 3
OK
TESTS
20
31
0
def way_too_long_words(txt_arr): res = [] for input_txt in txt_arr: n = len(input_txt) if n <= 10: res.append(input_txt) else: res.append(input_txt[0] + str(n-2) + input_txt[-1]) return res if __name__ == "__main__": n = int(input()) txt_a...
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python def way_too_long_words(txt_arr): res = [] for input_txt in txt_arr: n = len(input_txt) if n <= 10: res.append(input_txt) else: res.append(input_txt[0] + str(n-2) + input_txt[-1]) return res if __name__ == "__main__": n = int(input()) ...
3.9845
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,594,449,452
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
7,065,600
from collections import Counter k=int(input()) string="" string+=input() string+=input() string+=input() string+=input() string=list(string) string.remove('.') string=Counter(string) count=string.most_common(1) cnt=count[0][1] if cnt<=2*k: print("YES") else: print("NO")
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 from collections import Counter k=int(input()) string="" string+=input() string+=input() string+=input() string+=input() string=list(string) string.remove('.') string=Counter(string) count=string.most_common(1) cnt=count[0][1] if cnt<=2*k: print("YES") else: print("NO") ```
0
6
C
Alice, Bob and Chocolate
PROGRAMMING
1,200
[ "greedy", "two pointers" ]
C. Alice, Bob and Chocolate
2
64
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
[ "5\n2 9 8 2 7\n" ]
[ "2 3\n" ]
none
0
[ { "input": "5\n2 9 8 2 7", "output": "2 3" }, { "input": "1\n1", "output": "1 0" }, { "input": "2\n1 1", "output": "1 1" }, { "input": "3\n1 1 1", "output": "2 1" }, { "input": "4\n1 1 1 1", "output": "2 2" }, { "input": "1\n6", "output": "1 0" }...
1,592,383,999
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
216
307,200
# Alice_Bob_and_chocolate n = int(input()); A = list(map(int , input().split())) #Alice i = 0; ai =0; #Bob j = len(A)-1; bj =0 ; # ki=-1; kj=-1; while(i<j): if i == j: i +=1; break; if i!=ki: ai +=A[i]; if j!=kj: bj += A[j]; ...
Title: Alice, Bob and Chocolate Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. Fo...
```python # Alice_Bob_and_chocolate n = int(input()); A = list(map(int , input().split())) #Alice i = 0; ai =0; #Bob j = len(A)-1; bj =0 ; # ki=-1; kj=-1; while(i<j): if i == j: i +=1; break; if i!=ki: ai +=A[i]; if j!=kj: bj += A[j]; ...
0
962
A
Equator
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on...
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (...
0
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }...
1,524,523,715
2,147,483,647
Python 3
OK
TESTS
106
171
20,582,400
#k=int(input()) #n,m=map(int,input().split()) import sys #a=list(map(int,input().split())) #b=list(map(int,input().split())) import math n=int(input()) a=list(map(int,input().split())) ss=sum(a); s=0 for i in range(n): s+=a[i] if(2*s>=ss): print(i+1) sys.exit()
Title: Equator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve...
```python #k=int(input()) #n,m=map(int,input().split()) import sys #a=list(map(int,input().split())) #b=list(map(int,input().split())) import math n=int(input()) a=list(map(int,input().split())) ss=sum(a); s=0 for i in range(n): s+=a[i] if(2*s>=ss): print(i+1) sys...
3
1,003
D
Coins and Queries
PROGRAMMING
1,600
[ "greedy" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the...
The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers o...
Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1.
[ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n" ]
[ "1\n-1\n3\n2\n" ]
none
0
[ { "input": "5 4\n2 4 8 2 4\n8\n5\n14\n10", "output": "1\n-1\n3\n2" }, { "input": "3 3\n1 1 1\n1\n2\n3", "output": "1\n2\n3" }, { "input": "4 1\n2 4 16 32\n14", "output": "-1" }, { "input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\...
1,621,996,883
4,943
PyPy 3
RUNTIME_ERROR
TESTS
0
124
2,150,400
def main(): n, q = map(int, input().split()) a = [*map(int, input().split())] d = {} for i in range(n): d[a[i]] = d.get(a[i], 0) + 1 for i in range(q): x = int(input()) c = 0 for j in reversed(d.keys()): y = min(d[j], x // j) c += y x -= y * j if x: print(-1) else: print(...
Title: Coins and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). Polycarp wants to know answer...
```python def main(): n, q = map(int, input().split()) a = [*map(int, input().split())] d = {} for i in range(n): d[a[i]] = d.get(a[i], 0) + 1 for i in range(q): x = int(input()) c = 0 for j in reversed(d.keys()): y = min(d[j], x // j) c += y x -= y * j if x: print(-1) else: ...
-1
608
A
Saitama Destroys Hotel
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor...
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively. The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim...
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
[ "3 7\n2 1\n3 8\n5 2\n", "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n" ]
[ "11\n", "79\n" ]
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done: 1. Move to floor 5: takes 2 seconds. 2. Pick up passenger 3. 3. Move to floor 3: takes 2 seconds. 4. Wait for passenger 2 to arrive: takes 4 seconds. 5. Pick up passenger 2. 6. Go to floor 2: take...
500
[ { "input": "3 7\n2 1\n3 8\n5 2", "output": "11" }, { "input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64", "output": "79" }, { "input": "1 1000\n1000 1000", "output": "2000" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 1000\n1 1", "output": "1000" }, ...
1,499,750,341
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
61
5,529,600
string = input() numbers = string.split() a, b, floors, times = int(numbers[0]), int(numbers[1]), [], [] for x in range(a): string = input() numbers = string.split() floors.append(int(numbers[0])) times.append(int(numbers[1])) floors, times = floors[::-1], times[::-1] n = 0 for x in range(a): ...
Title: Saitama Destroys Hotel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo...
```python string = input() numbers = string.split() a, b, floors, times = int(numbers[0]), int(numbers[1]), [], [] for x in range(a): string = input() numbers = string.split() floors.append(int(numbers[0])) times.append(int(numbers[1])) floors, times = floors[::-1], times[::-1] n = 0 for x in ...
0
937
B
Vile Grasshoppers
PROGRAMMING
1,400
[ "brute force", "math", "number theory" ]
null
null
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grassh...
The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109).
Output the number of the highest suitable branch. If there are none, print -1 instead.
[ "3 6\n", "3 4\n" ]
[ "5\n", "-1\n" ]
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5. It immediately follows that there are no valid branches in second sample case.
1,000
[ { "input": "3 6", "output": "5" }, { "input": "3 4", "output": "-1" }, { "input": "2 2", "output": "-1" }, { "input": "5 50", "output": "49" }, { "input": "944192806 944193066", "output": "944192807" }, { "input": "1000000000 1000000000", "output":...
1,532,078,694
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
124
0
p, y = (int(x) for x in input().split()) a = [1] * y for i in range(2,p + 1): j = 2 while True: if j * i > y - 1: break else: a[j*i] = 0 j += 1 a.pop(0) a.pop(0) flag = 0 in a if flag: a.reverse() index = a.index(0) a.reverse() pri...
Title: Vile Grasshoppers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (mor...
```python p, y = (int(x) for x in input().split()) a = [1] * y for i in range(2,p + 1): j = 2 while True: if j * i > y - 1: break else: a[j*i] = 0 j += 1 a.pop(0) a.pop(0) flag = 0 in a if flag: a.reverse() index = a.index(0) a.reverse(...
-1
796
A
Buying A House
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ...
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=...
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
[ "5 1 20\n0 27 32 21 19\n", "7 3 50\n62 0 0 0 99 33 22\n", "10 5 100\n1 0 1 0 0 0 0 0 1 1\n" ]
[ "40", "30", "20" ]
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 a...
500
[ { "input": "5 1 20\n0 27 32 21 19", "output": "40" }, { "input": "7 3 50\n62 0 0 0 99 33 22", "output": "30" }, { "input": "10 5 100\n1 0 1 0 0 0 0 0 1 1", "output": "20" }, { "input": "5 3 1\n1 1 0 0 1", "output": "10" }, { "input": "5 5 5\n1 0 5 6 0", "outpu...
1,559,807,370
2,147,483,647
Python 3
OK
TESTS
58
109
0
n,m,k=map(int,input().split()) m-=1 l=[int(x) for x in input().split()] q=[] for i in range(n): if l[i]!=0 and l[i]<=k: q.append((abs(i-m))*10) print(min(q))
Title: Buying A House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li...
```python n,m,k=map(int,input().split()) m-=1 l=[int(x) for x in input().split()] q=[] for i in range(n): if l[i]!=0 and l[i]<=k: q.append((abs(i-m))*10) print(min(q)) ```
3
299
A
Ksusha and Array
PROGRAMMING
1,000
[ "brute force", "number theory", "sortings" ]
null
null
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n" ]
[ "2\n", "1\n", "-1\n" ]
none
500
[ { "input": "3\n2 2 4", "output": "2" }, { "input": "5\n2 1 3 1 6", "output": "1" }, { "input": "3\n2 3 5", "output": "-1" }, { "input": "1\n331358794", "output": "331358794" }, { "input": "5\n506904227 214303304 136194869 838256937 183952885", "output": "-1" ...
1,555,231,972
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
248
7,475,200
n = input() li = input().split() m = int(min(li)) for item in li: if int(item) % m != 0: m=-1 break; print (m)
Title: Ksusha and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that ...
```python n = input() li = input().split() m = int(min(li)) for item in li: if int(item) % m != 0: m=-1 break; print (m) ```
0
26
B
Regular Bracket Sequence
PROGRAMMING
1,400
[ "greedy" ]
B. Regular Bracket Sequence
5
256
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some...
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output the maximum possible length of a regular bracket sequence.
[ "(()))(\n", "((()())\n" ]
[ "4\n", "6\n" ]
none
1,000
[ { "input": "(()))(", "output": "4" }, { "input": "((()())", "output": "6" }, { "input": "(", "output": "0" }, { "input": ")", "output": "0" }, { "input": ")(()(", "output": "2" }, { "input": "))))))(", "output": "0" }, { "input": "()()(()((...
1,679,855,489
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
92
0
s = str(input()) l = [] lo = [] for i in s: l.append(i) if l[-1] == "(": l.pop() for i in l: if i == "(": lo.append(i) c = 0 for i in l: if i == ")" and len(lo) > 0: c+=2 lo.pop() print(c)
Title: Regular Bracket Sequence Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula...
```python s = str(input()) l = [] lo = [] for i in s: l.append(i) if l[-1] == "(": l.pop() for i in l: if i == "(": lo.append(i) c = 0 for i in l: if i == ")" and len(lo) > 0: c+=2 lo.pop() print(c) ```
0
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }...
1,693,990,116
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
124
3,072,000
n = int(input()) m = int(input()) sol = n + m;n = str(n) m = str(m);sol = str(c) n = int(n.replace('0', "")) m = int(m.replace('0', "")) sol=int(sol.replace("0","")) if n + m == sol: print("YES") else: print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu...
```python n = int(input()) m = int(input()) sol = n + m;n = str(n) m = str(m);sol = str(c) n = int(n.replace('0', "")) m = int(m.replace('0', "")) sol=int(sol.replace("0","")) if n + m == sol: print("YES") else: print("NO") ```
-1
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-...
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input"...
1,665,214,610
2,147,483,647
Python 3
OK
TESTS
65
46
0
n,t = map(int,input().split()) s = '1' i = 1 while i <= n-1: s += '0' i += 1 w = s + '0' num1 = int(s) num2 = int(w) while num1 < num2: if num1 % t == 0: print(num1) break else: num1 += 1 if num1 == num2: print(-1)
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larg...
```python n,t = map(int,input().split()) s = '1' i = 1 while i <= n-1: s += '0' i += 1 w = s + '0' num1 = int(s) num2 = int(w) while num1 < num2: if num1 % t == 0: print(num1) break else: num1 += 1 if num1 == num2: print(-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,627,881,485
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
6,656,000
n, a,b = map(int,input().split()) c= (a+b)//n if a%c==0 and b%c==0: print(c) else: c-=1 print(min(a,b, c))
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 n, a,b = map(int,input().split()) c= (a+b)//n if a%c==0 and b%c==0: print(c) else: c-=1 print(min(a,b, c)) ```
0
518
A
Vitaly and Strings
PROGRAMMING
1,600
[ "constructive algorithms", "strings" ]
null
null
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli...
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string. The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters. It is guaranteed that the lengths of strings *s* and *t* are the same and str...
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them.
[ "a\nc\n", "aaa\nzzz\n", "abcdefg\nabcdefh\n" ]
[ "b\n", "kkk\n", "No such string\n" ]
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ...
500
[ { "input": "a\nc", "output": "b" }, { "input": "aaa\nzzz", "output": "kkk" }, { "input": "abcdefg\nabcdefh", "output": "No such string" }, { "input": "abcdefg\nabcfefg", "output": "abcdefh" }, { "input": "frt\nfru", "output": "No such string" }, { "inp...
1,638,356,843
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
46
0
s=input() a=input() l=list(s) l[len(s)-1]=chr(((ord(l[len(s)-1])-97+1)%26+97)) st="" for i in l: st+=i if st<a: print(st) else: print("No such string")
Title: Vitaly and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provi...
```python s=input() a=input() l=list(s) l[len(s)-1]=chr(((ord(l[len(s)-1])-97+1)%26+97)) st="" for i in l: st+=i if st<a: print(st) else: print("No such string") ```
0
691
B
s-palindrome
PROGRAMMING
1,600
[ "implementation", "strings" ]
null
null
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. You are given a string *s*. Check if the ...
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters.
Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise.
[ "oXoxoXo\n", "bod\n", "ER\n" ]
[ "TAK\n", "TAK\n", "NIE\n" ]
none
0
[ { "input": "oXoxoXo", "output": "TAK" }, { "input": "bod", "output": "TAK" }, { "input": "ER", "output": "NIE" }, { "input": "o", "output": "TAK" }, { "input": "a", "output": "NIE" }, { "input": "opo", "output": "NIE" }, { "input": "HCMoxkg...
1,473,522,321
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
93
0
pair = dict() pair['A'] = 'A' pair['b'] = 'd' pair['d'] = 'b' pair['H'] = 'H' pair['I'] = 'I' pair['M'] = 'M' pair['O'] = 'O' pair['o'] = 'o' pair['p'] = 'q' pair['q'] = 'p' pair['T'] = 'T' pair['U'] = 'U' pair['V'] = 'V' pair['v'] = 'v' pair['W'] = 'W' pair['w'] = 'w' pair['X'] = 'X' pair['x'] = 'x' pair['Y'] = 'Y' s ...
Title: s-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second h...
```python pair = dict() pair['A'] = 'A' pair['b'] = 'd' pair['d'] = 'b' pair['H'] = 'H' pair['I'] = 'I' pair['M'] = 'M' pair['O'] = 'O' pair['o'] = 'o' pair['p'] = 'q' pair['q'] = 'p' pair['T'] = 'T' pair['U'] = 'U' pair['V'] = 'V' pair['v'] = 'v' pair['W'] = 'W' pair['w'] = 'w' pair['X'] = 'X' pair['x'] = 'x' pair['Y'...
0
801
A
Vicious Keyboard
PROGRAMMING
1,100
[ "brute force" ]
null
null
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi...
The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
[ "VK\n", "VV\n", "V\n", "VKKKKKKKKKVVVVVVVVVK\n", "KVKV\n" ]
[ "1\n", "1\n", "0\n", "3\n", "1\n" ]
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear. For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring. For the fourth case, we ...
500
[ { "input": "VK", "output": "1" }, { "input": "VV", "output": "1" }, { "input": "V", "output": "0" }, { "input": "VKKKKKKKKKVVVVVVVVVK", "output": "3" }, { "input": "KVKV", "output": "1" }, { "input": "VKKVVVKVKVK", "output": "5" }, { "input...
1,492,357,293
393
Python 3
OK
TESTS
63
62
5,529,600
s = input().strip() s = s.replace("VK", "*") cnt = sum(map(lambda x: x=="*",s)) if "VV" in s or "KK" in s: cnt +=1 print(cnt)
Title: Vicious Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i...
```python s = input().strip() s = s.replace("VK", "*") cnt = sum(map(lambda x: x=="*",s)) if "VV" in s or "KK" in s: cnt +=1 print(cnt) ```
3
274
A
k-Multiple Free Set
PROGRAMMING
1,500
[ "binary search", "greedy", "sortings" ]
null
null
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=&lt;<=*y*) from the set, such that *y*<==<=*x*·*k*. You're given a set of *n* distinct positive integers. Your task is to find th...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). All the numbers in the lines are separated by single spaces.
On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}.
[ "6 2\n2 3 6 5 4 10\n" ]
[ "3\n" ]
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
500
[ { "input": "6 2\n2 3 6 5 4 10", "output": "3" }, { "input": "10 2\n1 2 3 4 5 6 7 8 9 10", "output": "6" }, { "input": "1 1\n1", "output": "1" }, { "input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1...
1,591,357,607
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
8,294,400
n,k=map(int,input().split()) li=[int(i)for i in input().split()] li.sort() m=0 lst=list() for i in range(0,n-1): lst=[] lst.append(li[i]) for j in range(i+1,n): flag=1 lst1=lst for h in lst1: if li[j]/h==k: flag=0 break if flag==1: lst.append(li[j]) m...
Title: k-Multiple Free Set Time Limit: None seconds Memory Limit: None megabytes Problem Description: A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=&lt;<=*y*) from the set, ...
```python n,k=map(int,input().split()) li=[int(i)for i in input().split()] li.sort() m=0 lst=list() for i in range(0,n-1): lst=[] lst.append(li[i]) for j in range(i+1,n): flag=1 lst1=lst for h in lst1: if li[j]/h==k: flag=0 break if flag==1: lst.append(l...
0
120
A
Elevator
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n...
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the...
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
[ "front\n1\n" ]
[ "L\n" ]
none
0
[ { "input": "front\n1", "output": "L" }, { "input": "back\n1", "output": "R" }, { "input": "front\n2", "output": "R" }, { "input": "back\n2", "output": "L" } ]
1,447,199,712
2,147,483,647
Python 3
OK
TESTS
4
92
0
fi = open('input.txt', 'r') d, a = fi.readline().strip() == 'front', int(fi.readline()) == 1 print('L' if d == a else 'R', file=open('output.txt', 'w'))
Title: Elevator Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through...
```python fi = open('input.txt', 'r') d, a = fi.readline().strip() == 'front', int(fi.readline()) == 1 print('L' if d == a else 'R', file=open('output.txt', 'w')) ```
3
676
C
Vasya and String
PROGRAMMING
1,500
[ "binary search", "dp", "strings", "two pointers" ]
null
null
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original strin...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
[ "4 2\nabba\n", "8 1\naabaabaa\n" ]
[ "4\n", "5\n" ]
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
1,500
[ { "input": "4 2\nabba", "output": "4" }, { "input": "8 1\naabaabaa", "output": "5" }, { "input": "1 0\na", "output": "1" }, { "input": "1 1\nb", "output": "1" }, { "input": "1 0\nb", "output": "1" }, { "input": "1 1\na", "output": "1" }, { ...
1,691,830,169
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n, k = map(int, input().split()) s = input() max_beauty = 0 count_a = 0 count_b = 0 window_start = 0 for i in range(n): if s[i] == 'a': count_a += 1 else: count_b += 1 min_count = min(count_a, count_b) while (i - window_start + 1) - min_count > k: if s[window_start] =...
Title: Vasya and String Time Limit: None seconds Memory Limit: None megabytes Problem Description: High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ...
```python n, k = map(int, input().split()) s = input() max_beauty = 0 count_a = 0 count_b = 0 window_start = 0 for i in range(n): if s[i] == 'a': count_a += 1 else: count_b += 1 min_count = min(count_a, count_b) while (i - window_start + 1) - min_count > k: if s[windo...
0
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,698,415,903
2,147,483,647
Python 3
OK
TESTS
25
92
0
l1=[] for i in range(1,6): l=list(map(int,input().split())) l1.append(l) for i in l1: for j in i: if j!=0: c=i.index(j) r=l1.index(i) m=abs(r-2) m=m+abs(c-2) print(m)
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri...
```python l1=[] for i in range(1,6): l=list(map(int,input().split())) l1.append(l) for i in l1: for j in i: if j!=0: c=i.index(j) r=l1.index(i) m=abs(r-2) m=m+abs(c-2) print(m) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,671,444,940
2,147,483,647
PyPy 3-64
OK
TESTS
81
154
0
n = int(input()) x = [] for i in range(n): a, b, c = map(int, input().split()) x.append([a,b,c]) s = 0 m = 0 l = 0 for i in range(n): s += x[i][0] m += x[i][1] l += x[i][2] if s == 0 and m == 0 and l == 0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n = int(input()) x = [] for i in range(n): a, b, c = map(int, input().split()) x.append([a,b,c]) s = 0 m = 0 l = 0 for i in range(n): s += x[i][0] m += x[i][1] l += x[i][2] if s == 0 and m == 0 and l == 0: print("YES") else: print("NO") ```
3.9615
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}...
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All sub...
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"...
1,638,956,940
2,147,483,647
PyPy 3-64
OK
TESTS
133
109
512,000
"""https://codeforces.com/problemset/problem/981/A """ s = input() for r in range(len(s), 1, -1): if s[:r] != s[r - 1::-1]: print(r) break else: print(0)
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar...
```python """https://codeforces.com/problemset/problem/981/A """ s = input() for r in range(len(s), 1, -1): if s[:r] != s[r - 1::-1]: print(r) break else: print(0) ```
3
505
A
Mr. Kitayuta's Gift
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes...
The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter.
If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
[ "revive\n", "ee\n", "kitayuta\n" ]
[ "reviver\n", "eye", "NA\n" ]
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver". For the second sample, there is more than one solution. For example, "eve" will also be accepted. For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
500
[ { "input": "revive", "output": "reviver" }, { "input": "ee", "output": "eee" }, { "input": "kitayuta", "output": "NA" }, { "input": "evima", "output": "NA" }, { "input": "a", "output": "aa" }, { "input": "yutampo", "output": "NA" }, { "inpu...
1,556,375,686
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
s = input() n = len(s) i, j = 0, n-1 cnt = 0 if s == s[::-1]: k = n//2 print(s[:k+1] + s[k:]) exit() while(i < j): if s[i] == s[j]: i += 1 j -= 1 else: s = s[:j+1] + s[i] + s[j+1:] i += 1 if len(s) > n + 1: print('NA'); break if n + 1 != len(s)...
Title: Mr. Kitayuta's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re...
```python s = input() n = len(s) i, j = 0, n-1 cnt = 0 if s == s[::-1]: k = n//2 print(s[:k+1] + s[k:]) exit() while(i < j): if s[i] == s[j]: i += 1 j -= 1 else: s = s[:j+1] + s[i] + s[j+1:] i += 1 if len(s) > n + 1: print('NA'); break if n + 1...
0
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co...
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "ou...
1,613,645,596
2,147,483,647
Python 3
OK
TESTS
26
62
0
n=int(input()) m=n//2 switcher={ 0:[m-1,m+1], 1:[m,m+1], 2:[m-2,m+2], 3:[m,m+1], } ans=switcher.get(n%4) print(ans[0],ans[1])
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is cal...
```python n=int(input()) m=n//2 switcher={ 0:[m-1,m+1], 1:[m,m+1], 2:[m-2,m+2], 3:[m,m+1], } ans=switcher.get(n%4) print(ans[0],ans[1]) ```
3