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
476
E
Dreamoon and Strings
PROGRAMMING
2,200
[ "dp", "strings" ]
null
null
Dreamoon has a string *s* and a pattern string *p*. He first removes exactly *x* characters from *s* obtaining string *s*' as a result. Then he calculates that is defined as the maximal number of non-overlapping substrings equal to *p* that can be found in *s*'. He wants to make this number as big as possible. More f...
The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=2<=000). The second line of the input contains the string *p* (1<=≤<=|*p*|<=≤<=500). Both strings will only consist of lower case English letters.
Print |*s*|<=+<=1 space-separated integers in a single line representing the for all *x* from 0 to |*s*|.
[ "aaaaa\naa\n", "axbaxxb\nab\n" ]
[ "2 2 1 1 0 0\n", "0 1 1 2 1 1 0 0\n" ]
For the first sample, the corresponding optimal values of *s*' after removal 0 through |*s*| = 5 characters from *s* are {"aaaaa", "aaaa", "aaa", "aa", "a", ""}. For the second sample, possible corresponding optimal values of *s*' are {"axbaxxb", "abaxxb", "axbab", "abab", "aba", "ab", "a", ""}.
2,500
[ { "input": "aaaaa\naa", "output": "2 2 1 1 0 0" }, { "input": "axbaxxb\nab", "output": "0 1 1 2 1 1 0 0" }, { "input": "aabb\nab", "output": "1 1 1 0 0" }, { "input": "aaaaaaaaaaaaaaa\na", "output": "15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0" }, { "input": "aaaaaaaaaa...
1,698,961,766
2,147,483,647
PyPy 3
OK
TESTS
43
171
20,172,800
s, p = input(), input() n, m = len(s) + 1, len(p) d = [[0] * n for t in range(n)] for x in range(1, n): i, j = x, m while i and j: j -= s[i - 1] == p[j - 1] i -= 1 if not j: for y in range(i + 1): d[x][y + x - i - m] = d[i][y] + 1 for y in range(x): d[x][y] = max(d[x][y...
Title: Dreamoon and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon has a string *s* and a pattern string *p*. He first removes exactly *x* characters from *s* obtaining string *s*' as a result. Then he calculates that is defined as the maximal number of non-overlapping s...
```python s, p = input(), input() n, m = len(s) + 1, len(p) d = [[0] * n for t in range(n)] for x in range(1, n): i, j = x, m while i and j: j -= s[i - 1] == p[j - 1] i -= 1 if not j: for y in range(i + 1): d[x][y + x - i - m] = d[i][y] + 1 for y in range(x): d[x][y] = ...
3
990
C
Bracket Sequences Concatenation Problem
PROGRAMMING
1,500
[ "implementation" ]
null
null
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg...
The first line contains one integer $n \, (1 \le n \le 3 \cdot 10^5)$ — the number of bracket sequences. The following $n$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $3 \cdot 10^5$.
In the single line print a single integer — the number of pairs $i, j \, (1 \le i, j \le n)$ such that the bracket sequence $s_i + s_j$ is a regular bracket sequence.
[ "3\n)\n()\n(\n", "2\n()\n()\n" ]
[ "2\n", "4\n" ]
In the first example, suitable pairs are $(3, 1)$ and $(2, 2)$. In the second example, any pair is suitable, namely $(1, 1), (1, 2), (2, 1), (2, 2)$.
0
[ { "input": "3\n)\n()\n(", "output": "2" }, { "input": "2\n()\n()", "output": "4" }, { "input": "7\n()(\n)\n)(\n())\n(((\n()()()\n()", "output": "6" }, { "input": "6\n(\n((\n(((\n))))\n)))))\n))))))", "output": "0" }, { "input": "9\n(()\n((())\n(\n)\n(()()(()())))\...
1,528,657,111
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
6,144,000
n = int(input()) s = list() global stack stack = list() for i in range(0,n): s.append(input()) #---------------------------------stack--------------------- def push(x,): stack.append(x) def pop(): if len(stack)!=0: return(stack.pop()) def check(a,b,count): c = a+b ...
Title: Bracket Sequences Concatenation Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting ...
```python n = int(input()) s = list() global stack stack = list() for i in range(0,n): s.append(input()) #---------------------------------stack--------------------- def push(x,): stack.append(x) def pop(): if len(stack)!=0: return(stack.pop()) def check(a,b,count): ...
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,586,519,908
2,147,483,647
Python 3
OK
TESTS
30
218
0
import sys lines = sys.stdin.readlines() st = lines[0].strip() lowerC, upperC = 0,0 for l in st: if ord(l) >= ord("a"): lowerC += 1 else: upperC += 1 if lowerC >= upperC: print(st.lower()) else: print(st.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python import sys lines = sys.stdin.readlines() st = lines[0].strip() lowerC, upperC = 0,0 for l in st: if ord(l) >= ord("a"): lowerC += 1 else: upperC += 1 if lowerC >= upperC: print(st.lower()) else: print(st.upper()) ```
3.9455
988
D
Points and Powers of Two
PROGRAMMING
1,800
[ "brute force", "math" ]
null
null
There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any sub...
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of points. The second line contains $n$ pairwise distinct integers $x_1, x_2, \dots, x_n$ ($-10^9 \le x_i \le 10^9$) — the coordinates of points.
In the first line print $m$ — the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print $m$ integers — the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them.
[ "6\n3 5 4 7 10 12\n", "5\n-1 2 5 8 11\n" ]
[ "3\n7 3 5", "1\n8\n" ]
In the first example the answer is $[7, 3, 5]$. Note, that $|7-3|=4=2^2$, $|7-5|=2=2^1$ and $|3-5|=2=2^1$. You can't find a subset having more points satisfying the required property.
0
[ { "input": "6\n3 5 4 7 10 12", "output": "3\n3 4 5 " }, { "input": "5\n-1 2 5 8 11", "output": "1\n-1 " }, { "input": "1\n42", "output": "1\n42 " }, { "input": "3\n0 -536870912 536870912", "output": "3\n-536870912 0 536870912 " }, { "input": "2\n536870912 -5368709...
1,620,758,023
6,043
PyPy 3
OK
TESTS
99
920
44,953,600
from sys import stdin input = stdin.readline def solve(): n = int(input()) x = [int(x) for x in input().split()] s = set(x) ans = [x[0]] for i in range(n): for j in range(0, 32): if x[i] + 2**j in s: ans = [x[i], x[i] + 2**j] if x[i] +...
Title: Points and Powers of Two Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is a...
```python from sys import stdin input = stdin.readline def solve(): n = int(input()) x = [int(x) for x in input().split()] s = set(x) ans = [x[0]] for i in range(n): for j in range(0, 32): if x[i] + 2**j in s: ans = [x[i], x[i] + 2**j] ...
3
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,690,043,958
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
words = int(input()) for i in range(words): print(words)
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 words = int(input()) for i in range(words): print(words) ```
0
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRR...
1,637,473,411
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) s=input() count=0 for i in range(n): if s[i] in 'RU'': s.replace('RU','D') elif s[i] in 'UR': s.replace('UR','D') print(s)
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence movi...
```python n=int(input()) s=input() count=0 for i in range(n): if s[i] in 'RU'': s.replace('RU','D') elif s[i] in 'UR': s.replace('UR','D') print(s) ```
-1
278
A
Circle Line
PROGRAMMING
800
[ "implementation" ]
null
null
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) —...
Print a single number — the length of the shortest path between stations number *s* and *t*.
[ "4\n2 3 4 9\n1 3\n", "4\n5 8 2 100\n4 1\n", "3\n1 1 1\n3 1\n", "3\n31 41 59\n1 1\n" ]
[ "5\n", "15\n", "1\n", "0\n" ]
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of st...
500
[ { "input": "4\n2 3 4 9\n1 3", "output": "5" }, { "input": "4\n5 8 2 100\n4 1", "output": "15" }, { "input": "3\n1 1 1\n3 1", "output": "1" }, { "input": "3\n31 41 59\n1 1", "output": "0" }, { "input": "5\n16 13 10 30 15\n4 2", "output": "23" }, { "inpu...
1,591,639,718
2,147,483,647
Python 3
OK
TESTS
23
218
0
n=int(input()) l=list(map(int,input().split())) x,y=map(int,input().split()) s,t=min(x,y),max(x,y) print(min(sum(l[s-1:t-1]),sum(l[t-1:])+sum(l[:s-1])))
Title: Circle Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd...
```python n=int(input()) l=list(map(int,input().split())) x,y=map(int,input().split()) s,t=min(x,y),max(x,y) print(min(sum(l[s-1:t-1]),sum(l[t-1:])+sum(l[:s-1]))) ```
3
733
B
Parade
PROGRAMMING
1,100
[ "math" ]
null
null
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns. The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively.
Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached. Consider that columns are numbered from 1 to *n* in the order they are given in the input data. If there are several answers, print any of them.
[ "3\n5 6\n8 9\n10 3\n", "2\n6 5\n5 6\n", "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n" ]
[ "3\n", "1\n", "0\n" ]
In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5. If you give the order to change the leg to the third co...
1,000
[ { "input": "3\n5 6\n8 9\n10 3", "output": "3" }, { "input": "2\n6 5\n5 6", "output": "1" }, { "input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32", "output": "0" }, { "input": "2\n500 499\n500 500", "output": "0" }, { "input": "1\n139 252", "output": "0" }, { ...
1,583,872,075
2,147,483,647
PyPy 3
OK
TESTS
40
873
9,420,800
import sys import math import bisect def solve(A, B): n = len(A) sum_a = sum(A) sum_b = sum(B) max_val = abs(sum_a - sum_b) sol = 0 for i in range(n): tmp_a = sum_a - A[i] + B[i] tmp_b = sum_b - B[i] + A[i] val = abs(tmp_a - tmp_b) if max_val < val:...
Title: Parade Time Limit: None seconds Memory Limit: None megabytes Problem Description: Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should...
```python import sys import math import bisect def solve(A, B): n = len(A) sum_a = sum(A) sum_b = sum(B) max_val = abs(sum_a - sum_b) sol = 0 for i in range(n): tmp_a = sum_a - A[i] + B[i] tmp_b = sum_b - B[i] + A[i] val = abs(tmp_a - tmp_b) if max_...
3
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,644,604,108
2,147,483,647
PyPy 3
OK
TESTS
10
62
0
import math a = int(input()) - 1 print(math.factorial(2*a)//(math.factorial(a)**2))
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python import math a = int(input()) - 1 print(math.factorial(2*a)//(math.factorial(a)**2)) ```
3
215
A
Bicycle Chain
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o...
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
[ "2\n4 5\n3\n12 13 15\n", "4\n1 2 3 4\n5\n10 11 12 13 14\n" ]
[ "2\n", "1\n" ]
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
500
[ { "input": "2\n4 5\n3\n12 13 15", "output": "2" }, { "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 2\n1\n1", "output": "1" }, { "input": "1\n1\n2\n1 2", "output": "1" }, { "input":...
1,589,525,191
2,147,483,647
PyPy 3
OK
TESTS
57
310
21,401,600
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) temp = [0] for i in a: for j in b: if j%i==0: if j/i > max(temp): temp = [] temp.append(j/i) elif j/i == max(temp): te...
Title: Bicycle Chain Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We ...
```python n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) temp = [0] for i in a: for j in b: if j%i==0: if j/i > max(temp): temp = [] temp.append(j/i) elif j/i == max(temp): ...
3
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,694,959,754
2,147,483,647
Python 3
OK
TESTS
30
248
16,076,800
b=[] for i in range(int(input())):b.append(input()) print(b.count('Tetrahedron')*4+b.count('Cube')*6+b.count('Octahedron')*8+b.count('Dodecahedron')*12+b.count('Icosahedron')*20)
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python b=[] for i in range(int(input())):b.append(input()) print(b.count('Tetrahedron')*4+b.count('Cube')*6+b.count('Octahedron')*8+b.count('Dodecahedron')*12+b.count('Icosahedron')*20) ```
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,595,269,529
2,147,483,647
PyPy 3
OK
TESTS
33
155
20,172,800
a = [[8]*5 for i in range(5)] b = [[int(j) for j in input().split()] for i in range(3)] c = [[1]*5 for i in range(5)] n, k = 0, 0 for i in range(1,4): for j in range(1,4): a[i][j] = b[n][k] k+=1 n+=1 k = 0 for i in range(1,4): for j in range(1,4): if a[i][j] % 2 == ...
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 = [[8]*5 for i in range(5)] b = [[int(j) for j in input().split()] for i in range(3)] c = [[1]*5 for i in range(5)] n, k = 0, 0 for i in range(1,4): for j in range(1,4): a[i][j] = b[n][k] k+=1 n+=1 k = 0 for i in range(1,4): for j in range(1,4): if a[i][...
3
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,696,771,104
2,147,483,647
Python 3
OK
TESTS
44
92
0
n,t = map(int,input().split()) que = list(input()) for j in range(t): check = 0 for i in range(len(que)-1): if que[i+1] =="G" and que[i] == "B" and i >= check: que[i],que[i+1] = que[i+1],que[i] check = i + 2 print("".join(que))
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 n,t = map(int,input().split()) que = list(input()) for j in range(t): check = 0 for i in range(len(que)-1): if que[i+1] =="G" and que[i] == "B" and i >= check: que[i],que[i+1] = que[i+1],que[i] check = i + 2 print("".join(que)) ```
3
17
A
Noldbach problem
PROGRAMMING
1,000
[ "brute force", "math", "number theory" ]
A. Noldbach problem
2
64
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold...
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
[ "27 2\n", "45 7\n" ]
[ "YES", "NO" ]
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
0
[ { "input": "27 2", "output": "YES" }, { "input": "45 7", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "15 1", "output": "YES" }, { "input": "17 1", "output": "YES" }, { "input": "34 5", "output": "NO" }, { "input": "37 ...
1,667,046,426
2,147,483,647
Python 3
OK
TESTS
35
122
0
# Hydro submission #635d1c16e2991f80a1014e3d@1667046423273 n,k =map( int,input().split()) a = [] count=0 for i in range(2, n + 1): for j in range(2, i): if i % j == 0: break else: a.append(i) for i in a: for j in range(1, len(a)): if a[j-1]+a[j]+1==i: count+=...
Title: Noldbach problem Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob...
```python # Hydro submission #635d1c16e2991f80a1014e3d@1667046423273 n,k =map( int,input().split()) a = [] count=0 for i in range(2, n + 1): for j in range(2, i): if i % j == 0: break else: a.append(i) for i in a: for j in range(1, len(a)): if a[j-1]+a[j]+1==i: ...
3.9695
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow...
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output...
1,691,730,759
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
n,k=map(int,input().split()) # if n is odd if n%2: no_of_odd=(n//2)+1 else: no_of_odd=n//2 if k<(no_of_odd): print((k*2)-1) else: print((k-no_of_odd)*2)
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ...
```python n,k=map(int,input().split()) # if n is odd if n%2: no_of_odd=(n//2)+1 else: no_of_odd=n//2 if k<(no_of_odd): print((k*2)-1) else: print((k-no_of_odd)*2) ```
0
740
A
Alyona and copybooks
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack ...
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
[ "1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n" ]
[ "3\n", "1\n", "0\n", "1000000000\n" ]
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona ...
500
[ { "input": "1 1 3 4", "output": "3" }, { "input": "6 2 1 1", "output": "1" }, { "input": "4 4 4 4", "output": "0" }, { "input": "999999999 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1016 3 2 1", "output": "0" }, { "input":...
1,486,672,320
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
61
4,608,000
import math def main(): n, a, b, c = map(int, input().split()) n = (4 - (n%4)) % 4 if n == 0: print(0) elif n == 1: print(a) elif n == 2: print(min(2*a, b)) elif n == 3: print(min(3*a, c, a + b)) main()
Title: Alyona and copybooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the sh...
```python import math def main(): n, a, b, c = map(int, input().split()) n = (4 - (n%4)) % 4 if n == 0: print(0) elif n == 1: print(a) elif n == 2: print(min(2*a, b)) elif n == 3: print(min(3*a, c, a + b)) main() ```
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,674,138,062
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
a,b,c=map(int,input().split()) l=[] l.append(a) l.append(b) l.append(c) l.sort() print(a[1]-a[0]+a[2]-a[1])
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python a,b,c=map(int,input().split()) l=[] l.append(a) l.append(b) l.append(c) l.sort() print(a[1]-a[0]+a[2]-a[1]) ```
-1
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", ...
1,641,313,907
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
7,065,600
n=int(input()) q=[] x=[int(x) for x in input().split()] for i in range(n): if x[i] not in q: if x[i]!=0: q.append(x[i]) print(len(q))
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second ...
```python n=int(input()) q=[] x=[int(x) for x in input().split()] for i in range(n): if x[i] not in q: if x[i]!=0: q.append(x[i]) print(len(q)) ```
0
962
D
Merge Equals
PROGRAMMING
1,600
[ "data structures", "implementation" ]
null
null
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two...
The first line contains a single integer $n$ ($2 \le n \le 150\,000$) — the number of elements in the array. The second line contains a sequence from $n$ elements $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{9}$) — the elements of the array.
In the first line print an integer $k$ — the number of elements in the array after all the performed operations. In the second line print $k$ integers — the elements of the array after all the performed operations.
[ "7\n3 4 1 2 2 1 1\n", "5\n1 1 3 1 1\n", "5\n10 40 20 50 30\n" ]
[ "4\n3 8 2 1 \n", "2\n3 4 \n", "5\n10 40 20 50 30 \n" ]
The first two examples were considered in the statement. In the third example all integers in the given array are distinct, so it will not change.
0
[ { "input": "7\n3 4 1 2 2 1 1", "output": "4\n3 8 2 1 " }, { "input": "5\n1 1 3 1 1", "output": "2\n3 4 " }, { "input": "5\n10 40 20 50 30", "output": "5\n10 40 20 50 30 " }, { "input": "100\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 1...
1,696,505,745
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
import heapq n = int(input()) a = [int(i) for i in input().split()] a = [[a[i],i] for i in range(n)] c = [] heapq.heapify(a) heapq.heapify(c) while a: x = heapq.heappop(a) if not a: heapq.heappush(c,x) break y = heapq.heappop(a) if x[0]!=y[0]: heapq.heappush(c,x) ...
Title: Merge Equals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first...
```python import heapq n = int(input()) a = [int(i) for i in input().split()] a = [[a[i],i] for i in range(n)] c = [] heapq.heapify(a) heapq.heapify(c) while a: x = heapq.heappop(a) if not a: heapq.heappush(c,x) break y = heapq.heappop(a) if x[0]!=y[0]: heapq.heap...
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,630,059,635
2,147,483,647
Python 3
OK
TESTS
40
78
6,758,400
def chat_room(): s = input() res = "hello" j = 0 count = 0 for i in range(len(s)): try: if s[i] == res[j]: j+=1 count += 1 if count == 5: return "YES" except: pass return "NO" print(chat_room())
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 chat_room(): s = input() res = "hello" j = 0 count = 0 for i in range(len(s)): try: if s[i] == res[j]: j+=1 count += 1 if count == 5: return "YES" except: pass return "NO" print(chat_room()) ```
3.948411
903
C
Boxes Packing
PROGRAMMING
1,200
[ "greedy" ]
null
null
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Print the minimum possible number of visible boxes.
[ "3\n1 2 3\n", "4\n4 2 4 3\n" ]
[ "1\n", "2\n" ]
In the first example it is possible to put box 1 into box 2, and 2 into 3. In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
0
[ { "input": "3\n1 2 3", "output": "1" }, { "input": "4\n4 2 4 3", "output": "2" }, { "input": "10\n58 58 58 58 58 58 58 58 58 58", "output": "10" }, { "input": "10\n86 89 89 86 86 89 86 86 89 89", "output": "5" }, { "input": "100\n981 288 186 186 292 876 341 288 98...
1,610,140,339
2,147,483,647
Python 3
OK
TESTS
24
62
409,600
n = int(input()) a = input().split() for i in range(0,n): a[i] = int(a[i]) a.sort() a.append("x") y = 1 i = 0 while i < n-1: occ = 1 while a[i] == a[i+1]: occ += 1 i += 1 if occ > y: y = occ i += 1 print(y)
Title: Boxes Packing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not pu...
```python n = int(input()) a = input().split() for i in range(0,n): a[i] = int(a[i]) a.sort() a.append("x") y = 1 i = 0 while i < n-1: occ = 1 while a[i] == a[i+1]: occ += 1 i += 1 if occ > y: y = occ i += 1 print(y) ```
3
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,583,959,112
2,147,483,647
Python 3
OK
TESTS
25
248
0
n, m = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) suma = 0 for i in range(n): if (a[i] < 0) and m: suma += abs(a[i]) m -= 1 print(suma)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python n, m = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) suma = 0 for i in range(n): if (a[i] < 0) and m: suma += abs(a[i]) m -= 1 print(suma) ```
3.938
869
A
The Artful Expedient
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, deno...
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi. The third line contains *n* space-separated integers *y*1,<=...
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
[ "3\n1 2 3\n4 5 6\n", "5\n2 4 6 8 10\n9 7 5 3 1\n" ]
[ "Karen\n", "Karen\n" ]
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number. In the second example, there are 16 such pairs, and Karen wins again.
500
[ { "input": "3\n1 2 3\n4 5 6", "output": "Karen" }, { "input": "5\n2 4 6 8 10\n9 7 5 3 1", "output": "Karen" }, { "input": "1\n1\n2000000", "output": "Karen" }, { "input": "2\n97153 2000000\n1999998 254", "output": "Karen" }, { "input": "15\n31 30 29 28 27 26 25 24...
1,605,441,221
2,147,483,647
PyPy 3
OK
TESTS
49
171
2,150,400
import sys n = int(sys.stdin.readline()) arr1 = list(map(int, sys.stdin.readline().split())) arr2 = list(map(int, sys.stdin.readline().split())) cnt = 0 arr = arr1 + arr2 for i in arr: for j in arr: temp = i ^ j if temp == 2 * n: cnt += 1 print('Karen' if cnt % 2 == 0 else 'Koy...
Title: The Artful Expedient Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive int...
```python import sys n = int(sys.stdin.readline()) arr1 = list(map(int, sys.stdin.readline().split())) arr2 = list(map(int, sys.stdin.readline().split())) cnt = 0 arr = arr1 + arr2 for i in arr: for j in arr: temp = i ^ j if temp == 2 * n: cnt += 1 print('Karen' if cnt % 2 == 0...
3
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,694,337,085
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
t = 4 y = 3 u = 2 for z in range(3): n, q, w, e, r = map(int, input().split()) if n == 1: print(t) else: if q == 1: print(y) else: if w == 1: print(u) else: if e == 1: print(y) ...
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 t = 4 y = 3 u = 2 for z in range(3): n, q, w, e, r = map(int, input().split()) if n == 1: print(t) else: if q == 1: print(y) else: if w == 1: print(u) else: if e == 1: pri...
0
995
B
Suit and Tie
PROGRAMMING
1,400
[ "greedy", "implementation", "math" ]
null
null
Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the pic...
The first line contains a single integer $n$ ($1 \le n \le 100$), the number of pairs of people. The second line contains $2n$ integers $a_1, a_2, \dots, a_{2n}$. For each $i$ with $1 \le i \le n$, $i$ appears exactly twice. If $a_j = a_k = i$, that means that the $j$-th and $k$-th people in the line form a couple.
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
[ "4\n1 1 2 3 3 2 4 4\n", "3\n1 1 2 2 3 3\n", "3\n3 1 2 3 1 2\n" ]
[ "2\n", "0\n", "3\n" ]
In the first sample case, we can transform $1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$ in two steps. Note that the sequence $1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$ also works in the same number of steps. The second sample case already satisfies the constr...
750
[ { "input": "4\n1 1 2 3 3 2 4 4", "output": "2" }, { "input": "3\n1 1 2 2 3 3", "output": "0" }, { "input": "3\n3 1 2 3 1 2", "output": "3" }, { "input": "8\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4", "output": "27" }, { "input": "2\n1 2 1 2", "output": "1" }, { ...
1,650,765,689
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
61
0
n = int(input()) p = input().split(" ") p = [int(p[i]) for i in range (2*n)] c = 0 # slides the value at index ind to i+1, returns number of spots slid def slide(i, ind): temp = p[ind] for j in range (ind-1, i, -1): p[j+1] = p[j] print(p) p[i+1] = temp return ind-i-1 for i in range (0,...
Title: Suit and Tie Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the o...
```python n = int(input()) p = input().split(" ") p = [int(p[i]) for i in range (2*n)] c = 0 # slides the value at index ind to i+1, returns number of spots slid def slide(i, ind): temp = p[ind] for j in range (ind-1, i, -1): p[j+1] = p[j] print(p) p[i+1] = temp return ind-i-1 for i in...
0
0
none
none
none
0
[ "none" ]
null
null
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones ...
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=500) — the number of gemstones. The second line contains *n* space-separated integers, the *i*-th of which is *c**i* (1<=≤<=*c**i*<=≤<=*n*) — the color of the *i*-th gemstone in a line.
Print a single integer — the minimum number of seconds needed to destroy the entire line.
[ "3\n1 2 1\n", "3\n1 2 3\n", "7\n1 4 4 2 3 2 1\n" ]
[ "1\n", "3\n", "2\n" ]
In the first sample, Genos can destroy the entire line in one second. In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds. In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 ...
0
[ { "input": "3\n1 2 1", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "7\n1 4 4 2 3 2 1", "output": "2" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n1 2", "output": "2" }, { ...
1,689,171,604
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689171603.416308")# 1689171603.416328
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In ...
```python print("_RANDOM_GUESS_1689171603.416308")# 1689171603.416328 ```
0
876
A
Trip For Meal
PROGRAMMING
900
[ "math" ]
null
null
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ...
First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits. Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses. Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses. Fourth line contains an integer *c* ...
Output one number — minimum distance in meters Winnie must go through to have a meal *n* times.
[ "3\n2\n3\n1\n", "1\n2\n3\n5\n" ]
[ "3\n", "0\n" ]
In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3. In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.
500
[ { "input": "3\n2\n3\n1", "output": "3" }, { "input": "1\n2\n3\n5", "output": "0" }, { "input": "10\n1\n8\n3", "output": "9" }, { "input": "7\n10\n5\n6", "output": "30" }, { "input": "9\n9\n7\n5", "output": "42" }, { "input": "9\n37\n85\n76", "outpu...
1,508,408,815
2,147,483,647
Python 3
OK
TESTS
48
78
5,939,200
import math import re def ria(): return [int(i) for i in input().split()] def ri(): return int(input()) def rfa(): return [float(i) for i in input().split()] n = ria()[0] a = ria()[0] b = ria()[0] c = ria()[0] n -= 1 if n == 0: print(0) exit() print(min(a + c * (n - 1...
Title: Trip For Meal Time Limit: None seconds Memory Limit: None megabytes Problem Description: Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair...
```python import math import re def ria(): return [int(i) for i in input().split()] def ri(): return int(input()) def rfa(): return [float(i) for i in input().split()] n = ria()[0] a = ria()[0] b = ria()[0] c = ria()[0] n -= 1 if n == 0: print(0) exit() print(min(a + ...
3
645
C
Enduring Exodus
PROGRAMMING
1,600
[ "binary search", "two pointers" ]
null
null
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of *n* rooms located in a row, some of which are occupie...
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=&lt;<=*n*<=≤<=100<=000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length *n* describing the rooms. The *i*-th character of the string will be '0' if the *i*-th roo...
Print the minimum possible distance between Farmer John's room and his farthest cow.
[ "7 2\n0100100\n", "5 1\n01010\n", "3 2\n000\n" ]
[ "2\n", "2\n", "1\n" ]
In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 f...
1,500
[ { "input": "7 2\n0100100", "output": "2" }, { "input": "5 1\n01010", "output": "2" }, { "input": "3 2\n000", "output": "1" }, { "input": "10 1\n1101111101", "output": "6" }, { "input": "2 1\n00", "output": "1" }, { "input": "3 1\n010", "output": "2...
1,691,544,707
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
46
0
n,k = list(map(int,input().split())) rooms = input() R = [] for i in range(len(rooms)): if rooms[i] == "0": R.append(i) l = 0 m = 1 r = k minDist = 100000 while r <= len(R) - 1: mid = (R[l] + R[r]) / 2 if R[m] >= mid: longDist = R[m] - R[l] else: longDist = R[r] - R[m] if lon...
Title: Enduring Exodus Time Limit: None seconds Memory Limit: None megabytes Problem Description: In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxuriou...
```python n,k = list(map(int,input().split())) rooms = input() R = [] for i in range(len(rooms)): if rooms[i] == "0": R.append(i) l = 0 m = 1 r = k minDist = 100000 while r <= len(R) - 1: mid = (R[l] + R[r]) / 2 if R[m] >= mid: longDist = R[m] - R[l] else: longDist = R[r] - R[m] ...
0
523
C
Name Quest
PROGRAMMING
1,400
[ "*special", "greedy" ]
null
null
A Martian boy is named *s* — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets hap...
The first line contains string *s*, consisting of lowercase English letters. The length of string *s* is from 1 to 1000 letters. The second line contains string *t*, that also consists of lowercase English letters. The length of string *t* is from 1 to 106 letters.
Print the sought number of ways to cut string *t* in two so that each part made *s* happy.
[ "aba\nbaobababbah\n", "mars\nsunvenusearthmarsjupitersaturnuranusneptune\n" ]
[ "2\n", "0\n" ]
none
1,500
[ { "input": "aba\nbaobababbah", "output": "2" }, { "input": "mars\nsunvenusearthmarsjupitersaturnuranusneptune", "output": "0" }, { "input": "rry\nsorrymercuryismissedabove", "output": "3" }, { "input": "a\naaaaaaaaaaaaaa", "output": "13" }, { "input": "abcaba\nabc...
1,426,362,235
17,035
Python 3
MEMORY_LIMIT_EXCEEDED
PRETESTS
6
265
268,390,400
s = str(input()) t = str(input()) def get_lowest(start, l): for el in l: if el > start: return el return False def find_name(v, s): letters = [] for l in s: letter = [] for x in range(len(v)): if l == v[x]: letter.appen...
Title: Name Quest Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Martian boy is named *s* — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by remo...
```python s = str(input()) t = str(input()) def get_lowest(start, l): for el in l: if el > start: return el return False def find_name(v, s): letters = [] for l in s: letter = [] for x in range(len(v)): if l == v[x]: le...
0
369
B
Valera and Contest
PROGRAMMING
1,400
[ "constructive algorithms", "implementation", "math" ]
null
null
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually. After the contest was over, Valer...
The first line of the input contains exactly six integers *n*,<=*k*,<=*l*,<=*r*,<=*s**all*,<=*s**k* (1<=≤<=*n*,<=*k*,<=*l*,<=*r*<=≤<=1000; *l*<=≤<=*r*; *k*<=≤<=*n*; 1<=≤<=*s**k*<=≤<=*s**all*<=≤<=106). It's guaranteed that the input is such that the answer exists.
Print exactly *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
[ "5 3 1 3 13 9\n", "5 3 1 3 15 9\n" ]
[ "2 3 2 3 3 ", "3 3 3 3 3 " ]
none
1,000
[ { "input": "5 3 1 3 13 9", "output": "2 3 2 3 3 " }, { "input": "5 3 1 3 15 9", "output": "3 3 3 3 3 " }, { "input": "50 25 1 1 50 25", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1000 700 782...
1,587,213,667
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
n,k,l,r,s,s1=[int(i) for i in input().split()] l2=[] l1=[] c=int(s1//k) while(len(l1)<k): l1.append(c) d=sum(l1) if(d==s1): pass else: while(d<s1): for i in range(0,len(l1)): l1[i]=l1[i]+1 d=d+1 d=n-k while(len(l2)<d): l2.append(l) e=sum(l2) if...
Title: Valera and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual c...
```python n,k,l,r,s,s1=[int(i) for i in input().split()] l2=[] l1=[] c=int(s1//k) while(len(l1)<k): l1.append(c) d=sum(l1) if(d==s1): pass else: while(d<s1): for i in range(0,len(l1)): l1[i]=l1[i]+1 d=d+1 d=n-k while(len(l2)<d): l2.append(l) e=s...
0
408
A
Line to Cashier
PROGRAMMING
900
[ "implementation" ]
null
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i*...
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
[ "1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n" ]
[ "20\n", "100\n" ]
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
500
[ { "input": "1\n1\n1", "output": "20" }, { "input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100" }, { "input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "output": "100" }, { "input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"...
1,587,757,966
2,147,483,647
Python 3
OK
TESTS
20
124
0
n=int(input()) l=list(map(int,input().split())) t=[] for i in range(n): k=list(map(int,input().split())) p=0 for i in k: p +=i*5 else: p +=15*(len(k)) t +=[p] else: print(min(t))
Title: Line to Cashier Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* c...
```python n=int(input()) l=list(map(int,input().split())) t=[] for i in range(n): k=list(map(int,input().split())) p=0 for i in k: p +=i*5 else: p +=15*(len(k)) t +=[p] else: print(min(t)) ```
3
789
B
Masha and geometric depression
PROGRAMMING
1,700
[ "brute force", "implementation", "math" ]
null
null
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=&gt;<=1 the respective term satisfi...
The first line of input contains four integers *b*1, *q*, *l*, *m* (-109<=≤<=*b*1,<=*q*<=≤<=109, 1<=≤<=*l*<=≤<=109, 1<=≤<=*m*<=≤<=105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second lin...
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
[ "3 2 30 4\n6 14 25 48\n", "123 1 2143435 4\n123 11 -5453 141245\n", "123 1 2143435 4\n54343 -13 6 124\n" ]
[ "3", "0", "inf" ]
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed *l* by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer....
1,000
[ { "input": "3 2 30 4\n6 14 25 48", "output": "3" }, { "input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0" }, { "input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf" }, { "input": "3 2 25 2\n379195692 -69874783", "output": "4" }, { "input": "3 2 3...
1,500,815,816
3,716
PyPy 3
RUNTIME_ERROR
TESTS
1
78
23,142,400
def ans(n): print(n) sys.exit() b1, q, l, m = map(int, input().split()) w = set(map(int, input().split())) inf = 'inf' #possiblity for answering inf if b1 == 0: if (0 in w): ans(inf) else: ans(0) # b1 != 0 if q == 0: if 0 not in w: ans(inf) e...
Title: Masha and geometric depression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric pro...
```python def ans(n): print(n) sys.exit() b1, q, l, m = map(int, input().split()) w = set(map(int, input().split())) inf = 'inf' #possiblity for answering inf if b1 == 0: if (0 in w): ans(inf) else: ans(0) # b1 != 0 if q == 0: if 0 not in w: ans(i...
-1
895
A
Pizza Separation
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
[ "4\n90 90 90 90\n", "3\n100 100 160\n", "1\n360\n", "4\n170 30 150 10\n" ]
[ "0\n", "40\n", "360\n", "0\n" ]
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Pety...
500
[ { "input": "4\n90 90 90 90", "output": "0" }, { "input": "3\n100 100 160", "output": "40" }, { "input": "1\n360", "output": "360" }, { "input": "4\n170 30 150 10", "output": "0" }, { "input": "5\n10 10 10 10 320", "output": "280" }, { "input": "8\n45 4...
1,511,712,779
479
PyPy 3
OK
TESTS
93
139
23,859,200
n = int(input()) best = 360 tab = list(map(int, input().split())) pre_sum = [0] for i in range(1, len(tab) + 1): pre_sum += [tab[i - 1] + pre_sum[-1]] for i in range(n + 1): for j in range(i, n + 1): best = min([best, 2 * abs(180 - (pre_sum[j] - pre_sum[i - 1]))]) print(best);
Title: Pizza Separation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut in...
```python n = int(input()) best = 360 tab = list(map(int, input().split())) pre_sum = [0] for i in range(1, len(tab) + 1): pre_sum += [tab[i - 1] + pre_sum[-1]] for i in range(n + 1): for j in range(i, n + 1): best = min([best, 2 * abs(180 - (pre_sum[j] - pre_sum[i - 1]))]) print(best); ```
3
450
B
Jzzhu and Sequences
PROGRAMMING
1,300
[ "implementation", "math" ]
null
null
Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7).
[ "2 3\n3\n", "0 -1\n2\n" ]
[ "1\n", "1000000006\n" ]
In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1. In the second sample, *f*<sub class="lower-index">2</sub> =  - 1;  - 1 modulo (10<sup class="upper-...
1,000
[ { "input": "2 3\n3", "output": "1" }, { "input": "0 -1\n2", "output": "1000000006" }, { "input": "-9 -11\n12345", "output": "1000000005" }, { "input": "0 0\n1000000000", "output": "0" }, { "input": "-1000000000 1000000000\n2000000000", "output": "1000000000" ...
1,646,111,788
2,147,483,647
PyPy 3-64
OK
TESTS
74
62
0
f1,f2 = map(int, input().split()) n = int(input()) md = 10**9+7 if ((n-1)//3)%2==0: ans = ([f1, f2, f2-f1][(n-1)%3])%md else: ans = ([-f1, -f2, f1-f2][(n-1)%3])%md print(ans)
Title: Jzzhu and Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). Input Specification: The first line contains two integers...
```python f1,f2 = map(int, input().split()) n = int(input()) md = 10**9+7 if ((n-1)//3)%2==0: ans = ([f1, f2, f2-f1][(n-1)%3])%md else: ans = ([-f1, -f2, f1-f2][(n-1)%3])%md print(ans) ```
3
215
A
Bicycle Chain
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o...
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
[ "2\n4 5\n3\n12 13 15\n", "4\n1 2 3 4\n5\n10 11 12 13 14\n" ]
[ "2\n", "1\n" ]
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
500
[ { "input": "2\n4 5\n3\n12 13 15", "output": "2" }, { "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 2\n1\n1", "output": "1" }, { "input": "1\n1\n2\n1 2", "output": "1" }, { "input":...
1,591,781,582
2,147,483,647
PyPy 3
OK
TESTS
57
280
1,331,200
# cook your dish here n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) count=0 m =0 mylist = [] for i in a: for j in b: if j%i==0: c = j/i mylist.append(c) m = max(mylist) count = mylist.count(m) print(count)
Title: Bicycle Chain Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We ...
```python # cook your dish here n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) count=0 m =0 mylist = [] for i in a: for j in b: if j%i==0: c = j/i mylist.append(c) m = max(mylist) count = mylist.count(m) print(...
3
426
B
Sereja and Mirroring
PROGRAMMING
1,300
[ "implementation" ]
null
null
Let's assume that we are given a matrix *b* of size *x*<=×<=*y*, let's determine the operation of mirroring matrix *b*. The mirroring of matrix *b* is a 2*x*<=×<=*y* matrix *c* which has the following properties: - the upper half of matrix *c* (rows with numbers from 1 to *x*) exactly matches *b*; - the lower half o...
The first line contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains *m* integers — the elements of matrix *a*. The *i*-th line contains integers *a**i*1,<=*a**i*2,<=...,<=*a**im* (0<=≤<=*a**ij*<=≤<=1) — the *i*-th row of the matrix *a*.
In the single line, print the answer to the problem — the minimum number of rows of matrix *b*.
[ "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1\n", "3 3\n0 0 0\n0 0 0\n0 0 0\n", "8 1\n0\n1\n1\n0\n0\n1\n1\n0\n" ]
[ "2\n", "3\n", "2\n" ]
In the first test sample the answer is a 2 × 3 matrix *b*: If we perform a mirroring operation with this matrix, we get the matrix *a* that is given in the input:
1,000
[ { "input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3" }, { "input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2" }, { "input": "10 4\n0 0 1 0\n0 0 1 0\n1 1 0 1\n0 0 1 1\n1 0 1 0\n1 0 1 0\n0 0 1 1\n1 1 0 1\n0 0 1 0\...
1,620,296,595
2,147,483,647
PyPy 3
OK
TESTS
65
124
21,606,400
def issymmetric(n, mat): if n%2: return False else: return mat[:n//2] == mat[n//2:][::-1] n, m = map(int, input().split()) mat = [] for i in range(n): mat.append(list(map(int, input().split()))) #print(n, mat) while issymmetric(n, mat): mat = mat[:n//2] n //= 2 print(n)
Title: Sereja and Mirroring Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's assume that we are given a matrix *b* of size *x*<=×<=*y*, let's determine the operation of mirroring matrix *b*. The mirroring of matrix *b* is a 2*x*<=×<=*y* matrix *c* which has the following properties: ...
```python def issymmetric(n, mat): if n%2: return False else: return mat[:n//2] == mat[n//2:][::-1] n, m = map(int, input().split()) mat = [] for i in range(n): mat.append(list(map(int, input().split()))) #print(n, mat) while issymmetric(n, mat): mat = mat[:n//2] n //= 2 print(...
3
916
A
Jamie and Alarm Snooze
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He ...
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60). The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59).
Print the minimum number of times he needs to press the button.
[ "3\n11 23\n", "5\n01 07\n" ]
[ "2\n", "0\n" ]
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
500
[ { "input": "3\n11 23", "output": "2" }, { "input": "5\n01 07", "output": "0" }, { "input": "34\n09 24", "output": "3" }, { "input": "2\n14 37", "output": "0" }, { "input": "14\n19 54", "output": "9" }, { "input": "42\n15 44", "output": "12" }, ...
1,632,191,461
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
140
20,172,800
n = int(input()) time = input().split() if '7' in time[0] or '7' in time[1]: ans = 0 else: x, ans, y = int(time[1]), 0, int(time[0]) while '7' not in str(x) and '7' not in str(y): if x > n: x -= n ans += 1 if x <= n: y -= 1 diff = x...
Title: Jamie and Alarm Snooze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will the...
```python n = int(input()) time = input().split() if '7' in time[0] or '7' in time[1]: ans = 0 else: x, ans, y = int(time[1]), 0, int(time[0]) while '7' not in str(x) and '7' not in str(y): if x > n: x -= n ans += 1 if x <= n: y -= 1 ...
0
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s...
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch...
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,579,578,805
2,147,483,647
Python 3
OK
TESTS
26
108
307,200
n,d=[int(x) for x in input().split()] t=[int(x) for x in input().split()] summ=sum(t)+(n-1)*10 if summ>d: print(-1) else: print((n-1)*2+(d-summ)//5)
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit...
```python n,d=[int(x) for x in input().split()] t=[int(x) for x in input().split()] summ=sum(t)+(n-1)*10 if summ>d: print(-1) else: print((n-1)*2+(d-summ)//5) ```
3
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10...
1,669,771,069
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
0
def checkPerf(k): ds=[int(ch) for ch in str(k)] if(sum(ds)==10): return True return False cnt=0 i=0 n=int(input()) while True: i+=1 if(checkPerf(i)): cnt+=1 if(cnt==n): print(i) break
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A singl...
```python def checkPerf(k): ds=[int(ch) for ch in str(k)] if(sum(ds)==10): return True return False cnt=0 i=0 n=int(input()) while True: i+=1 if(checkPerf(i)): cnt+=1 if(cnt==n): print(i) break ```
0
812
A
Sagheer and Crossroads
PROGRAMMING
1,200
[ "implementation" ]
null
null
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane...
The input consists of four lines with each line describing a road part given in a counter-clockwise order. Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
[ "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4. In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.
500
[ { "input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1", "output": "YES" }, { "input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1", "output": "NO" }, { "input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0", "output": "NO" }, { "input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1", "output": "NO" }, ...
1,592,865,393
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
93
6,963,200
class block: def __init__(self, l,s,r,p,no): self.id=no self.l = l self.s = s self.r = r self.p =p self.opposite=(no+2)%4 self.right=(no+1)%4 self.left=(no-1)%4 self.attacking=[] if(l): self.attacking.append(self...
Title: Sagheer and Crossroads Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l...
```python class block: def __init__(self, l,s,r,p,no): self.id=no self.l = l self.s = s self.r = r self.p =p self.opposite=(no+2)%4 self.right=(no+1)%4 self.left=(no-1)%4 self.attacking=[] if(l): self.attacking.a...
0
0
none
none
none
0
[ "none" ]
null
null
This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two d...
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu...
[ "yes\nno\nyes\n", "no\nyes\nno\nno\nno\n" ]
[ "2\n80\n5\ncomposite\n", "58\n59\n78\n78\n2\nprime\n" ]
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/> The hi...
0
[ { "input": "30", "output": "composite 4" }, { "input": "59", "output": "prime 15" }, { "input": "2", "output": "prime 16" }, { "input": "7", "output": "prime 16" }, { "input": "9", "output": "composite 3" }, { "input": "13", "output": "prime 15" ...
1,686,442,617
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
46
0
v=[] c=0 flag=False for i in range(2,10): v+=[i] for j in v: print(j,flush=True) if input()=="yes": c+=1 if c >=2: print("composite") else: print("prime")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden n...
```python v=[] c=0 flag=False for i in range(2,10): v+=[i] for j in v: print(j,flush=True) if input()=="yes": c+=1 if c >=2: print("composite") else: print("prime") ```
0
886
A
ACM ICPC
PROGRAMMING
1,000
[ "brute force" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. ...
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
500
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { ...
1,653,604,300
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
46
0
from sys import exit a=list(map(int,input().split())) a=sorted(a) sum=0 for i in a: sum=sum+i half=sum/2 half=half-a[-1] a.pop(-1) for i in a: x=a.pop(i) rest=half-x if rest in a: print("YES") exit() a.insert(i, x) print("NO")
Title: ACM ICPC Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build ...
```python from sys import exit a=list(map(int,input().split())) a=sorted(a) sum=0 for i in a: sum=sum+i half=sum/2 half=half-a[-1] a.pop(-1) for i in a: x=a.pop(i) rest=half-x if rest in a: print("YES") exit() a.insert(i, x) print("NO") ```
-1
1,008
A
Romaji
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).
[ "sumimasen\n", "ninja\n", "codeforces\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
500
[ { "input": "sumimasen", "output": "YES" }, { "input": "ninja", "output": "YES" }, { "input": "codeforces", "output": "NO" }, { "input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "output": "YES" }, { "in...
1,637,775,221
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n=input() l=len(n) for i in range(l): if n(i) not in "a,e,i,o,u,n" and n(i+1) not in "a,e,i,o,u": print(no) else: print(yes)
Title: Romaji Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after eve...
```python n=input() l=len(n) for i in range(l): if n(i) not in "a,e,i,o,u,n" and n(i+1) not in "a,e,i,o,u": print(no) else: print(yes) ```
-1
812
A
Sagheer and Crossroads
PROGRAMMING
1,200
[ "implementation" ]
null
null
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane...
The input consists of four lines with each line describing a road part given in a counter-clockwise order. Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
[ "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4. In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.
500
[ { "input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1", "output": "YES" }, { "input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1", "output": "NO" }, { "input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0", "output": "NO" }, { "input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1", "output": "NO" }, ...
1,622,270,113
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
124
2,355,200
import sys import string from collections import Counter, defaultdict from math import fsum, sqrt, gcd, ceil, factorial from operator import * from itertools import accumulate inf = float("inf") # input = sys.stdin.readline flush = lambda: sys.stdout.flush comb = lambda x, y: (factorial(x) // factorial(y))...
Title: Sagheer and Crossroads Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l...
```python import sys import string from collections import Counter, defaultdict from math import fsum, sqrt, gcd, ceil, factorial from operator import * from itertools import accumulate inf = float("inf") # input = sys.stdin.readline flush = lambda: sys.stdout.flush comb = lambda x, y: (factorial(x) // fac...
0
690
E1
Photographs (I)
PROGRAMMING
1,800
[]
null
null
The Human-Cow Confederation (*HC*2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves ...
The first line of the input contains the number *q* of questions (1<=≤<=*q*<=≤<=220). After that, *q* questions follow, each of which in the format described below. The first line of every question contains two space-separated integers *h* and *w* (1<=≤<=*h*,<=*w*<=≤<=600) – the height (number of rows) and width (numb...
Your program should print *q* lines. The *i*-th line should contain your answer for the *i*-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct. Because the input is rather huge, feel free to p...
[]
[]
The link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip
0
[]
1,490,350,123
2,147,483,647
Python 3
OK
TESTS
1
46
4,915,200
for x in ['YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES', 'YES', 'Y...
Title: Photographs (I) Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Human-Cow Confederation (*HC*2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turi...
```python for x in ['YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'NO', 'NO', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES',...
3
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,680,878,603
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
def binary_gcd(a, b): if a == 0: return b elif b == 0: return a elif a == b: return a elif a % 2 == 0 and b % 2 == 0: return 2 * binary_gcd(a // 2, b // 2) elif a % 2 == 0: return binary_gcd(a // 2, b) elif b % 2 == 0: return binary_gcd...
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi...
```python def binary_gcd(a, b): if a == 0: return b elif b == 0: return a elif a == b: return a elif a % 2 == 0 and b % 2 == 0: return 2 * binary_gcd(a // 2, b // 2) elif a % 2 == 0: return binary_gcd(a // 2, b) elif b % 2 == 0: return ...
-1
74
A
Room Leader
PROGRAMMING
1,000
[ "implementation" ]
A. Room Leader
2
256
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document. In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five prob...
The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number o...
Print on the single line the handle of the room leader.
[ "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n" ]
[ "tourist" ]
The number of points that each participant from the example earns, are as follows: - Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R —  - 350 - some_participant — 2220 Thus, the leader of the room is tourist.
500
[ { "input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0", "output": "tourist" }, { "input": "1\nA 0 0 200 0 0 0 0", "output": "A" }, { "input": "2\n12345678901234567890 1 0...
1,616,882,421
2,147,483,647
Python 3
OK
TESTS
32
124
307,200
total_contestants = int(input()) final_scores = {} for _ in range(total_contestants): handle, successful_hacks, unsuccessful_hacks, *problem_values = input().split() successful_hacks = int(successful_hacks) unsuccessful_hacks = int(unsuccessful_hacks) final_scores[handle] = (successful_hacks * 10...
Title: Room Leader Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document. In the beginning of the round the contestants are divided into rooms. Each room contains e...
```python total_contestants = int(input()) final_scores = {} for _ in range(total_contestants): handle, successful_hacks, unsuccessful_hacks, *problem_values = input().split() successful_hacks = int(successful_hacks) unsuccessful_hacks = int(unsuccessful_hacks) final_scores[handle] = (successful_...
3.968428
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul...
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter t...
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input":...
1,585,102,482
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
216
307,200
L = list() for i in range(3): L.append(input()) if L[0][1] == L[1][1] and L[1][1] == L[2][1]: print("Impossible") exit(0) L1 = list() for ch in L: if ch[1] == ">": L1.append(ch[2]+"<"+ch[0]) else: L1.append(ch) result = "" if L1[0][0] == L1[1][0] or L1[0][0] == L1[2][0]:...
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ...
```python L = list() for i in range(3): L.append(input()) if L[0][1] == L[1][1] and L[1][1] == L[2][1]: print("Impossible") exit(0) L1 = list() for ch in L: if ch[1] == ">": L1.append(ch[2]+"<"+ch[0]) else: L1.append(ch) result = "" if L1[0][0] == L1[1][0] or L1[0][0] ==...
-1
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od...
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t...
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617...
1,680,260,776
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
n = input().split() k = input().split() a = [] l = [] for i in range(len(k)-int(n[0])+1): for j in range(int(n[0])): a.append(int(k[i+j])) l.append(max(a)-min(a)) a = [] print(min(l))
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a...
```python n = input().split() k = input().split() a = [] l = [] for i in range(len(k)-int(n[0])+1): for j in range(int(n[0])): a.append(int(k[i+j])) l.append(max(a)-min(a)) a = [] print(min(l)) ```
0
811
A
Vladik and Courtesy
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving eac...
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
[ "1 1\n", "7 6\n" ]
[ "Valera\n", "Vladik\n" ]
Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e...
500
[ { "input": "1 1", "output": "Valera" }, { "input": "7 6", "output": "Vladik" }, { "input": "25 38", "output": "Vladik" }, { "input": "8311 2468", "output": "Valera" }, { "input": "250708 857756", "output": "Vladik" }, { "input": "957985574 24997558", ...
1,495,879,503
1,803
Python 3
WRONG_ANSWER
PRETESTS
4
62
0
def winner(a, b): a_c = 1 b_c = 2 for i in range(a + b): a -= a_c b -= b_c if a<0 or b<0: break a_c += 2 b_c += 2 if a<0 and b<0: return "Vladik" else: return "Valera" if __name__ == '__main__': a, b = map(int...
Title: Vladik and Courtesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla...
```python def winner(a, b): a_c = 1 b_c = 2 for i in range(a + b): a -= a_c b -= b_c if a<0 or b<0: break a_c += 2 b_c += 2 if a<0 and b<0: return "Vladik" else: return "Valera" if __name__ == '__main__': a, b...
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,679,183,576
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = input() n = int(n) temp = 0 arr = [] result = [] i = 0 while i < n: temp = input() arr.insert(i, temp) i = i + 1 i = 0 while i < n: temp = arr[i] if len(temp) > 10: newStr = temp[0] + str(len(temp)) + temp[len(temp)-1] else: newStr = temp result.insert(i,...
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 n = input() n = int(n) temp = 0 arr = [] result = [] i = 0 while i < n: temp = input() arr.insert(i, temp) i = i + 1 i = 0 while i < n: temp = arr[i] if len(temp) > 10: newStr = temp[0] + str(len(temp)) + temp[len(temp)-1] else: newStr = temp result...
0
599
C
Day at the Beach
PROGRAMMING
1,600
[ "sortings" ]
null
null
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the day there were *n* castles built by friends. Castles are numbered from 1 to *n*, and the ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day. The next line contains *n* integers *h**i* (1<=≤<=*h**i*<=≤<=109). The *i*-th of these integers corresponds to the height of the *i*-th castle.
Print the maximum possible number of blocks in a valid partitioning.
[ "3\n1 2 3\n", "4\n2 1 3 2\n" ]
[ "3\n", "2\n" ]
In the first sample the partitioning looks like that: [1][2][3]. In the second sample the partitioning is: [2, 1][3, 2]
1,500
[ { "input": "3\n1 2 3", "output": "3" }, { "input": "4\n2 1 3 2", "output": "2" }, { "input": "17\n1 45 22 39 28 23 23 100 500 778 777 778 1001 1002 1005 1003 1005", "output": "10" }, { "input": "101\n1 50 170 148 214 153 132 234 181 188 180 225 226 200 197 122 181 168 87 220 ...
1,658,894,851
2,147,483,647
PyPy 3-64
OK
TESTS
39
171
20,992,000
from collections import Counter n=int(input()) arr=list(map(int,input().split())) p=sorted(arr) ans=0 c=Counter() seen=set() for a,b in zip(arr,p): c[a]+=1 c[b]-=1 if c[a]>0: seen.add(a) if c[a]==0 and a in seen: seen.remove(a) if c[b]>0: seen.add(b) if c[...
Title: Day at the Beach Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At th...
```python from collections import Counter n=int(input()) arr=list(map(int,input().split())) p=sorted(arr) ans=0 c=Counter() seen=set() for a,b in zip(arr,p): c[a]+=1 c[b]-=1 if c[a]>0: seen.add(a) if c[a]==0 and a in seen: seen.remove(a) if c[b]>0: seen.add(b) ...
3
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is ...
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m...
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", ...
1,693,933,375
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
31
0
first_stroke = input()[::-1] second_stroke = input()[::-1] sums_stoke = sum([len(first_stroke), len(second_stroke)]) for i in range(max(len(first_stroke), len(second_stroke))): if first_stroke[i] == second_stroke[i]: if i == min(len(first_stroke), len(second_stroke)) - 1: print(sums_stoke - (i ...
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ...
```python first_stroke = input()[::-1] second_stroke = input()[::-1] sums_stoke = sum([len(first_stroke), len(second_stroke)]) for i in range(max(len(first_stroke), len(second_stroke))): if first_stroke[i] == second_stroke[i]: if i == min(len(first_stroke), len(second_stroke)) - 1: print(sums_s...
-1
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ...
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#...
1,696,872,419
2,147,483,647
Python 3
OK
TESTS
28
46
102,400
n,m=map(int,input().split()) a=[] for i in range(n): b=[] for j in range(m): b.append('.') a.append(b) for i in range(m): a[0][i]='#' def right(): global row a[row][m-1]='#' row+=1 for i in range(m): a[row][i]='#' row+=1 def left(): global row ...
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*...
```python n,m=map(int,input().split()) a=[] for i in range(n): b=[] for j in range(m): b.append('.') a.append(b) for i in range(m): a[0][i]='#' def right(): global row a[row][m-1]='#' row+=1 for i in range(m): a[row][i]='#' row+=1 def left(): gl...
3
27
E
Number With The Given Amount Of Divisors
PROGRAMMING
2,000
[ "brute force", "dp", "number theory" ]
E. Number With The Given Amount Of Divisors
2
256
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000).
Output the smallest positive integer with exactly *n* divisors.
[ "4\n", "6\n" ]
[ "6\n", "12\n" ]
none
2,500
[ { "input": "1", "output": "1" }, { "input": "7", "output": "64" }, { "input": "8", "output": "24" }, { "input": "9", "output": "36" }, { "input": "10", "output": "48" }, { "input": "15", "output": "144" }, { "input": "20", "output": "24...
1,691,314,239
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> #define int long long #define mod 1000000007 #define test freopen("1.txt","r",stdin); #define endl "\n" #define ff first #define ss second using namespace std; int MAXV=2e18; vector<int>primes={2,3,5,7,11,13,17,19,23,29,31,37,41}; int f(int num,int factors,int i,int n){ if(factors==n){ ret...
Title: Number With The Given Amount Of Divisors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. Input Specification: The first line...
```python #include<bits/stdc++.h> #define int long long #define mod 1000000007 #define test freopen("1.txt","r",stdin); #define endl "\n" #define ff first #define ss second using namespace std; int MAXV=2e18; vector<int>primes={2,3,5,7,11,13,17,19,23,29,31,37,41}; int f(int num,int factors,int i,int n){ if(factors==n...
-1
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean...
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ...
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "outp...
1,680,886,088
2,147,483,647
PyPy 3
OK
TESTS
31
77
0
l = "qwertyuiopasdfghjkl;zxcvbnm,./" x = input() s = input() y = "" for i in range(len(s)): if x == 'L': if s[i] not in ('p', ';', '/'): y = y + l[l.index(s[i]) + 1] else: y = y + s[i] else: if s[i] not in ('q', 'a', 'z'): y = y + l[l.index(s[i]) - 1] else: y = y + s[i] pri...
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately....
```python l = "qwertyuiopasdfghjkl;zxcvbnm,./" x = input() s = input() y = "" for i in range(len(s)): if x == 'L': if s[i] not in ('p', ';', '/'): y = y + l[l.index(s[i]) + 1] else: y = y + s[i] else: if s[i] not in ('q', 'a', 'z'): y = y + l[l.index(s[i]) - 1] else: y = y + s[i]...
3
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 58697...
1,685,195,036
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
92
0
def horseshoe(data): y = data.split() count = 0 for i in range(len(y) - 1): if y[i + 1] == y[i]: count += 1 return count print(horseshoe(input()))
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ...
```python def horseshoe(data): y = data.split() count = 0 for i in range(len(y) - 1): if y[i + 1] == y[i]: count += 1 return count print(horseshoe(input())) ```
0
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,593,990,750
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
20,172,800
from sys import stdin, stdout def stdinhack(): for line in stdin: yield line next_line = lambda: next(stdinhack()).split() write = lambda x : stdout.write(x) def solve (): x, y = map(int, next_line()) if x>0 and y>0: print(0, x+y, x+y,0) if x<0 and y>0: print(x-y, 0, 0, -x+y) if x>0 and y<0: print(...
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 from sys import stdin, stdout def stdinhack(): for line in stdin: yield line next_line = lambda: next(stdinhack()).split() write = lambda x : stdout.write(x) def solve (): x, y = map(int, next_line()) if x>0 and y>0: print(0, x+y, x+y,0) if x<0 and y>0: print(x-y, 0, 0, -x+y) if x>0 and y...
0
0
none
none
none
0
[ "none" ]
null
null
An atom of element X can exist in *n* distinct states with energies *E*1<=&lt;<=*E*2<=&lt;<=...<=&lt;<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states *i*, *j* and *k* are selected, where *i*<=&lt;<=*j*<=&lt;<=*k*...
The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*. The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=&lt;<=*E*2...<=&lt;<=*E**n*<=≤<=109). It is guaranteed th...
If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9. Formally, let your answer be *a*, and the jury's answe...
[ "4 4\n1 3 5 7\n", "10 8\n10 13 15 16 17 19 20 22 24 25\n", "3 1\n2 5 10\n" ]
[ "0.5\n", "0.875\n", "-1\n" ]
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example choose states 4, 5 a...
0
[ { "input": "4 4\n1 3 5 7", "output": "0.5" }, { "input": "10 8\n10 13 15 16 17 19 20 22 24 25", "output": "0.875" }, { "input": "3 1\n2 5 10", "output": "-1" }, { "input": "5 3\n4 6 8 9 10", "output": "0.5" }, { "input": "10 128\n110 121 140 158 174 188 251 271 27...
1,553,631,047
3,347
PyPy 3
WRONG_ANSWER
TESTS
21
187
11,264,000
n,u=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() j,i=1,0 maxi=-1 while(i<n-1): while(1): if j>=n or arr[j]-arr[i]>u: j-=1 break j+=1 if arr[j]-arr[i]<=u and j!=i: maxi=max(maxi,(arr[j]-arr[i+1])/(arr[j]-arr[i])) if i==j: j+=1 i+=1 print(maxi)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: An atom of element X can exist in *n* distinct states with energies *E*1<=&lt;<=*E*2<=&lt;<=...<=&lt;<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the sche...
```python n,u=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() j,i=1,0 maxi=-1 while(i<n-1): while(1): if j>=n or arr[j]-arr[i]>u: j-=1 break j+=1 if arr[j]-arr[i]<=u and j!=i: maxi=max(maxi,(arr[j]-arr[i+1])/(arr[j]-arr[i])) if i==j: j+=1 i+=1 print(maxi) ```
0
845
B
Luba And The Ticket
PROGRAMMING
1,600
[ "brute force", "greedy", "implementation" ]
null
null
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of las...
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
[ "000000\n", "123456\n", "111000\n" ]
[ "0\n", "2\n", "1\n" ]
In the first example the ticket is already lucky, so the answer is 0. In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required. In the third example Luba can replace any zero with 3. It's easy to see that at least one re...
0
[ { "input": "000000", "output": "0" }, { "input": "123456", "output": "2" }, { "input": "111000", "output": "1" }, { "input": "120111", "output": "0" }, { "input": "999999", "output": "0" }, { "input": "199880", "output": "1" }, { "input": "...
1,503,373,427
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
wow = [0]*6 j = 0 rub = input() for i in rub: wow[j] = int(i) j += 1 a1 = [wow[0],wow[1],wow[2]] a2 = [wow[3],wow[4],wow[5]] sum1 = sum(a1) sum2 = sum(a2) if(sum1 < sum2): noisud = min(a1) maksud = max(a2) pontang = sum2-sum1 if(sum2 < sum1): noisud = min(a2) maksud...
Title: Luba And The Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th...
```python wow = [0]*6 j = 0 rub = input() for i in rub: wow[j] = int(i) j += 1 a1 = [wow[0],wow[1],wow[2]] a2 = [wow[3],wow[4],wow[5]] sum1 = sum(a1) sum2 = sum(a2) if(sum1 < sum2): noisud = min(a1) maksud = max(a2) pontang = sum2-sum1 if(sum2 < sum1): noisud = min(a2) ...
-1
448
B
Suffix Structures
PROGRAMMING
1,400
[ "implementation", "strings" ]
null
null
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know th...
The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without th...
[ "automaton\ntomat\n", "array\narary\n", "both\nhot\n", "need\ntree\n" ]
[ "automaton\n", "array\n", "both\n", "need tree\n" ]
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".
1,000
[ { "input": "automaton\ntomat", "output": "automaton" }, { "input": "array\narary", "output": "array" }, { "input": "both\nhot", "output": "both" }, { "input": "need\ntree", "output": "need tree" }, { "input": "abacaba\naaaa", "output": "automaton" }, { ...
1,647,207,074
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
s = input() t = input() if t in s: print("automaton") else: s_freqs = {} for c in s: if c not in s_freqs: s_freqs[c] = 0 s_freqs[c] += 1 t_freqs = {} for c in t: if c not in t_freqs: t_freqs[c] = 0 t_freqs[c] += 1 if s_freqs ...
Title: Suffix Structures Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*....
```python s = input() t = input() if t in s: print("automaton") else: s_freqs = {} for c in s: if c not in s_freqs: s_freqs[c] = 0 s_freqs[c] += 1 t_freqs = {} for c in t: if c not in t_freqs: t_freqs[c] = 0 t_freqs[c] += 1 i...
0
963
A
Alternating Sum
PROGRAMMING
1,800
[ "math", "number theory" ]
null
null
You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$. Find out the non-negative ...
The first line contains four integers $n, a, b$ and $k$ $(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$. The second line contains a sequence of length $k$ consisting of characters '+' and '-'. If the $i$-th character (0-indexed) is '+', then $s_{i} = 1$, otherwise $s_{i} = -1$. Note that onl...
Output a single integer — value of given expression modulo $10^{9} + 9$.
[ "2 2 3 3\n+-+\n", "4 1 5 1\n-\n" ]
[ "7\n", "999999228\n" ]
In the first example: $(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$ = $2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$ = 7 In the second example: $(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$.
500
[ { "input": "2 2 3 3\n+-+", "output": "7" }, { "input": "4 1 5 1\n-", "output": "999999228" }, { "input": "1 1 4 2\n-+", "output": "3" }, { "input": "3 1 4 4\n+--+", "output": "45" }, { "input": "5 1 1 6\n++---+", "output": "0" }, { "input": "5 2 2 6\n+...
1,589,705,075
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
23,040,000
q=10**9+9 n,a,b,k=map(int,input().split()) s=input() result=0 for i in range(n+1): c=(a**(n-i))%q d=(b**i)%q e=[1,-1][s[i%k]=='-'] result+=(c*d*e) print(result%q)
Title: Alternating Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other w...
```python q=10**9+9 n,a,b,k=map(int,input().split()) s=input() result=0 for i in range(n+1): c=(a**(n-i))%q d=(b**i)%q e=[1,-1][s[i%k]=='-'] result+=(c*d*e) print(result%q) ```
0
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", ...
1,618,637,795
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
n = int(input()) s = input() li = [] count = 0 for i in s: if i=='B': count+=1 else: if count!=0: li.append(count) count =0 if len(li)!=0: print(len(li)) print(*li) else: print(len(li))
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the...
```python n = int(input()) s = input() li = [] count = 0 for i in s: if i=='B': count+=1 else: if count!=0: li.append(count) count =0 if len(li)!=0: print(len(li)) print(*li) else: print(len(li)) ```
0
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,687,861,171
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
m,s = map(int,input().split()) mn = 10**(m-1) mx = str((10**m )-1) if s>=1 and s<=len(mx)*9: num = '' if s<10: mxim = int(str(s) + '0'*(m-1)) minm = int(str(1) + '0'*(m-2) + str(s-1)) else: n = s//9 l = s%9 if l != 0: mxim = int('9'*n + str(l...
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python m,s = map(int,input().split()) mn = 10**(m-1) mx = str((10**m )-1) if s>=1 and s<=len(mx)*9: num = '' if s<10: mxim = int(str(s) + '0'*(m-1)) minm = int(str(1) + '0'*(m-2) + str(s-1)) else: n = s//9 l = s%9 if l != 0: mxim = int('9'...
0
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,689,069,194
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
a=map(int,input().split()) b=list(set(a)) c=len(b) print(c)
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python a=map(int,input().split()) b=list(set(a)) c=len(b) print(c) ```
-1
177
A1
Good Matrix Elements
PROGRAMMING
800
[ "implementation" ]
null
null
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which ha...
The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 po...
Print a single integer — the sum of good matrix elements.
[ "3\n1 2 3\n4 5 6\n7 8 9\n", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n" ]
[ "45\n", "17\n" ]
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
30
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "45" }, { "input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "output": "17" }, { "input": "1\n3", "output": "3" }, { "input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33", ...
1,549,573,414
2,147,483,647
Python 3
OK
TESTS1
17
248
0
x=int(input()) z=0;s=0;l=(x-1) for i in range(x): y=input().split() if i<((x//2)-1) : z+=int(y[s])+int(y[l])+int(y[x//2]) s+=1;l-=1 elif i==((x//2)-1) : z += int(y[s]) + int(y[l]) + int(y[x // 2]) elif i ==(x//2): for r in range(x): z+=int(y[r]) ...
Title: Good Matrix Elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the ...
```python x=int(input()) z=0;s=0;l=(x-1) for i in range(x): y=input().split() if i<((x//2)-1) : z+=int(y[s])+int(y[l])+int(y[x//2]) s+=1;l-=1 elif i==((x//2)-1) : z += int(y[s]) + int(y[l]) + int(y[x // 2]) elif i ==(x//2): for r in range(x): z+=int...
3
754
B
Ilya and tic-tac-toe game
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by maki...
The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it mea...
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
[ "xx..\n.oo.\nx...\noox.\n", "x.ox\nox..\nx.o.\noo.x\n", "x..x\n..oo\no...\nx.xo\n", "o.x.\no...\n.x..\nooxx\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row. In the second example it wasn't possible to win by making single turn. In the third example Ilya could have won by placing X in the last row between two existing Xs. In the fourth ex...
1,000
[ { "input": "xx..\n.oo.\nx...\noox.", "output": "YES" }, { "input": "x.ox\nox..\nx.o.\noo.x", "output": "NO" }, { "input": "x..x\n..oo\no...\nx.xo", "output": "YES" }, { "input": "o.x.\no...\n.x..\nooxx", "output": "NO" }, { "input": ".xox\no.x.\nx.o.\n..o.", "...
1,607,637,443
2,147,483,647
PyPy 3
OK
TESTS
95
155
0
s=[] for i in range(4): s1=input() s.append(s1) a=set() for i in range(4): s1=s[i][0:3] s2=s[i][1:4] s3=s[0][i]+s[1][i]+s[2][i] s4=s[1][i]+s[2][i]+s[3][i] a.add(s1) a.add(s2) a.add(s3) a.add(s4) for i in range(0,2): for j in range(2): a.add(s[i][j]+s...
Title: Ilya and tic-tac-toe game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last...
```python s=[] for i in range(4): s1=input() s.append(s1) a=set() for i in range(4): s1=s[i][0:3] s2=s[i][1:4] s3=s[0][i]+s[1][i]+s[2][i] s4=s[1][i]+s[2][i]+s[3][i] a.add(s1) a.add(s2) a.add(s3) a.add(s4) for i in range(0,2): for j in range(2): a.add...
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,669,581,455
2,147,483,647
Python 3
OK
TESTS
34
46
0
card = int(input('')) arr = list(map(int,input().split(' '))) khaled = 0 yahya = 0 start = 0 end = card -1 winner = 1 while card != 0 : result = 0 card -=1 if arr[start] > arr[end]: result = arr[start] start = start +1 else : result = arr[end] end = end - 1 if wi...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python card = int(input('')) arr = list(map(int,input().split(' '))) khaled = 0 yahya = 0 start = 0 end = card -1 winner = 1 while card != 0 : result = 0 card -=1 if arr[start] > arr[end]: result = arr[start] start = start +1 else : result = arr[end] end = end - 1...
3
821
C
Okabe and Boxes
PROGRAMMING
1,500
[ "data structures", "greedy", "trees" ]
null
null
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the sta...
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes. Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of...
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
[ "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n" ]
[ "1\n", "2\n" ]
In the first sample, Daru should reorder the boxes after adding box 3 to the stack. In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
1,500
[ { "input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "output": "1" }, { "input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove", "output": "2" }, { "input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremov...
1,596,410,483
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
8
3,000
30,924,800
n = int(input()) stack = [] nxt = 1 ans = 0 l = 0 for _ in range(2*n): cmd = input() if cmd[:3] == "add": _,b = cmd.split() b = int(b) stack.append(b) else: if not stack: nxt += 1;continue if stack.pop() == nxt: nxt += 1 else: ...
Title: Okabe and Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which a...
```python n = int(input()) stack = [] nxt = 1 ans = 0 l = 0 for _ in range(2*n): cmd = input() if cmd[:3] == "add": _,b = cmd.split() b = int(b) stack.append(b) else: if not stack: nxt += 1;continue if stack.pop() == nxt: nxt += 1 el...
0
0
none
none
none
0
[ "none" ]
null
null
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters.
On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes. Print suffixes in lexicographical (alphabetical) order.
[ "abacabaca\n", "abaca\n" ]
[ "3\naca\nba\nca\n", "0\n" ]
The first test was analysed in the problem statement. In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
0
[ { "input": "abacabaca", "output": "3\naca\nba\nca" }, { "input": "abaca", "output": "0" }, { "input": "gzqgchv", "output": "1\nhv" }, { "input": "iosdwvzerqfi", "output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer" }, { "input": "oawtxikrpvfuzugjweki", "output...
1,462,480,198
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
62
4,608,000
def solve(data): n=len(data) res=[] if n<=6: return 0 else: for i in range(5,n-2,1): if (i != n-3): res.append(data[i:i+2]) if (i != n-4): res.append(data[i:i+3]) res.append(data[-2:]) res = sorted(list(set(r...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in differ...
```python def solve(data): n=len(data) res=[] if n<=6: return 0 else: for i in range(5,n-2,1): if (i != n-3): res.append(data[i:i+2]) if (i != n-4): res.append(data[i:i+3]) res.append(data[-2:]) res = sorted(...
-1
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,609,182,175
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
108
0
n = input() h1 = n.find("h") e1 = n.find("e") l1 = n.find("ll") o1 = n.find("o") if h1 != -1 and e1 != -1 and l1 !=0 and o1 != -1: if h1 < e1 and e1 < l1 and l1 < o1: print("YES") exit(0) print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python n = input() h1 = n.find("h") e1 = n.find("e") l1 = n.find("ll") o1 = n.find("o") if h1 != -1 and e1 != -1 and l1 !=0 and o1 != -1: if h1 < e1 and e1 < l1 and l1 < o1: print("YES") exit(0) print("NO") ```
0
92
A
Chips
PROGRAMMING
800
[ "implementation", "math" ]
A. Chips
2
256
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The pre...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
[ "4 11\n", "17 107\n", "3 8\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ...
500
[ { "input": "4 11", "output": "0" }, { "input": "17 107", "output": "2" }, { "input": "3 8", "output": "1" }, { "input": "46 7262", "output": "35" }, { "input": "32 6864", "output": "0" }, { "input": "36 6218", "output": "14" }, { "input": "...
1,598,358,206
2,147,483,647
Python 3
OK
TESTS
25
216
0
n,m=map(int,input().split()) x=0 flag=0 while x<m: for i in range(1,n+1): if x<m: x+=i if x>m: x-=i flag=1 break if flag==1: break print(m-x)
Title: Chips Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu...
```python n,m=map(int,input().split()) x=0 flag=0 while x<m: for i in range(1,n+1): if x<m: x+=i if x>m: x-=i flag=1 break if flag==1: break print(m-x) ```
3.946
1,011
A
Stages
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are $n$ stages available. The ro...
The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket. The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th...
Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
[ "5 3\nxyabd\n", "7 4\nproblem\n", "2 2\nab\n", "12 1\nabaabbaaabbb\n" ]
[ "29", "34", "-1", "1" ]
In the first example, the following rockets satisfy the condition: - "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$). Rocket "adx" has the minimal weight, so the answer is $29$. In the second example, target rocket is "belo". Its weight ...
500
[ { "input": "5 3\nxyabd", "output": "29" }, { "input": "7 4\nproblem", "output": "34" }, { "input": "2 2\nab", "output": "-1" }, { "input": "12 1\nabaabbaaabbb", "output": "1" }, { "input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa", "output": ...
1,532,824,383
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
109
0
n = input("n:") k = input("k:") if k==0 : print("0") else : n=int(n) k=int(k) a = [] for i in range(0,n) : a.append(ord(input("->"))-96) a = sorted(a) j = 1 s=a[0] i=1 while j<k and i<len(a) : if a[i]>a[i-1]+1 : s +=a[i] ...
Title: Stages Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — conca...
```python n = input("n:") k = input("k:") if k==0 : print("0") else : n=int(n) k=int(k) a = [] for i in range(0,n) : a.append(ord(input("->"))-96) a = sorted(a) j = 1 s=a[0] i=1 while j<k and i<len(a) : if a[i]>a[i-1]+1 : s +=a[i] ...
-1
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,574,775,530
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
word = input() count = 0 for a in 'holle': if a in word: b = word.find(a) word = word[b:] count += 1 if count >= 5: print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python word = input() count = 0 for a in 'holle': if a in word: b = word.find(a) word = word[b:] count += 1 if count >= 5: print('YES') else: print('NO') ```
0
108
A
Palindromic Times
PROGRAMMING
1,000
[ "implementation", "strings" ]
A. Palindromic Times
2
256
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th...
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
[ "12:21\n", "23:59\n" ]
[ "13:31\n", "00:00\n" ]
none
500
[ { "input": "12:21", "output": "13:31" }, { "input": "23:59", "output": "00:00" }, { "input": "15:51", "output": "20:02" }, { "input": "10:44", "output": "11:11" }, { "input": "04:02", "output": "04:40" }, { "input": "02:11", "output": "02:20" }, ...
1,513,303,590
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
5,529,600
s = input() l = s.split(':') if l[1] > l[0][::-1]: l[0] = str(int(l[0]) + 1) if l[0] == '24': l[0] = '00' if len(l[0])==1: l[0] = '0' + l[0] if l[0][1] >= '6': if l[0][0] == '0': print('10:01') else: print('20:02') else: print(l[0]+':'+l[0][::-1])
Title: Palindromic Times Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling...
```python s = input() l = s.split(':') if l[1] > l[0][::-1]: l[0] = str(int(l[0]) + 1) if l[0] == '24': l[0] = '00' if len(l[0])==1: l[0] = '0' + l[0] if l[0][1] >= '6': if l[0][0] == '0': print('10:01') else: print('20:02') else: print(l[0]+':'+l[0][::-1]) ```
0
260
A
Adding Digits
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di...
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
[ "5 4 5\n", "12 11 1\n", "260 150 10\n" ]
[ "524848\n", "121\n", "-1\n" ]
none
500
[ { "input": "5 4 5", "output": "524848" }, { "input": "12 11 1", "output": "121" }, { "input": "260 150 10", "output": "-1" }, { "input": "78843 5684 42717", "output": "-1" }, { "input": "93248 91435 1133", "output": "-1" }, { "input": "100000 10 64479"...
1,636,198,397
2,147,483,647
PyPy 3
OK
TESTS
25
93
18,227,200
n,a,b = map(int,input().split()) m=0 for i in range(10): if((n*10+i)%a==0): n = n*10+i m=1 break if m: print(str(n)+'0'*(b-1)) else: print(-1)
Title: Adding Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one ...
```python n,a,b = map(int,input().split()) m=0 for i in range(10): if((n*10+i)%a==0): n = n*10+i m=1 break if m: print(str(n)+'0'*(b-1)) else: print(-1) ```
3
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,695,987,934
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
x="YES" c=input() for i in range(len(c)): if(c[i]=='4' or c[i]=='7'): continue else: x="NO" break print(x)
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python x="YES" c=input() for i in range(len(c)): if(c[i]=='4' or c[i]=='7'): continue else: x="NO" break print(x) ```
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,664,886,730
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n, m, a = map(int, input().split()) if m%a > 1 and n%a > 1: cnt = ((m//a)+1%(m%a))*((n//a)+1%(n%a)) if m%a == 1 and n%a==1: cnt = ((m//a)+1)*((n//a)+1) else: cnt = (m//a)*(n//a) print(cnt)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python n, m, a = map(int, input().split()) if m%a > 1 and n%a > 1: cnt = ((m//a)+1%(m%a))*((n//a)+1%(n%a)) if m%a == 1 and n%a==1: cnt = ((m//a)+1)*((n//a)+1) else: cnt = (m//a)*(n//a) print(cnt) ```
0
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,587,222,581
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
310
0
''' INPUT SHORTCUTS N, K = map(int,input().split()) N ,A,B = map(int,input().split()) string = str(input()) arr = list(map(int,input().split())) N = int(input()) ''' N = int(input()) arr = list(map(int,input().split())) add = sum(arr) if add%(N+1)==0: print(2) else: print(3)
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 ''' INPUT SHORTCUTS N, K = map(int,input().split()) N ,A,B = map(int,input().split()) string = str(input()) arr = list(map(int,input().split())) N = int(input()) ''' N = int(input()) arr = list(map(int,input().split())) add = sum(arr) if add%(N+1)==0: print(2) else: print(3) ```
0
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff...
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 ...
1,697,645,709
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
124
19,660,800
n = int(input()) a = list(map(int, input().split())) count = 0 x = max(a) y = min(a) if a.count(x) == a.count(y) and a.count(x) > 1: count= a.count(x) + a.count(y) dif = x - y else: count+=1 dif = x - y print(dif, count)
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th...
```python n = int(input()) a = list(map(int, input().split())) count = 0 x = max(a) y = min(a) if a.count(x) == a.count(y) and a.count(x) > 1: count= a.count(x) + a.count(y) dif = x - y else: count+=1 dif = x - y print(dif, count) ```
0
394
A
Counting Sticks
PROGRAMMING
0
[ "brute force", "implementation" ]
null
null
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add...
The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100.
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print...
[ "||+|=|||||\n", "|||||+||=||\n", "|+|=||||||\n", "||||+||=||||||\n" ]
[ "|||+|=||||\n", "Impossible\n", "Impossible\n", "||||+||=||||||\n" ]
In the first sample we can shift stick from the third group of sticks to the first one. In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign. There is no answer in the third sample because we cannot remove sticks from the expression. In the forth s...
500
[ { "input": "||+|=|||||", "output": "|||+|=||||" }, { "input": "|||||+||=||", "output": "Impossible" }, { "input": "|+|=||||||", "output": "Impossible" }, { "input": "||||+||=||||||", "output": "||||+||=||||||" }, { "input": "||||||||||||+|||||||||||=||||||||||||||...
1,580,495,625
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
140
819,200
import re def get_actual(input_string): a, b, c = map(str, re.split('[+ =]', input_string)) a_count = len(a) b_count = len(b) c_count = len(c) if c_count - b_count == a_count: return input_string elif (c_count - (b_count + a_count)) >= 1: #diff = c_count - (b_cou...
Title: Counting Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our te...
```python import re def get_actual(input_string): a, b, c = map(str, re.split('[+ =]', input_string)) a_count = len(a) b_count = len(b) c_count = len(c) if c_count - b_count == a_count: return input_string elif (c_count - (b_count + a_count)) >= 1: #diff = c_coun...
0
893
C
Rumor
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "greedy" ]
null
null
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor. ...
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
[ "5 2\n2 5 3 4 8\n1 4\n4 5\n", "10 0\n1 2 3 4 5 6 7 8 9 10\n", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n" ]
[ "10\n", "55\n", "15\n" ]
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example ...
0
[ { "input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10" }, { "input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55" }, { "input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15" }, { "input": "1 0\n0", "output": "0" }, { "input": "1 0\n10000000...
1,625,973,881
2,147,483,647
Python 3
OK
TESTS
46
951
39,526,400
# _ ##################################################################################################################### nCharacters, nPairs = map(int, input().split(' ')) characters, golds = set(), {} for iCharacter, gold in enumerate(input().split(' ')): character = str(iCharacter+1) characters.add(c...
Title: Rumor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte...
```python # _ ##################################################################################################################### nCharacters, nPairs = map(int, input().split(' ')) characters, golds = set(), {} for iCharacter, gold in enumerate(input().split(' ')): character = str(iCharacter+1) charac...
3
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO"...
1,691,089,851
2,147,483,647
Python 3
OK
TESTS
20
92
0
w = int(input()) if ((w%2)!=0): print("NO") elif(w<=2): print("NO") else: print("YES")
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin...
```python w = int(input()) if ((w%2)!=0): print("NO") elif(w<=2): print("NO") else: print("YES") ```
3.954
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* woode...
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal...
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ...
1,632,839,537
2,147,483,647
Python 3
OK
TESTS
57
186
6,963,200
n = int(input()) countl0,countl1 = 0,0 countr0,countr1 = 0,0 for i in range(n): l,r = map(int, input().split()) if l==0: countl0 += 1 else: countl1 += 1 if r==0: countr0 += 1 else: countr1 += 1 print(min(countr1,countr0) + min(countl0,countl1))
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long...
```python n = int(input()) countl0,countl1 = 0,0 countr0,countr1 = 0,0 for i in range(n): l,r = map(int, input().split()) if l==0: countl0 += 1 else: countl1 += 1 if r==0: countr0 += 1 else: countr1 += 1 print(min(countr1,countr0) + min(countl0,countl1)) ...
3
779
C
Dishonest Sellers
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "sortings" ]
null
null
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*. Not all of sellers are honest, so now some products could be more expensive than after a week...
In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during d...
Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now.
[ "3 1\n5 4 6\n3 1 5\n", "5 3\n3 4 7 10 3\n4 5 5 12 5\n" ]
[ "10\n", "25\n" ]
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ...
1,000
[ { "input": "3 1\n5 4 6\n3 1 5", "output": "10" }, { "input": "5 3\n3 4 7 10 3\n4 5 5 12 5", "output": "25" }, { "input": "1 0\n9\n8", "output": "8" }, { "input": "2 0\n4 10\n1 2", "output": "3" }, { "input": "4 2\n19 5 17 13\n3 18 8 10", "output": "29" }, ...
1,551,559,263
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
N, K = input().strip().split() N, K = int(N), int(K) #wants to buy at least k now(with discounts), wants to buy n in total discounts = input().strip().split() normal = input().strip().split() items = [] for i in range(N): discounts[i] = int(discounts[i]) normal[i] = int(normal[i]) items.append([disc...
Title: Dishonest Sellers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be...
```python N, K = input().strip().split() N, K = int(N), int(K) #wants to buy at least k now(with discounts), wants to buy n in total discounts = input().strip().split() normal = input().strip().split() items = [] for i in range(N): discounts[i] = int(discounts[i]) normal[i] = int(normal[i]) items.ap...
0
766
B
Mahmoud and a Triangle
PROGRAMMING
1,000
[ "constructive algorithms", "geometry", "greedy", "math", "number theory", "sortings" ]
null
null
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments...
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
[ "5\n1 5 3 2 4\n", "3\n4 1 2\n" ]
[ "YES\n", "NO\n" ]
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
1,000
[ { "input": "5\n1 5 3 2 4", "output": "YES" }, { "input": "3\n4 1 2", "output": "NO" }, { "input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576", "output": "NO" },...
1,648,130,370
2,147,483,647
Python 3
OK
TESTS
87
124
8,089,600
n = int(input()) arr = [] aux = input().split() for i in range(n): arr.append(int(aux[i])) def isNonDegTr(arr, n): if(n < 3): return False arr.sort() for i in range(n-2): if(arr[i]+arr[i+1]>arr[i+2]): return True if(isNonDegTr(arr, n)): print("YES") else...
Title: Mahmoud and a Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he ca...
```python n = int(input()) arr = [] aux = input().split() for i in range(n): arr.append(int(aux[i])) def isNonDegTr(arr, n): if(n < 3): return False arr.sort() for i in range(n-2): if(arr[i]+arr[i+1]>arr[i+2]): return True if(isNonDegTr(arr, n)): print("Y...
3
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", ...
1,668,917,616
2,147,483,647
Python 3
OK
TESTS
47
233
7,270,400
from collections import Counter input() s = Counter(map(int,input().split())) m = max(s) dp = [0]*(m+1) dp[1] = s[1] dp[2] = max(dp[1],2*s[2]) for i in range(3,m+1): dp[i] = max(dp[i-2] + i*s[i], dp[i-1]) print(dp[-1])
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make ...
```python from collections import Counter input() s = Counter(map(int,input().split())) m = max(s) dp = [0]*(m+1) dp[1] = s[1] dp[2] = max(dp[1],2*s[2]) for i in range(3,m+1): dp[i] = max(dp[i-2] + i*s[i], dp[i-1]) print(dp[-1]) ```
3
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-s...
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "inpu...
1,690,708,890
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
#from collections import Counter #import math count_time=1 if count_time: import time start_time = time.time() #------------------------------------------ p=input() j=None ok=False for i in p: if i=='+': j=chr(ord(j)+1) if j in 'HQ9': ok=True break ...
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in...
```python #from collections import Counter #import math count_time=1 if count_time: import time start_time = time.time() #------------------------------------------ p=input() j=None ok=False for i in p: if i=='+': j=chr(ord(j)+1) if j in 'HQ9': ok=True ...
0
0
none
none
none
0
[ "none" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ...
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equival...
0
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { ...
1,619,302,706
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
409,600
def comparassion(palavra_1, palavra_2): if(palavra_1 == palavra_2): return True if(len(palavra_1)!=len(palavra_2)): return False center = len(palavra_1)//2 return (comparassion(palavra_1[center:], palavra_2[center:]) and comparassion(palavra_1[:center], palavra_2[:center])) or (comparassion(pa...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into t...
```python def comparassion(palavra_1, palavra_2): if(palavra_1 == palavra_2): return True if(len(palavra_1)!=len(palavra_2)): return False center = len(palavra_1)//2 return (comparassion(palavra_1[center:], palavra_2[center:]) and comparassion(palavra_1[:center], palavra_2[:center])) or (compa...
-1
989
B
A Tide of Riverscape
PROGRAMMING
1,200
[ "constructive algorithms", "strings" ]
null
null
"Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence. Doubtfully, Kanno peeks a...
The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively. The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' c...
Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
[ "10 7\n1.0.1.0.1.\n", "10 6\n1.0.1.1000\n", "10 9\n1........1\n" ]
[ "1000100010\n", "1001101000\n", "No\n" ]
In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different. In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different. In the third example, $9$ is always a period because the onl...
1,000
[ { "input": "10 7\n1.0.1.0.1.", "output": "1000100010" }, { "input": "10 6\n1.0.1.1000", "output": "1001101000" }, { "input": "10 9\n1........1", "output": "No" }, { "input": "1 1\n.", "output": "No" }, { "input": "5 1\n0...1", "output": "00001" }, { "i...
1,528,725,459
1,359
Python 3
CHALLENGED
CHALLENGES
8
140
716,800
import re import math import decimal import bisect def read(): return input().strip() def iread(): return int(input().strip()) def viread(): return [int(x) for x in input().strip().split()] # code goes here n, p = viread() line = read() for i, c in enumerate(line): try: # print("at i = {}, ...
Title: A Tide of Riverscape Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its...
```python import re import math import decimal import bisect def read(): return input().strip() def iread(): return int(input().strip()) def viread(): return [int(x) for x in input().strip().split()] # code goes here n, p = viread() line = read() for i, c in enumerate(line): try: # print("a...
-1
0
none
none
none
0
[ "none" ]
null
null
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with *n* rows and *m*...
The only line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105; *n*·*m*<=≤<=105) — the number of rows and the number of columns in the required matrix.
If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next *n* lines output *m* integers which form the required matrix.
[ "2 4\n", "2 1\n" ]
[ "YES\n5 4 7 2 \n3 6 1 8 \n", "NO\n" ]
In the first test case the matrix initially looks like this: It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
0
[ { "input": "2 4", "output": "YES\n5 4 7 2 \n3 6 1 8 " }, { "input": "2 1", "output": "NO" }, { "input": "1 1", "output": "YES\n1" }, { "input": "1 2", "output": "NO" }, { "input": "1 3", "output": "NO" }, { "input": "2 2", "output": "NO" }, { ...
1,514,045,032
7,132
PyPy 3
WRONG_ANSWER
PRETESTS
0
93
25,497,600
#!/usr/bin/env python3 from random import shuffle def solve(): n, m = get([int]) if n+m < 4: return 'NO' L = [(i-1)*m + j for i in range(1,n+1) for j in range(1,m+1)] shuffle(L) L = list(zip(*([iter(L)]*m))) L = [' '.join(map(str, row)) for row in L] return '\n'.join(L) _...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not ne...
```python #!/usr/bin/env python3 from random import shuffle def solve(): n, m = get([int]) if n+m < 4: return 'NO' L = [(i-1)*m + j for i in range(1,n+1) for j in range(1,m+1)] shuffle(L) L = list(zip(*([iter(L)]*m))) L = [' '.join(map(str, row)) for row in L] return '\n'.join(L) ...
0
612
C
Replace To Make Regular Bracket Sequence
PROGRAMMING
1,400
[ "data structures", "expression parsing", "math" ]
null
null
You are given string *s* consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace &lt; by the bracket {, but you can't replace it by ) or &gt;. The following d...
The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106.
If it's impossible to get RBS from *s* print Impossible. Otherwise print the least number of replaces needed to get RBS from *s*.
[ "[&lt;}){}\n", "{()}[]\n", "]]\n" ]
[ "2", "0", "Impossible" ]
none
0
[ { "input": "[<}){}", "output": "2" }, { "input": "{()}[]", "output": "0" }, { "input": "]]", "output": "Impossible" }, { "input": ">", "output": "Impossible" }, { "input": "{}", "output": "0" }, { "input": "{}", "output": "0" }, { "input": ...
1,532,831,523
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
st = input() a1 = st.count('(')-st.count(')') a2 = st.count('<')-st.count('>') a3 = st.count('{')-st.count('}') a4 = st.count('[')-st.count(']') if a1+a2+a3+a4 ==0: print(abs(a1)+abs(a2)+abs(a3)+abs(4)) else: print("Impossible")
Title: Replace To Make Regular Bracket Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given string *s* consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another...
```python st = input() a1 = st.count('(')-st.count(')') a2 = st.count('<')-st.count('>') a3 = st.count('{')-st.count('}') a4 = st.count('[')-st.count(']') if a1+a2+a3+a4 ==0: print(abs(a1)+abs(a2)+abs(a3)+abs(4)) else: print("Impossible") ```
0
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ...
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output"...
1,532,040,691
2,147,483,647
Python 3
OK
TESTS
20
248
0
n = int(input()) values = [int(k) for k in input().split()] minimo = 1000000000 j = 0 for i in range(-1,n-1): if abs(values[i] - values[i+1])< minimo: minimo = abs(values[i] - values[i+1]) j = i if j<0: print(n, 1) else: print(j+1, j+2)
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So...
```python n = int(input()) values = [int(k) for k in input().split()] minimo = 1000000000 j = 0 for i in range(-1,n-1): if abs(values[i] - values[i+1])< minimo: minimo = abs(values[i] - values[i+1]) j = i if j<0: print(n, 1) else: print(j+1, j+2) ```
3.938
710
B
Optimal Point on a Line
PROGRAMMING
1,400
[ "brute force", "sortings" ]
null
null
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line. The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
[ "4\n1 2 3 4\n" ]
[ "2\n" ]
none
0
[ { "input": "4\n1 2 3 4", "output": "2" }, { "input": "5\n-1 -10 2 6 7", "output": "2" }, { "input": "10\n-68 10 87 22 30 89 82 -97 -52 25", "output": "22" }, { "input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -...
1,471,985,078
2,147,483,647
Python 3
OK
TESTS
42
296
27,443,200
n = int(input()) A = list(map(int, input().split())) A.sort() print(A[n//2 - (1 if n % 2 == 0 else 0)])
Title: Optimal Point on a Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=...
```python n = int(input()) A = list(map(int, input().split())) A.sort() print(A[n//2 - (1 if n % 2 == 0 else 0)]) ```
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,815,733
2,147,483,647
Python 3
OK
TESTS
117
109
102,400
def max_beauty(n, k, s): max_len = 0 for c in ['a', 'b']: start = 0 changes = 0 for end in range(n): if s[end] != c: changes += 1 while changes > k: if s[start] != c: changes -= 1 start += 1 ...
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 def max_beauty(n, k, s): max_len = 0 for c in ['a', 'b']: start = 0 changes = 0 for end in range(n): if s[end] != c: changes += 1 while changes > k: if s[start] != c: changes -= 1 start ...
3
45
A
Codecraft III
PROGRAMMING
900
[ "implementation" ]
A. Codecraft III
2
256
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa...
The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III.
Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December.
[ "November\n3\n", "May\n24\n" ]
[ "February\n", "May\n" ]
none
0
[ { "input": "November\n3", "output": "February" }, { "input": "May\n24", "output": "May" }, { "input": "April\n0", "output": "April" }, { "input": "September\n0", "output": "September" }, { "input": "August\n0", "output": "August" }, { "input": "June\n1...
1,390,484,477
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] current_month = raw_input() months_left = int(raw_input()) i = months.index(current_month) print months[(i+months_left)%12]
Title: Codecraft III Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *...
```python months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] current_month = raw_input() months_left = int(raw_input()) i = months.index(current_month) print months[(i+months_left)%12] ```
-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,531,915,544
2,147,483,647
Python 3
OK
TESTS
26
109
0
from math import gcd n = int(input()) for a, b in zip(range((n - 1) // 2, 0, -1), range((n + 2) // 2, n)): if gcd(a, b) == 1: print(a, b) break
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 from math import gcd n = int(input()) for a, b in zip(range((n - 1) // 2, 0, -1), range((n + 2) // 2, n)): if gcd(a, b) == 1: print(a, b) break ```
3
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894"...
1,624,679,818
2,147,483,647
Python 3
OK
TESTS
37
77
0
a, b = map(int, input().split()) c = a % b if c == 0: print(a+b) else: print(a + (b - c))
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *...
```python a, b = map(int, input().split()) c = a % b if c == 0: print(a+b) else: print(a + (b - c)) ```
3
468
A
24 Game
PROGRAMMING
1,500
[ "constructive algorithms", "greedy", "math" ]
null
null
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence eit...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes). If there is a way to obtain 24 as the result number, in the following *n*<=-<=1 lines print the required operations an operation per line. Each operation should be in form: "*a* *op* *b* = *c*". Where *a* and *b* are the numbe...
[ "1\n", "8\n" ]
[ "NO\n", "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24\n" ]
none
500
[ { "input": "1", "output": "NO" }, { "input": "8", "output": "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24" }, { "input": "12", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 =...
1,642,655,359
2,147,483,647
PyPy 3-64
OK
TESTS
31
264
9,932,800
n = int(input()) if n in [1, 2, 3]: print("NO") else: print("YES") if n % 2 == 0: for i in range((n - 4) // 2): print(f"{n - 2 * i} - {n - 2 * i - 1} = 1") print("4 * 3 = 12", "12 * 2 = 24", "24 * 1 = 24", sep = '\n') for j in range((n - 4) // 2): ...
Title: 24 Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them...
```python n = int(input()) if n in [1, 2, 3]: print("NO") else: print("YES") if n % 2 == 0: for i in range((n - 4) // 2): print(f"{n - 2 * i} - {n - 2 * i - 1} = 1") print("4 * 3 = 12", "12 * 2 = 24", "24 * 1 = 24", sep = '\n') for j in range((n - 4) // 2): ...
3
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces ...
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": "...
1,695,631,130
2,147,483,647
Python 3
OK
TESTS
42
62
0
s=input() vowels=["a","o","y","e","u","i"] output="" for letter in s: letter=letter.lower() if letter in vowels : continue output+="."+letter print(output)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters...
```python s=input() vowels=["a","o","y","e","u","i"] output="" for letter in s: letter=letter.lower() if letter in vowels : continue output+="."+letter print(output) ```
3