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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,501,227,551 | 2,351 | Python 3 | OK | TESTS | 89 | 62 | 4,608,000 | import sys
arr = list(map(int,input().split()))
n = arr[0]
a = arr[1]
b = arr[2]
c = arr[3]
if n % 4 == 0:
print(0)
elif n % 4 == 3:
print( min(a,b+c,c*3,(c+(2*a) )))
elif n % 4 == 2:
print(min( a*2, b, c*2, (c+(3*a)) ))
elif n % 4 == 1:
print(min(a*3,b+a,c)) | 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 sys
arr = list(map(int,input().split()))
n = arr[0]
a = arr[1]
b = arr[2]
c = arr[3]
if n % 4 == 0:
print(0)
elif n % 4 == 3:
print( min(a,b+c,c*3,(c+(2*a) )))
elif n % 4 == 2:
print(min( a*2, b, c*2, (c+(3*a)) ))
elif n % 4 == 1:
print(min(a*3,b+a,c))
``` | 3 | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,699,188,088 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n,a,b,c = list(map(int,input().split()))
l = [a,b,c]
l.sort(reverse=True)
d = []
t = n
i,t = divmod(t,l[0])
j,t = divmod(t,l[1])
k,t = divmod(t,l[2])
if t == 0:
d.append(i+j+k)
t = n
i,t = divmod(t,l[0])
j,t = divmod(t,l[1])
# k,t = divmod(t,l[2])
if t == 0:
d.append(i+j)
t = n
i,t = ... | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
n,a,b,c = list(map(int,input().split()))
l = [a,b,c]
l.sort(reverse=True)
d = []
t = n
i,t = divmod(t,l[0])
j,t = divmod(t,l[1])
k,t = divmod(t,l[2])
if t == 0:
d.append(i+j+k)
t = n
i,t = divmod(t,l[0])
j,t = divmod(t,l[1])
# k,t = divmod(t,l[2])
if t == 0:
d.append(i+j)
t =... | 0 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,583,588,797 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 0 | str = list(input())
nineteen = {'n': [3, 2], 'i': [1, 1], 'e': [3, 3], 't': [1, 1]}
str_count = [(str.count(key) - x) // y + 1 for key, [x, y] in nineteen.items()]
output = max(min(str_count), 0)
print(output)
| Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
str = list(input())
nineteen = {'n': [3, 2], 'i': [1, 1], 'e': [3, 3], 't': [1, 1]}
str_count = [(str.count(key) - x) // y + 1 for key, [x, y] in nineteen.items()]
output = max(min(str_count), 0)
print(output)
``` | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,622,666,608 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 248 | 0 | import sys
def answer(r, g, b):
num = r//3 + g//3 + b//3
rm = r%3
gm = g%3
bm = b%3
mods = [rm, gm, bm]
if sorted(mods) != [1, 2, 2] and sorted(mods) != [0, 2, 2]:
num += min(mods)
return num
if (rm == 0 or rm == 1) and r//3 > 1:
num += 2
return ... | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
import sys
def answer(r, g, b):
num = r//3 + g//3 + b//3
rm = r%3
gm = g%3
bm = b%3
mods = [rm, gm, bm]
if sorted(mods) != [1, 2, 2] and sorted(mods) != [0, 2, 2]:
num += min(mods)
return num
if (rm == 0 or rm == 1) and r//3 > 1:
num += 2
... | 0 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,657,038,804 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 248 | 512,000 | n,m=list(map(int,input().split()))
arr=list(map(int,input().split()))
arr.sort()
ans=0
for i in range(m):
if(arr[i]<0):
ans+=abs(arr[i])
print(ans) | 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=list(map(int,input().split()))
arr=list(map(int,input().split()))
arr.sort()
ans=0
for i in range(m):
if(arr[i]<0):
ans+=abs(arr[i])
print(ans)
``` | 3.937046 |
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,696,004,834 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 186 | 0 | input_string = input().strip()
vowels = {'A', 'O', 'Y', 'E', 'U', 'I', 'a', 'o', 'y', 'e', 'u', 'i'}
result_string = ''
for char in input_string:
if char not in vowels:
result_string += '.' + char.lower()
print(result_string) | 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
input_string = input().strip()
vowels = {'A', 'O', 'Y', 'E', 'U', 'I', 'a', 'o', 'y', 'e', 'u', 'i'}
result_string = ''
for char in input_string:
if char not in vowels:
result_string += '.' + char.lower()
print(result_string)
``` | 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,688,923,446 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | for i in range(int(input())):
n=input()
x=[]
x=[i for i in n]
if(len(x)>10):
print(x[0],end="")
print(len(x)-2,end="")
print(x[len(x)-1])
else:
print(n)
| 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
for i in range(int(input())):
n=input()
x=[]
x=[i for i in n]
if(len(x)>10):
print(x[0],end="")
print(len(x)-2,end="")
print(x[len(x)-1])
else:
print(n)
``` | 3.9845 |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,643,127,984 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 92 | 0 | l, r = 1, int(input())
while l < r:
print(l, r, end=" ")
l += 1
r -= 1
if l == r:
print(l) | Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ... | ```python
l, r = 1, int(input())
while l < r:
print(l, r, end=" ")
l += 1
r -= 1
if l == r:
print(l)
``` | 3.977 |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,604,285,687 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 280 | 0 | n,k = map(int,input().split())
if k/n >= 3:
print(0)
else:
c = 0
while k%n != 0:
k -= 1
c += 1
print(n-c)
| Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
n,k = map(int,input().split())
if k/n >= 3:
print(0)
else:
c = 0
while k%n != 0:
k -= 1
c += 1
print(n-c)
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,653,492,274 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import math
a = int(input())
b = int(input())
c = int(input())
t = 0
if (a == 0 and b == 0):
print(0)
else:
t = int(a / c)+ int(b / c) + math.ceil(a / c - a //c) + math.ceil(b/c - b//c)
print(t)
| 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
import math
a = int(input())
b = int(input())
c = int(input())
t = 0
if (a == 0 and b == 0):
print(0)
else:
t = int(a / c)+ int(b / c) + math.ceil(a / c - a //c) + math.ceil(b/c - b//c)
print(t)
``` | -1 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,650,468,231 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | def solution():
inputs = input().split()
board_height = int(inputs[0])
board_width = int(inputs[1])
half_board_height = board_height // 2
half_board_width = board_width // 2
area_sum = 2 * half_board_height * half_board_width
if ((board_height % 2 == 1) and (board_width % 2 == 1)):
... | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
def solution():
inputs = input().split()
board_height = int(inputs[0])
board_width = int(inputs[1])
half_board_height = board_height // 2
half_board_width = board_width // 2
area_sum = 2 * half_board_height * half_board_width
if ((board_height % 2 == 1) and (board_width % 2 == 1)... | 3.977 |
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The ... | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input":... | 1,667,671,369 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 342 | 0 | n, k = map(int, input().split())
i = 1
while i < n + 1:
if k:
print(n, end=" ")
n -= 1
k -= 1
else:
print(i, end=" ")
i += 1
| Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutat... | ```python
n, k = map(int, input().split())
i = 1
while i < n + 1:
if k:
print(n, end=" ")
n -= 1
k -= 1
else:
print(i, end=" ")
i += 1
``` | 3 | |
157 | A | Game Outcome | PROGRAMMING | 800 | [
"brute force"
] | null | null | Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100. | Print the single number — the number of the winning squares. | [
"1\n1\n",
"2\n1 2\n3 4\n",
"4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n"
] | [
"0\n",
"2\n",
"6\n"
] | In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning: | 500 | [
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2\n3 4",
"output": "2"
},
{
"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3",
"output": "6"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "4"
},
{
"inpu... | 1,621,071,917 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 124 | 0 | n = int(input())
s = [list(map(int, input().split())) for _ in range(n)]
Y = [0 for _ in range(n)]
T = [0 for _ in range(n)]
for i in range(n):
for j in range(n):
Y[i] += s[i][j]
T[j] += s[i][j]
ans = 0
for i in range(n):
for j in range(n):
if T[j] > Y[i]:
a... | Title: Game Outcome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each s... | ```python
n = int(input())
s = [list(map(int, input().split())) for _ in range(n)]
Y = [0 for _ in range(n)]
T = [0 for _ in range(n)]
for i in range(n):
for j in range(n):
Y[i] += s[i][j]
T[j] += s[i][j]
ans = 0
for i in range(n):
for j in range(n):
if T[j] > Y[i]:
... | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,671,591,524 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | # Read input
n = int(input())
a = list(map(int, input().split()))
# Initialize the number of valid ways to 0
ways = 0
# Iterate through the list of cookie bags
for i in range(n):
# If the number of cookies in the current bag is even
if a[i] % 2 == 0:
# Calculate the total number of cookies in the r... | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
# Read input
n = int(input())
a = list(map(int, input().split()))
# Initialize the number of valid ways to 0
ways = 0
# Iterate through the list of cookie bags
for i in range(n):
# If the number of cookies in the current bag is even
if a[i] % 2 == 0:
# Calculate the total number of cookie... | 0 | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,699,206,100 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | q=input()
q=list(q)
n=0
for i in q:
k=q.count(i)
if k<2: n=n+1
if n%2==0: print('CHAT WITH HER!')
else: print('IGNORE HIM!')
| Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
q=input()
q=list(q)
n=0
for i in q:
k=q.count(i)
if k<2: n=n+1
if n%2==0: print('CHAT WITH HER!')
else: print('IGNORE HIM!')
``` | 0 | |
175 | A | Robot Bicorn Attack | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided ... | The only line of input contains non-empty string *s* obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters. | Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1. | [
"1234\n",
"9000\n",
"0009\n"
] | [
"37\n",
"90\n",
"-1\n"
] | In the first example the string must be split into numbers 1, 2 and 34.
In the second example the string must be split into numbers 90, 0 and 0.
In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes. | 500 | [
{
"input": "1234",
"output": "37"
},
{
"input": "9000",
"output": "90"
},
{
"input": "0009",
"output": "-1"
},
{
"input": "100000010000001000000",
"output": "3000000"
},
{
"input": "1000000011",
"output": "1000011"
},
{
"input": "9991",
"output": "... | 1,449,774,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | def g(a):
return (len(a) > 1 or a[0] != '0') and int(a) <= 1000000
def f(a, b, c):
return int(a) + int(b) + int(c) if g(a) and g(b) and g(c) else -1
s, v = input(), -1
for i in range(1, len(s) - 1):
for j in range(i + 1, len(s)):
v = max(v, f(s[:i], s[i:j], s[j:]))
print(v) | Title: Robot Bicorn Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played thre... | ```python
def g(a):
return (len(a) > 1 or a[0] != '0') and int(a) <= 1000000
def f(a, b, c):
return int(a) + int(b) + int(c) if g(a) and g(b) and g(c) else -1
s, v = input(), -1
for i in range(1, len(s) - 1):
for j in range(i + 1, len(s)):
v = max(v, f(s[:i], s[i:j], s[j:]))
print(v)
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,621,870,737 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 124 | 0 | class Force:
def __init__(self, x, y, z) -> None:
self.x = x
self.y = y
self.z = z
def __iadd__(self, other):
return Force(self.x + other.x, self.y + other.y, self.z + other.z)
def isvalid(self):
return "YES" if self.x == self.y == self.z == 0 else "NO"
... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
class Force:
def __init__(self, x, y, z) -> None:
self.x = x
self.y = y
self.z = z
def __iadd__(self, other):
return Force(self.x + other.x, self.y + other.y, self.z + other.z)
def isvalid(self):
return "YES" if self.x == self.y == self.z == 0 el... | 3.969 |
43 | C | Lucky Tickets | PROGRAMMING | 1,300 | [
"greedy"
] | C. Lucky Tickets | 2 | 256 | Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid a... | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of pieces. The second line contains *n* space-separated numbers *a**i* (1<=≤<=*a**i*<=≤<=108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some o... | Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together. | [
"3\n123 123 99\n",
"6\n1 1 1 23 10 3\n"
] | [
"1\n",
"1\n"
] | none | 1,500 | [
{
"input": "3\n123 123 99",
"output": "1"
},
{
"input": "6\n1 1 1 23 10 3",
"output": "1"
},
{
"input": "3\n43440907 58238452 82582355",
"output": "1"
},
{
"input": "4\n31450303 81222872 67526764 17516401",
"output": "1"
},
{
"input": "5\n83280 20492640 21552119 7... | 1,678,564,026 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 614,400 | n=int(input())
x=list(map(int,input().split()))
d=[0,0,0]
for i in x:
d[i%3]+=1
print(min(d[1],d[2])+d[0]//2) | Title: Lucky Tickets
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collec... | ```python
n=int(input())
x=list(map(int,input().split()))
d=[0,0,0]
for i in x:
d[i%3]+=1
print(min(d[1],d[2])+d[0]//2)
``` | 3.975856 |
729 | E | Subordinates | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"graphs",
"greedy",
"sortings"
] | null | null | There are *n* workers in a company, each of them has a unique id from 1 to *n*. Exaclty one of them is a chief, his id is *s*. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his imme... | The first line contains two positive integers *n* and *s* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*s*<=≤<=*n*) — the number of workers and the id of the chief.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=*n*<=-<=1), where *a**i* is the number of superiors (not only immediate) the worker with... | Print the minimum number of workers that could make a mistake. | [
"3 2\n2 0 2\n",
"5 3\n1 0 0 4 1\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible that only the first worker made a mistake. Then:
- the immediate superior of the first worker is the second worker, - the immediate superior of the third worker is the first worker, - the second worker is the chief. | 2,000 | [
{
"input": "3 2\n2 0 2",
"output": "1"
},
{
"input": "5 3\n1 0 0 4 1",
"output": "2"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "2 1\n0 0",
"output": "1"
},
{
"input": "2 1\n0 1",
"output": "0"
},
{
"input": "2 1\n1 0",
"output": "2"
},
... | 1,479,639,451 | 6,751 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 46 | 0 | n,s = map(int,input().split())
A = list(map(int,input().split()))
maxs = max(A)
ans = [0] * maxs
answer = maxs
t = 0
if A[s-1] == 0:
t = 1
o = 0
for j in range(n):
if A[j] == 0:
o += 1
if A[j] == 0:
if j == s-1:
ans[0] = 1
answer -= 1
elif 1 <= A[j... | Title: Subordinates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* workers in a company, each of them has a unique id from 1 to *n*. Exaclty one of them is a chief, his id is *s*. Each worker except the chief has exactly one immediate superior.
There was a request to each o... | ```python
n,s = map(int,input().split())
A = list(map(int,input().split()))
maxs = max(A)
ans = [0] * maxs
answer = maxs
t = 0
if A[s-1] == 0:
t = 1
o = 0
for j in range(n):
if A[j] == 0:
o += 1
if A[j] == 0:
if j == s-1:
ans[0] = 1
answer -= 1
eli... | -1 | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,564,469,539 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 139 | 1,433,600 | def reverse(c):
if str.islower(c):
return str.upper(c)
if str.isupper(c):
return str.lower(c)
from collections import Counter
import collections
s1 = input()
t1 = input()
s = Counter(s1)
t = Counter(t1)
yay = 0
count = 0
for k in s:
count+=1
d = min(s[k], t[k])
s[k] -= d
t[k] ... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
def reverse(c):
if str.islower(c):
return str.upper(c)
if str.isupper(c):
return str.lower(c)
from collections import Counter
import collections
s1 = input()
t1 = input()
s = Counter(s1)
t = Counter(t1)
yay = 0
count = 0
for k in s:
count+=1
d = min(s[k], t[k])
s[k] -= ... | 0 | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,620,632,205 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 6,656,000 | f=open("input.txt",'r')
B,G=map(int,f.readline().split())
if B > G:
result = "GB"*G + "B"* (B-G)
elif B < G:
result = "GB"* B + "G" * (G-B)
elif B == G:
result = "GB"* G
o=open("output.txt",'w')
o.write(result)
| Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
f=open("input.txt",'r')
B,G=map(int,f.readline().split())
if B > G:
result = "GB"*G + "B"* (B-G)
elif B < G:
result = "GB"* B + "G" * (G-B)
elif B == G:
result = "GB"* G
o=open("output.txt",'w')
o.write(result)
``` | 0 | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,619,428,868 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 77 | 0 | from math import ceil
day=int(input())
horizontal=[]
vertical=[]
work_days=[]
for i in range(day**2):
hr,vr=map(int,input().split())
if hr not in horizontal and vr not in vertical :
horizontal.append(hr)
vertical.append(vr)
work_days.append(i+1)
for i in range(len(work_days))... | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
from math import ceil
day=int(input())
horizontal=[]
vertical=[]
work_days=[]
for i in range(day**2):
hr,vr=map(int,input().split())
if hr not in horizontal and vr not in vertical :
horizontal.append(hr)
vertical.append(vr)
work_days.append(i+1)
for i in range(len(w... | 3 | |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,677,762,196 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input())
a=[]
for _ in range(n):
a.append(input())
for i in range(n):
ct=0
for j in range(n):
if i+1<n and a[i+1][j]=='o':
ct+=1
if j+1<n and a[i][j+1]=='o':
ct+=1
if i-1>=0 and a[i-1][j]=='o':
ct+=1
if j-1>=0 and a[i][j-... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
n=int(input())
a=[]
for _ in range(n):
a.append(input())
for i in range(n):
ct=0
for j in range(n):
if i+1<n and a[i+1][j]=='o':
ct+=1
if j+1<n and a[i][j+1]=='o':
ct+=1
if i-1>=0 and a[i-1][j]=='o':
ct+=1
if j-1>=0 a... | 0 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,635,974,611 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 184 | 28,364,800 | b = input()
if "--" in b:
b = b.replace("--","2")
if "-." in b:
b = b.replace("-.","1")
if "." in b:
b = b.replace(".","0")
print(b) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
b = input()
if "--" in b:
b = b.replace("--","2")
if "-." in b:
b = b.replace("-.","1")
if "." in b:
b = b.replace(".","0")
print(b)
``` | 3.901166 |
0 | none | none | none | 0 | [
"none"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 0 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,592,856,810 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 312 | 21,708,800 | def dfs(node):
vis[node]=1
for i in range(n):
if (X[i]==X[node] or Y[i]==Y[node]) and vis[i]==0:
dfs(i)
r=[-1 for i in range(2005)]
n=int(input())
X,Y=[],[]
vis=[0]*101
for i in range(n):
x,y=map(int,input().split())
X.append(x)
Y.append(y)
ans=0
for i in range(n):
if (vis[i]==0):
dfs(i)
ans+=1
print... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in th... | ```python
def dfs(node):
vis[node]=1
for i in range(n):
if (X[i]==X[node] or Y[i]==Y[node]) and vis[i]==0:
dfs(i)
r=[-1 for i in range(2005)]
n=int(input())
X,Y=[],[]
vis=[0]*101
for i in range(n):
x,y=map(int,input().split())
X.append(x)
Y.append(y)
ans=0
for i in range(n):
if (vis[i]==0):
dfs(i)
an... | 3 | |
678 | D | Iterated Linear Function | PROGRAMMING | 1,700 | [
"math",
"number theory"
] | null | null | Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. | The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement.
Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you c... | Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7. | [
"3 4 1 1\n",
"3 4 2 1\n",
"3 4 3 1\n"
] | [
"7\n",
"25\n",
"79\n"
] | none | 0 | [
{
"input": "3 4 1 1",
"output": "7"
},
{
"input": "3 4 2 1",
"output": "25"
},
{
"input": "3 4 3 1",
"output": "79"
},
{
"input": "1 1 1 1",
"output": "2"
},
{
"input": "3 10 723 6",
"output": "443623217"
},
{
"input": "14 81 51 82",
"output": "908... | 1,636,772,475 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 109 | 17,715,200 | '''
Python3(PyPy3) Template for Programming-Contest.
'''
import sys
def input():
return sys.stdin.readline().rstrip()
DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # LDRU
mod = int(1e9 + 7)
inf = 1 << 64
def main():
A, B, n, x = map(int, input().split())
if A == 1:
ans = x + n * B % mod
... | Title: Iterated Linear Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find th... | ```python
'''
Python3(PyPy3) Template for Programming-Contest.
'''
import sys
def input():
return sys.stdin.readline().rstrip()
DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # LDRU
mod = int(1e9 + 7)
inf = 1 << 64
def main():
A, B, n, x = map(int, input().split())
if A == 1:
ans = x + n * B %... | 0 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,620,212,313 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 61 | 0 | n = int(input())
score = list(set(map(int, input().split(" "))))
if 0 in score:
score.remove(0)
print(len(score))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n = int(input())
score = list(set(map(int, input().split(" "))))
if 0 in score:
score.remove(0)
print(len(score))
``` | 3 | |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,696,056,069 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | def compare_strings(str1,str2):
str1=str1.lower()
str2=str2.lower()
if str1<str2:
return-1
elif str1>str2:
return 1
else:
return 0
str1=input()
str2=input()
result=compare_strings(str1,str2)
print(result) | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
def compare_strings(str1,str2):
str1=str1.lower()
str2=str2.lower()
if str1<str2:
return-1
elif str1>str2:
return 1
else:
return 0
str1=input()
str2=input()
result=compare_strings(str1,str2)
print(result)
``` | 3.977 |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,699,427,049 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 216 | 1,638,400 | questions = int(input())
total = 0
while questions:
answers = input()
answers = list(map(int, answers.split(' ')))
answers = answers.count(1)
if (answers > 1): total += 1
questions -= 1
print(total) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
questions = int(input())
total = 0
while questions:
answers = input()
answers = list(map(int, answers.split(' ')))
answers = answers.count(1)
if (answers > 1): total += 1
questions -= 1
print(total)
``` | 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,679,780,213 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
list = ['a']
for i in range(n):
st = str(input())
if len(st) > 10:
for i in st:
list.append(i)
one = list[1]
two = str(len(st)-2)
thre =list[len(st)]
print(one+two+thre)
else:
print(st)
list = ['a'] | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int(input())
list = ['a']
for i in range(n):
st = str(input())
if len(st) > 10:
for i in st:
list.append(i)
one = list[1]
two = str(len(st)-2)
thre =list[len(st)]
print(one+two+thre)
else:
print(st)
list = ['a']
``` | 3.977 |
911 | C | Three Garlands | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms"
] | null | null | Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s... | The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. | If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO. | [
"2 2 3\n",
"4 2 3\n"
] | [
"YES\n",
"NO\n"
] | In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't... | 0 | [
{
"input": "2 2 3",
"output": "YES"
},
{
"input": "4 2 3",
"output": "NO"
},
{
"input": "1499 1498 1500",
"output": "NO"
},
{
"input": "1500 1500 1500",
"output": "NO"
},
{
"input": "100 4 1",
"output": "YES"
},
{
"input": "4 2 4",
"output": "YES"
... | 1,598,532,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 0 | l= list(map(int,input().split()))
if(l.count(1)>0): print("YES")
elif(l.count(2)>=2): print("YES")
elif(l.count(2)==1 and l.count(4)==2):print("YES")
else: print("NO") | Title: Three Garlands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its st... | ```python
l= list(map(int,input().split()))
if(l.count(1)>0): print("YES")
elif(l.count(2)>=2): print("YES")
elif(l.count(2)==1 and l.count(4)==2):print("YES")
else: print("NO")
``` | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,638,463,634 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | entry = input()
out = entry[::-1]
entry2 = input()
if out==entry2:
Print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
entry = input()
out = entry[::-1]
entry2 = input()
if out==entry2:
Print("YES")
else:
print("NO")
``` | -1 |
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,510,257,988 | 1,288 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(''.join(sorted(set(map(str, map(min, (a,b))))))) | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the sm... | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(''.join(sorted(set(map(str, map(min, (a,b)))))))
``` | 0 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,691,825,976 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n =int(input())
num1=0
num2=0
for i in range(n):
m,c=input().split()
m=int(m)
c=int(c)
if m<c:
num1+=1
if c>m:
num2+=1
if num1<num2:
print("Mishka")
elif num2<num1:
print("Chris")
else:
print("Friendship is magic!^^")
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n =int(input())
num1=0
num2=0
for i in range(n):
m,c=input().split()
m=int(m)
c=int(c)
if m<c:
num1+=1
if c>m:
num2+=1
if num1<num2:
print("Mishka")
elif num2<num1:
print("Chris")
else:
print("Friendship is magic!^^")
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 0 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,510,508,301 | 5,601 | Python 3 | OK | TESTS | 33 | 140 | 19,046,400 | n = [None for x in range(int(input()))]
u = input().split()
u.reverse()
x = dict(zip(u,n))
for key in x:
n = key
print(n)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First o... | ```python
n = [None for x in range(int(input()))]
u = input().split()
u.reverse()
x = dict(zip(u,n))
for key in x:
n = key
print(n)
``` | 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,694,691,000 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 140 | 3,891,200 | import sys
fin = sys.stdin
s = fin.readline().rstrip()[::-1]
t = fin.readline().rstrip()[::-1]
i = 0
m = min(len(s), len(t))
for i in range(m):
if s[i] != t[i]:
break
else:
i = m
print(len(s)+len(t)-2*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
import sys
fin = sys.stdin
s = fin.readline().rstrip()[::-1]
t = fin.readline().rstrip()[::-1]
i = 0
m = min(len(s), len(t))
for i in range(m):
if s[i] != t[i]:
break
else:
i = m
print(len(s)+len(t)-2*i)
``` | 3 | |
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the chi... | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space... | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
... | 1,620,694,133 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 6,656,000 | number = open("input.txt", "r")
letter = open("output.txt", "w")
a = int(number.readline())
b = number.readline()
for i in range(a//2):
if b[i] == 'L':
letter.write(str(i+1) + " " + str(i+1+b)+"\n")
elif b[i] == 'R':
letter.write(str(i+1+b) + " " +str(i+1)+"\n")
| Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t... | ```python
number = open("input.txt", "r")
letter = open("output.txt", "w")
a = int(number.readline())
b = number.readline()
for i in range(a//2):
if b[i] == 'L':
letter.write(str(i+1) + " " + str(i+1+b)+"\n")
elif b[i] == 'R':
letter.write(str(i+1+b) + " " +str(i+1)+"\n")
... | -1 | |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,593,170,182 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 20,172,800 | list1=[]
list2=[]
x=int(input())
for _ in range(x-1):
n=int(input())
if(n>0):
list1.append(n)
else:
list2.append(abs(n))
n=int(input())
if(n>0):
list1.append(n)
list3=["first"]
else:
list2.append(abs(n))
list3=["second"]
s1=sum(list1)
s2=sum(list2)
if(s1>s2)... | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
list1=[]
list2=[]
x=int(input())
for _ in range(x-1):
n=int(input())
if(n>0):
list1.append(n)
else:
list2.append(abs(n))
n=int(input())
if(n>0):
list1.append(n)
list3=["first"]
else:
list2.append(abs(n))
list3=["second"]
s1=sum(list1)
s2=sum(list2)
... | 0 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,631,283,464 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 248 | 20,172,800 | import math
arr = list(map(lambda x: int(x), input().split()))
a = math.sqrt((arr[0]*arr[1])/arr[2])
b = math.sqrt((arr[2]*arr[1])/arr[0])
c = math.sqrt((arr[2]*arr[0])/arr[1])
print(int(4*(a+b+c))) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
arr = list(map(lambda x: int(x), input().split()))
a = math.sqrt((arr[0]*arr[1])/arr[2])
b = math.sqrt((arr[2]*arr[1])/arr[0])
c = math.sqrt((arr[2]*arr[0])/arr[1])
print(int(4*(a+b+c)))
``` | 3 | |
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ... | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo... | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished... | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
... | 1,690,718,215 | 2,147,483,647 | Python 3 | OK | TESTS | 110 | 46 | 0 | def main():
p,s,max,ds,rr = map(int,input().split())
days = 1
speed = s
total=s
total=s
while total<p:
total-=rr
speed+=ds
if speed>max:
speed = max
total+=speed
days+=1
print(days)
main()
| Title: Mister B and Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ... | ```python
def main():
p,s,max,ds,rr = map(int,input().split())
days = 1
speed = s
total=s
total=s
while total<p:
total-=rr
speed+=ds
if speed>max:
speed = max
total+=speed
days+=1
print(days)
main()
``` | 3 | |
616 | A | Comparing Two Long Integers | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can r... | The first line contains a non-negative integer *a*.
The second line contains a non-negative integer *b*.
The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if *a*<=<<=*b* and the symbol ">" if *a*<=><=*b*. If the numbers are equal print the symbol "=". | [
"9\n10\n",
"11\n10\n",
"00012345\n12345\n",
"0123\n9\n",
"0123\n111\n"
] | [
"<\n",
">\n",
"=\n",
">\n",
">\n"
] | none | 0 | [
{
"input": "9\n10",
"output": "<"
},
{
"input": "11\n10",
"output": ">"
},
{
"input": "00012345\n12345",
"output": "="
},
{
"input": "0123\n9",
"output": ">"
},
{
"input": "0123\n111",
"output": ">"
},
{
"input": "9\n9",
"output": "="
},
{
... | 1,662,316,052 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 12,697,600 | import sys
readline=sys.stdin.readline
A=int(readline())
B=int(readline())
if A<B:
ans="<"
elif A>B:
ans=">"
else:
ans="="
print(ans) | Title: Comparing Two Long Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use th... | ```python
import sys
readline=sys.stdin.readline
A=int(readline())
B=int(readline())
if A<B:
ans="<"
elif A>B:
ans=">"
else:
ans="="
print(ans)
``` | 0 | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,667,874,866 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
P = list(map(int, input().split()))
def loveTr(planes):
for p in planes:
if planes[planes[planes[p - 1] - 1] - 1] == p:
return 'SÍ'
return 'NO'
print(loveTr(P))
| Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
n = int(input())
P = list(map(int, input().split()))
def loveTr(planes):
for p in planes:
if planes[planes[planes[p - 1] - 1] - 1] == p:
return 'SÍ'
return 'NO'
print(loveTr(P))
``` | -1 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,654,723,344 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | w = input()
init = 'a'
rot = 0
for c in w:
temp = abs(ord(c) - ord(init)) # no of clockwise rotations (n)
rot += temp if temp <= 13 else (26-temp) # if clockwise > 13 do (26 - n) anticlockwise rotations
init = c
print(rot)
| Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
w = input()
init = 'a'
rot = 0
for c in w:
temp = abs(ord(c) - ord(init)) # no of clockwise rotations (n)
rot += temp if temp <= 13 else (26-temp) # if clockwise > 13 do (26 - n) anticlockwise rotations
init = c
print(rot)
``` | 3 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,663,436,224 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 24 | 500 | 8,601,600 | numbers = list(map (int , input().split()))
arr = []
sum = 0
for i in range(0 , numbers[0]):
arr.append(0)
for i in range(0 , numbers[1]):
arr.sort()
x = list(map(int, input().split()))
counter = x[0]
cap = x[1]
for k in range(0 , len(arr)):
if arr[k] < cap and counter !=... | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
numbers = list(map (int , input().split()))
arr = []
sum = 0
for i in range(0 , numbers[0]):
arr.append(0)
for i in range(0 , numbers[1]):
arr.sort()
x = list(map(int, input().split()))
counter = x[0]
cap = x[1]
for k in range(0 , len(arr)):
if arr[k] < cap and ... | 0 |
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac... | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n... | 1,622,283,126 | 2,226 | Python 3 | OK | TESTS | 26 | 156 | 0 | number_of_testcases = 1 #int(input())
for _ in range(number_of_testcases):
number_of_points = int(input())
coordinates = [list(map(int,input().split())) for i in range(number_of_points)]
#print(coordinates)
num_supercentral_points = 0
for i in coordinates:
correct_set = 0
... | Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give... | ```python
number_of_testcases = 1 #int(input())
for _ in range(number_of_testcases):
number_of_points = int(input())
coordinates = [list(map(int,input().split())) for i in range(number_of_points)]
#print(coordinates)
num_supercentral_points = 0
for i in coordinates:
correct_set... | 3 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,679,900,306 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | l,a,v,n,d=map(int,(input()for _ in range(5)))
m=0
for i in range(1,d+1):
if i%l and i%a and i%v and i%n and i%d:
continue
else:
m+=1
print(m)
| Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
l,a,v,n,d=map(int,(input()for _ in range(5)))
m=0
for i in range(1,d+1):
if i%l and i%a and i%v and i%n and i%d:
continue
else:
m+=1
print(m)
``` | 0 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,587,825,162 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | s,p1,p2,t1,t2=map(int,input().split())
a=(s*p1)+(2*t1)
b=(s*p2)+(2*t2)
if(a<b):
print('First')
elif(b<a):
print('Second')
else:
print('Friendship')
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s,p1,p2,t1,t2=map(int,input().split())
a=(s*p1)+(2*t1)
b=(s*p2)+(2*t2)
if(a<b):
print('First')
elif(b<a):
print('Second')
else:
print('Friendship')
``` | 3 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,647,608,409 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n = int(input())
l1 = n // 2 - (1 if n % 2 == 0 else 0)
r = l1 + 1
i = 0 + (1 if n % 2 == 0 else 0)
ans = ['a' for _ in range(n)]
for el in input():
# print(el)
if i % 3 == 2:
ans[r] = el
r += 1
else:
ans[l1] = el
l1 -= 1
i += 1
# print(ans)
str1 = ""
... | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n = int(input())
l1 = n // 2 - (1 if n % 2 == 0 else 0)
r = l1 + 1
i = 0 + (1 if n % 2 == 0 else 0)
ans = ['a' for _ in range(n)]
for el in input():
# print(el)
if i % 3 == 2:
ans[r] = el
r += 1
else:
ans[l1] = el
l1 -= 1
i += 1
# print(ans)
s... | 0 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,660,325,101 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | def check(lst):
for i in range(len(lst)-1):
if lst[i] > lst[i+1]:
return False
return True
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(1,len(arr)+1): # Sub array length
for j in range(len(arr)):
sub_arr = arr[j:j+i]
if check(... | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
def check(lst):
for i in range(len(lst)-1):
if lst[i] > lst[i+1]:
return False
return True
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(1,len(arr)+1): # Sub array length
for j in range(len(arr)):
sub_arr = arr[j:j+i]
... | 0 | |
383 | A | Milking cows | PROGRAMMING | 1,600 | [
"data structures",
"greedy"
] | null | null | Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity o... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right. | Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4\n0 0 1 0\n",
"5\n1 0 1 0 1\n"
] | [
"1",
"3"
] | In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost. | 500 | [
{
"input": "4\n0 0 1 0",
"output": "1"
},
{
"input": "5\n1 0 1 0 1",
"output": "3"
},
{
"input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0",
"output": "416"
},
{
"input": "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 ... | 1,672,870,015 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 124 | 3,686,400 | n = int(input())
lst = list(map(int,input().split()))
res,s = 0,0
for i in lst:
if i == 0:
res+=s
else:
s+=1
print(res) | Title: Milking cows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub... | ```python
n = int(input())
lst = list(map(int,input().split()))
res,s = 0,0
for i in lst:
if i == 0:
res+=s
else:
s+=1
print(res)
``` | 3 | |
876 | B | Divisiblity of Differences | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number... | First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=... | If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them... | [
"3 2 3\n1 8 4\n",
"3 3 3\n1 8 4\n",
"4 3 5\n2 7 7 7\n"
] | [
"Yes\n1 4 ",
"No",
"Yes\n2 7 7 "
] | none | 1,000 | [
{
"input": "3 2 3\n1 8 4",
"output": "Yes\n1 4 "
},
{
"input": "3 3 3\n1 8 4",
"output": "No"
},
{
"input": "4 3 5\n2 7 7 7",
"output": "Yes\n2 7 7 "
},
{
"input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825",
"output":... | 1,508,369,627 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 452 | 14,950,400 | n, k, m = map(int, input().split())
a = list(map(int, input().split()))
ost = [[] for i in range(m)]
for i in range(n): ost[a[i]%m].append(a[i]);
for i in range(m):
if len(ost[i])>=k:
print('Yes')
for j in range(k): print(ost[i][j], end=' ');
exit(0)
print('No') | Title: Divisiblity of Differences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be re... | ```python
n, k, m = map(int, input().split())
a = list(map(int, input().split()))
ost = [[] for i in range(m)]
for i in range(n): ost[a[i]%m].append(a[i]);
for i in range(m):
if len(ost[i])>=k:
print('Yes')
for j in range(k): print(ost[i][j], end=' ');
exit(0)
print('No')
``` | 3 | |
290 | C | WTF? | PROGRAMMING | 1,700 | [
"*special",
"graph matchings",
"implementation",
"trees"
] | null | null | The input contains between 1 and 10 lines, *i*-th line contains an integer number *x**i* (0<=≤<=*x**i*<=≤<=9). | Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4. | [
"3\n0\n1\n1\n"
] | [
"0.666667\n"
] | none | 0 | [
{
"input": "3\n0\n1\n1",
"output": "0.666667"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0\n1",
"output": "0.5"
},
{
"input": "9\n0\n0\n0\n0\n0\n0\n0\n0\n1",
"output": "0.111111"
},
{
"input": "5\n1\n1\n1\... | 1,585,948,524 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = b = c = 0
d = 1
for _ in range(input()):
x = input()
a += x
b += 1
if a * d < b * c :
break
c , d = a , b
print c * 1. / d | Title: WTF?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains between 1 and 10 lines, *i*-th line contains an integer number *x**i* (0<=≤<=*x**i*<=≤<=9).
Output Specification:
Output a single real number. The answer is considered to be correct if it... | ```python
a = b = c = 0
d = 1
for _ in range(input()):
x = input()
a += x
b += 1
if a * d < b * c :
break
c , d = a , b
print c * 1. / d
``` | -1 | ||
964 | A | Splits | PROGRAMMING | 800 | [
"math"
] | null | null | Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
Th... | The first line contains one integer $n$ ($1 \leq n \leq 10^9$). | Output one integer — the answer to the problem. | [
"7\n",
"8\n",
"9\n"
] | [
"4\n",
"5\n",
"5\n"
] | In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | 500 | [
{
"input": "7",
"output": "4"
},
{
"input": "8",
"output": "5"
},
{
"input": "9",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "286",
"output": "144"
},
{
"input": "48",
"output": "25"
},
{
"input": "941",
"output": "471... | 1,523,976,315 | 2,414 | Python 3 | OK | TESTS | 63 | 93 | 7,065,600 | n = int(input())
sum = 0
sum = n//2 + 1
print(sum)
| Title: Splits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The foll... | ```python
n = int(input())
sum = 0
sum = n//2 + 1
print(sum)
``` | 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,673,716,016 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 1,075 | 9,113,600 | di={"Tetrahedron": 4 ,"Cube":6,"Octahedron":8 ,"Dodecahedron":12, "Icosahedron":20 }
n=int(input())
c=0
for i in range(n) :
s=input()
c+=di[s]
print(c)
| 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
di={"Tetrahedron": 4 ,"Cube":6,"Octahedron":8 ,"Dodecahedron":12, "Icosahedron":20 }
n=int(input())
c=0
for i in range(n) :
s=input()
c+=di[s]
print(c)
``` | 3 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,516,783,413 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 5,632,000 | ch=input("")
l=ch.split()
y=int(l[-1])
c=100
for i in range (0,int(l[0])):
x=int(input(""))
if (y%x==0):
m=y/x
if (m<c):
c=m
print(round(c))
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
ch=input("")
l=ch.split()
y=int(l[-1])
c=100
for i in range (0,int(l[0])):
x=int(input(""))
if (y%x==0):
m=y/x
if (m<c):
c=m
print(round(c))
``` | -1 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,627,113,445 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 6,963,200 | n = int(input())
s=input()
c=[]
i=0
if n%2==1:
c.append(s[i])
i+=1
n-=1
while i<n:
c.insert(0, s[i])
c.append(s[i+1])
i+=2
x=''.join(c)
print(x)
| Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n = int(input())
s=input()
c=[]
i=0
if n%2==1:
c.append(s[i])
i+=1
n-=1
while i<n:
c.insert(0, s[i])
c.append(s[i+1])
i+=2
x=''.join(c)
print(x)
``` | 3 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,695,239,242 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 15 | 77 | 0 | n=int(input())
count1=0
count2=0
for i in range(n):
m,c=list(map(int,input().split(" ")))
if m>c:
count1+=1
else:
count2+=1
if count1==count2:
print("Friendship is magic!^^")
else:
if count1>count2:
print("Mishka")
else:
print("Chris")
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n=int(input())
count1=0
count2=0
for i in range(n):
m,c=list(map(int,input().split(" ")))
if m>c:
count1+=1
else:
count2+=1
if count1==count2:
print("Friendship is magic!^^")
else:
if count1>count2:
print("Mishka")
else:
print(... | 0 | |
618 | E | Robot Arm | PROGRAMMING | 2,500 | [
"data structures",
"geometry"
] | null | null | Roger is a robot. He has an arm that is a series of *n* segments connected to each other. The endpoints of the *i*-th segment are initially located at points (*i*<=-<=1,<=0) and (*i*,<=0). The endpoint at (*i*<=-<=1,<=0) is colored red and the endpoint at (*i*,<=0) is colored blue for all segments. Thus, the blue endpo... | The first line of the input will contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300<=000) — the number of segments and the number of operations to perform.
Each of the next *m* lines contains three integers *x**i*, *y**i* and *z**i* describing a move. If *x**i*<==<=1, this line describes a move of type 1, where... | Print *m* lines. The *i*-th line should contain two real values, denoting the coordinates of the blue endpoint of the last segment after applying operations 1,<=...,<=*i*. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer for a part... | [
"5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1\n"
] | [
"8.0000000000 0.0000000000\n5.0000000000 -3.0000000000\n4.2568551745 -2.6691306064\n4.2568551745 -3.6691306064\n"
] | The following pictures shows the state of the arm after each operation. The coordinates of point *F* are printed after applying each operation. For simplicity, we only show the blue endpoints of a segment (with the exception for the red endpoint of the first segment). For instance, the point labeled *B* is the blue end... | 2,500 | [
{
"input": "5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1",
"output": "8.0000000000 0.0000000000\n5.0000000000 -3.0000000000\n4.2568551745 -2.6691306064\n4.2568551745 -3.6691306064"
},
{
"input": "1 1\n2 1 302",
"output": "0.5299192642 0.8480480962"
},
{
"input": "50 50\n1 41 261\n2 47 324\n1 41 256... | 1,454,092,000 | 4,600 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 8,000 | 11,776,000 | from math import sin, cos, hypot, pi
n, m = (int(i) for i in input().split())
xpos = list(range(n + 1))
ypos = [0] * (n + 1)
# count = 0
for i in range(m):
x, y, z = (int(i) for i in input().split())
if x == 1:
vecx = xpos[y] - xpos[y - 1]
vecy = ypos[y] - ypos[y - 1]
length = hypot(vec... | Title: Robot Arm
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roger is a robot. He has an arm that is a series of *n* segments connected to each other. The endpoints of the *i*-th segment are initially located at points (*i*<=-<=1,<=0) and (*i*,<=0). The endpoint at (*i*<=-<=1,<=0) is c... | ```python
from math import sin, cos, hypot, pi
n, m = (int(i) for i in input().split())
xpos = list(range(n + 1))
ypos = [0] * (n + 1)
# count = 0
for i in range(m):
x, y, z = (int(i) for i in input().split())
if x == 1:
vecx = xpos[y] - xpos[y - 1]
vecy = ypos[y] - ypos[y - 1]
length =... | 0 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,689,491,884 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | w = input().replace("WUB", " ")
w = [_ for _ in w.split() if _]
print(" ".join(w))
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
w = input().replace("WUB", " ")
w = [_ for _ in w.split() if _]
print(" ".join(w))
``` | 3 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,592,062,414 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 0 | #!/usr/bin/env python
lst = list(map(int, input().split(' ')))
buckets = list(map(int, input().split(' ')))
no_of_buckets = lst[0]
length_garden = lst[1]
for i in range(no_of_buckets-1,-1, -1):
if length_garden % buckets[i] == 0:
print(length_garden//buckets[i])
break
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
#!/usr/bin/env python
lst = list(map(int, input().split(' ')))
buckets = list(map(int, input().split(' ')))
no_of_buckets = lst[0]
length_garden = lst[1]
for i in range(no_of_buckets-1,-1, -1):
if length_garden % buckets[i] == 0:
print(length_garden//buckets[i])
break
``` | 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,681,287,923 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | def long(n):
if len(n)<=10:
return n
else:
return n[0] + str(len(n)-2) + n[len(n)-1]
n=int(input())
L=[]
for j in range(n):
l=input()
L.append(long(l))
for k in L:
print(k)
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
def long(n):
if len(n)<=10:
return n
else:
return n[0] + str(len(n)-2) + n[len(n)-1]
n=int(input())
L=[]
for j in range(n):
l=input()
L.append(long(l))
for k in L:
print(k)
``` | 3.977 |
949 | A | Zebras | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o... | In the only line of input data there is a non-empty string *s* consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |*s*|) does not exceed 200<=000 characters. | If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer *k* (1<=≤<=*k*<=≤<=|*s*|), the resulting number of subsequences. In the *i*-th of following *k* lines first print the integer *l**i* (1<=≤<=*l**i*<=≤<=|*s*|), which is the length of the *i*-th subsequenc... | [
"0010100\n",
"111\n"
] | [
"3\n3 1 3 4\n3 2 5 6\n1 7\n",
"-1\n"
] | none | 500 | [
{
"input": "0010100",
"output": "3\n1 1\n5 2 3 4 5 6\n1 7"
},
{
"input": "111",
"output": "-1"
},
{
"input": "0",
"output": "1\n1 1"
},
{
"input": "1",
"output": "-1"
},
{
"input": "0101010101",
"output": "-1"
},
{
"input": "010100001",
"output": "... | 1,653,927,101 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 545 | 39,424,000 |
from collections import deque
def zebras(s):
zbs=[]
alzbs=[]
for i in range(n):
if s[i]=='0':
if not alzbs:
zbs.append([i+1])
else:
tmp=alzbs.pop()
tmp.append(i+1)
zbs.append(tmp)
... | Title: Zebras
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alter... | ```python
from collections import deque
def zebras(s):
zbs=[]
alzbs=[]
for i in range(n):
if s[i]=='0':
if not alzbs:
zbs.append([i+1])
else:
tmp=alzbs.pop()
tmp.append(i+1)
zbs.append(tmp)
... | 3 | |
81 | A | Plug-in | PROGRAMMING | 1,400 | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | 500 | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"... | 1,685,037,179 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 5,324,800 | def remove_duplicates(s):
st = []
for char in s[::-1]:
if st and st[-1] == char:
st.pop()
else:
st.append(char)
return ''.join(st[::-1])
s = input()
ans = remove_duplicates(s)
print(ans)
| Title: Plug-in
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed... | ```python
def remove_duplicates(s):
st = []
for char in s[::-1]:
if st and st[-1] == char:
st.pop()
else:
st.append(char)
return ''.join(st[::-1])
s = input()
ans = remove_duplicates(s)
print(ans)
``` | 3.928082 |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
... | 1,517,831,872 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 5,632,000 | #862A
n,x=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(x+1):
for j in range(i,x-1):
if i-j in b or x+1 not in b:
b.append(x+1)
count=count+1
if x in b:
count=count+1
print(count) | Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in ... | ```python
#862A
n,x=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(x+1):
for j in range(i,x-1):
if i-j in b or x+1 not in b:
b.append(x+1)
count=count+1
if x in b:
count=count+1
print(count)
``` | 0 | |
834 | A | The Useless Toy | PROGRAMMING | 900 | [
"implementation"
] | null | null | Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each s... | There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated... | Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise. | [
"^ >\n1\n",
"< ^\n3\n",
"^ v\n6\n"
] | [
"cw\n",
"ccw\n",
"undefined\n"
] | none | 500 | [
{
"input": "^ >\n1",
"output": "cw"
},
{
"input": "< ^\n3",
"output": "ccw"
},
{
"input": "^ v\n6",
"output": "undefined"
},
{
"input": "^ >\n999999999",
"output": "ccw"
},
{
"input": "> v\n1",
"output": "cw"
},
{
"input": "v <\n1",
"output": "cw"
... | 1,501,426,358 | 1,058 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 62 | 4,608,000 | pos=input().split()
p1=0;
p2=0
if(pos[0]=='^'): p1=1
if(pos[0]=='>'): p1=2
if(pos[0]=='v'): p1=3
if(pos[0]=='<'): p1=4
if(pos[1]=='^'): p2=1
if(pos[1]=='>'): p2=2
if(pos[1]=='v'): p2=3
if(pos[1]=='<'): p2=4
s=int(input())
s=s%4;
if((p1+s)%4==(p1-s)%4):
print('undefined')
elif((p1+s)%4==p2):
prin... | Title: The Useless Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bough... | ```python
pos=input().split()
p1=0;
p2=0
if(pos[0]=='^'): p1=1
if(pos[0]=='>'): p1=2
if(pos[0]=='v'): p1=3
if(pos[0]=='<'): p1=4
if(pos[1]=='^'): p2=1
if(pos[1]=='>'): p2=2
if(pos[1]=='v'): p2=3
if(pos[1]=='<'): p2=4
s=int(input())
s=s%4;
if((p1+s)%4==(p1-s)%4):
print('undefined')
elif((p1+s)%4==p2):... | 0 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,672,566,575 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 122 | 0 | import math
a, b, c = map(int, input().split(' '))
print(int(4 * (a * b + b * c + a * c) * math.sqrt(a * b * c) / (a * b * c)))
| Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
a, b, c = map(int, input().split(' '))
print(int(4 * (a * b + b * c + a * c) * math.sqrt(a * b * c) / (a * b * c)))
``` | 3 | |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,620,218,805 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | from math import *
k,n,s,p = [int(x) for x in input().split()]
#print(k,n,s,p)
val = ceil(n/s)
#print(val)
pack = (k*val)/p
print(int(pack)) | Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p... | ```python
from math import *
k,n,s,p = [int(x) for x in input().split()]
#print(k,n,s,p)
val = ceil(n/s)
#print(val)
pack = (k*val)/p
print(int(pack))
``` | 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,554,183 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
m = [0]*n
for i in range(n):
m[i] = input()
for i in range(len(m)):
if len(m[i]) > 10:
print(str(m[i][0]) + str(len(m[i])-2) + str(m[i][-1]))
else:
print(m[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 = int(input())
m = [0]*n
for i in range(n):
m[i] = input()
for i in range(len(m)):
if len(m[i]) > 10:
print(str(m[i][0]) + str(len(m[i])-2) + str(m[i][-1]))
else:
print(m[i])
``` | 3.977 |
828 | B | Black Square | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum pos... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | [
"5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n",
"1 2\nBB\n",
"3 3\nWWW\nWWW\nWWW\n"
] | [
"5\n",
"-1\n",
"1\n"
] | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | 750 | [
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW",
"output": "5"
},
{
"input": "1 2\nBB",
"output": "-1"
},
{
"input": "3 3\nWWW\nWWW\nWWW",
"output": "1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n... | 1,521,103,052 | 2,147,483,647 | Python 3 | OK | TESTS | 128 | 545 | 5,836,800 | ##n = int(input())
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
def list_input():
return list(map(int, input().split()))
[n, m] = list_input()
cell = list()
for i in range(n):
cell.append(input())
ps = [[0 for j in range(m+1)] for i in range(n+1)]
for i in range(n):
... | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of w... | ```python
##n = int(input())
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
def list_input():
return list(map(int, input().split()))
[n, m] = list_input()
cell = list()
for i in range(n):
cell.append(input())
ps = [[0 for j in range(m+1)] for i in range(n+1)]
for i in range... | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,665,534,204 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | # -*- coding: utf-8 -*-
"""
Created on Wed Oct 12 00:02:42 2022
@author: SaltLyy
"""
n=int(input())
x=[int(x)%2 for x in input().split()]
if sum(x) == 1:
print(x.index(1))
elif sum(x) == n-1:
print(x.index(0))
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 12 00:02:42 2022
@author: SaltLyy
"""
n=int(input())
x=[int(x)%2 for x in input().split()]
if sum(x) == 1:
print(x.index(1))
elif sum(x) == n-1:
print(x.index(0))
``` | 0 |
270 | B | Multithreading | PROGRAMMING | 1,400 | [
"data structures",
"greedy",
"implementation"
] | null | null | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of *n* different threads ordered by the time of the latest message in the threa... | The first line of input contains an integer *n*, the number of threads (1<=≤<=*n*<=≤<=105). The next line contains a list of *n* space-separated integers *a*1, *a*2, ..., *a**n* where *a**i* (1<=≤<=*a**i*<=≤<=*n*) is the old position of the *i*-th thread in the new list. It is guaranteed that all of the *a**i* are dist... | Output a single integer — the number of threads that surely contain a new message. | [
"5\n5 2 1 3 4\n",
"3\n1 2 3\n",
"4\n4 3 2 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.
In the second test case, there may be no new messages at all, since the thread order hasn't changed.
In the thi... | 1,500 | [
{
"input": "5\n5 2 1 3 4",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "4\n4 3 2 1",
"output": "3"
},
{
"input": "5\n1 2 5 3 4",
"output": "3"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
... | 1,649,821,376 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | input()
threads = list(map(int, input().split(" ")))
answer = threads.index(1)
print(answer)
| Title: Multithreading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent ... | ```python
input()
threads = list(map(int, input().split(" ")))
answer = threads.index(1)
print(answer)
``` | 0 | |
79 | C | Beaver | PROGRAMMING | 1,800 | [
"data structures",
"dp",
"greedy",
"hashing",
"strings",
"two pointers"
] | C. Beaver | 2 | 256 | After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string *s*, and she tried to remember the string *s* correctly.
However, Ciel... | In the first line there is a string *s*. The length of *s* will be between 1 and 105, inclusive.
In the second line there is a single integer *n* (1<=≤<=*n*<=≤<=10). Next *n* lines, there is a string *b**i* (1<=≤<=*i*<=≤<=*n*). Each length of *b**i* will be between 1 and 10, inclusive.
Each character of the given st... | Output in the first line two space-separated integers *len* and *pos*: the length of the longest contiguous substring of *s* that does not contain any *b**i*, and the first position of the substring (0-indexed). The position *pos* must be between 0 and |*s*|<=-<=*len* inclusive, where |*s*| is the length of string *s*.... | [
"Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse\n",
"IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd\n",
"unagioisii\n2\nioi\nunagi\n"
] | [
"12 4\n",
"0 0\n",
"5 5\n"
] | In the first sample, the solution is traight_alon.
In the second sample, the solution is an empty string, so the output can be «0 0», «0 1», «0 2», and so on.
In the third sample, the solution is either nagio or oisii. | 1,500 | [
{
"input": "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse",
"output": "12 4"
},
{
"input": "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd",
"output": "0 0"
},
{
"input": "unagioisii\n2\nioi\nunagi",
"output": "5 5"
},
{
"input": "abcabcabcabc\n3\nabcabca\... | 1,629,035,345 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 6,963,200 | s,r,q=input(),[],{}
for i in range(int(input())):
p=input()
o=len(p)
for j in range(len(s)):
if s[j:j+o]==p:r+=[[j,j+o-1]]
r.sort(key=lambda x:x[0])
r+=[[0,len(s)-1]]
for i in range(len(r)-1):q[r[i+1][1]-r[i][0]-1]=r[i][0]+1
print(max(q),q[max(q)]) | Title: Beaver
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to ... | ```python
s,r,q=input(),[],{}
for i in range(int(input())):
p=input()
o=len(p)
for j in range(len(s)):
if s[j:j+o]==p:r+=[[j,j+o-1]]
r.sort(key=lambda x:x[0])
r+=[[0,len(s)-1]]
for i in range(len(r)-1):q[r[i+1][1]-r[i][0]-1]=r[i][0]+1
print(max(q),q[max(q)])
``` | 0 |
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs som... | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaran... | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1... | 1,587,977,931 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 310 | 7,372,800 | n, s, t = map(int, input().split())
a = [0] + [int(x) for x in input().split()]
if s==t:
print("0")
else:
count = 0
found = False
temp = s
while(a[temp]!=s):
count += 1
temp = a[temp]
if temp == t:
found = True
break
if found:
... | Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ... | ```python
n, s, t = map(int, input().split())
a = [0] + [int(x) for x in input().split()]
if s==t:
print("0")
else:
count = 0
found = False
temp = s
while(a[temp]!=s):
count += 1
temp = a[temp]
if temp == t:
found = True
break
if foun... | 3 | |
567 | C | Geometric Progression | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"dp"
] | null | null | Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers.
He wants to know how many subsequences of length three can be selected from *a*, so that they form a geo... | The first line of the input contains two integers, *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of the sequence. | Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*. | [
"5 2\n1 1 2 2 4\n",
"3 1\n1 1 1\n",
"10 3\n1 2 6 2 3 6 9 18 3 9\n"
] | [
"4",
"1",
"6"
] | In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4. | 1,500 | [
{
"input": "5 2\n1 1 2 2 4",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "1"
},
{
"input": "10 3\n1 2 6 2 3 6 9 18 3 9",
"output": "6"
},
{
"input": "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "5 3\n5 15 15 15 45... | 1,618,034,305 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 405 | 22,630,400 | n , k = map(int, input().split())
arr = list(map(int, input().split()))
counter = 0
# To store no.of every element occurrence.
element_occurrence = {}
# To store no.of every element occurrence which has a valid value (Geometric Progression) .
# this store How many time this element valid to be used in Geo... | Title: Geometric Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers... | ```python
n , k = map(int, input().split())
arr = list(map(int, input().split()))
counter = 0
# To store no.of every element occurrence.
element_occurrence = {}
# To store no.of every element occurrence which has a valid value (Geometric Progression) .
# this store How many time this element valid to be u... | 3 | |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,600,898,398 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 |
n,m = map(int,input().split())
t=[]
for k in range(n):
t.append(list(map(int,input().split())))
if t[0][0]>0:
print('NO')
else:
for k in range(n):
if k!=n-1:
if t[k][1]>=t[k+1][0]:
if t[k][1]>=m:
print('YES')
... | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
n,m = map(int,input().split())
t=[]
for k in range(n):
t.append(list(map(int,input().split())))
if t[0][0]>0:
print('NO')
else:
for k in range(n):
if k!=n-1:
if t[k][1]>=t[k+1][0]:
if t[k][1]>=m:
print('YES')
... | 0 | |
514 | B | Han Solo and Lazer Gun | PROGRAMMING | 1,400 | [
"brute force",
"data structures",
"geometry",
"implementation",
"math"
] | null | null | There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot... | The first line contains three integers *n*, *x*0 и *y*0 (1<=≤<=*n*<=≤<=1000, <=-<=104<=≤<=*x*0,<=*y*0<=≤<=104) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next *n* lines contain two integers each *x**i*, *y**i* (<=-<=104<=≤<=*x**i*,<=*y**i*<=≤<=104) — the coordinates of the storm... | Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. | [
"4 0 0\n1 1\n2 2\n2 0\n-1 -1\n",
"2 1 2\n1 1\n1 0\n"
] | [
"2\n",
"1\n"
] | Explanation to the first and second samples from the statement, respectively: | 1,000 | [
{
"input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1",
"output": "2"
},
{
"input": "2 1 2\n1 1\n1 0",
"output": "1"
},
{
"input": "1 1 1\n0 0",
"output": "1"
},
{
"input": "2 0 0\n10000 -10000\n-10000 10000",
"output": "1"
},
{
"input": "2 0 0\n10000 -10000\n10000 10000",
... | 1,667,284,265 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | K=set()
X=[]
n,x0,y0=map(int,input().split())
for i in range(n):
X.append(list(map(int,input().split())))
for i in range(n):
K.add(float((X[i][1]-y0)/X[i][0]-x0))
print(len(K))
| Title: Han Solo and Lazer Gun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane.
Han Solo has the ... | ```python
K=set()
X=[]
n,x0,y0=map(int,input().split())
for i in range(n):
X.append(list(map(int,input().split())))
for i in range(n):
K.add(float((X[i][1]-y0)/X[i][0]-x0))
print(len(K))
``` | 0 | |
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,694,162,679 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | s=input()
s1=s.lower()
vowels=['a','e','i','o','u','y']
res=""
for i in s1:
if i not in vowels:
res+='.'
res+=i
print(res) | 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()
s1=s.lower()
vowels=['a','e','i','o','u','y']
res=""
for i in s1:
if i not in vowels:
res+='.'
res+=i
print(res)
``` | 3 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,689,352,367 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | n, k = map(int, input().split())
answer = 0
for i in range(n):
a = input()
if int(a[len(a) - 1]) < k:
answer += 1
print(answer)
| Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n, k = map(int, input().split())
answer = 0
for i in range(n):
a = input()
if int(a[len(a) - 1]) < k:
answer += 1
print(answer)
``` | 0 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,671,875,360 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | n = int(input())
lst = []
for i in range(n):
s = input()
lst.append(s)
lst = set(lst)
print(len(lst))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
n = int(input())
lst = []
for i in range(n):
s = input()
lst.append(s)
lst = set(lst)
print(len(lst))
``` | 3.977 |
797 | C | Minimal string | PROGRAMMING | 1,700 | [
"data structures",
"greedy",
"strings"
] | null | null | Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u*... | First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. | Print resulting string *u*. | [
"cab\n",
"acdb\n"
] | [
"abc\n",
"abdc\n"
] | none | 0 | [
{
"input": "cab",
"output": "abc"
},
{
"input": "acdb",
"output": "abdc"
},
{
"input": "a",
"output": "a"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "dijee",
"output": "deeji"
},
{
"input": "bhrmc",
... | 1,639,559,744 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 1,331,200 | s=input()
s1=[]
s2=""
for i in range(len(s)):
if s[i]==min(s[i:]):
s2=s2+s[i]
else :
s1.append(s[i])
for i in range(len(s1)):
s2=s2+(s1.pop())
print(s2)
| Title: Minimal string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first char... | ```python
s=input()
s1=[]
s2=""
for i in range(len(s)):
if s[i]==min(s[i:]):
s2=s2+s[i]
else :
s1.append(s[i])
for i in range(len(s1)):
s2=s2+(s1.pop())
print(s2)
``` | 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,686,765,827 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n=int(input())
lst=list(map(int,input().split()))
m=abs(lst[0]-lst[1])
a,b=0,1
for i in range(1,n-1):
d=abs(lst[i]-lst[i+1])
if(d<m):
a,b=i,i+1
l=abs(lst[-1]-lst[0])
if(l<m):
a,b=n-1,0
print(a+1,b+1) | 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())
lst=list(map(int,input().split()))
m=abs(lst[0]-lst[1])
a,b=0,1
for i in range(1,n-1):
d=abs(lst[i]-lst[i+1])
if(d<m):
a,b=i,i+1
l=abs(lst[-1]-lst[0])
if(l<m):
a,b=n-1,0
print(a+1,b+1)
``` | 0 |
201 | A | Clear Symmetry | PROGRAMMING | 1,700 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the *i*-row and the *j*-th col... | The only line contains a single integer *x* (1<=≤<=*x*<=≤<=100) — the required sharpness of the matrix. | Print a single number — the sought value of *n*. | [
"4\n",
"9\n"
] | [
"3\n",
"5\n"
] | The figure below shows the matrices that correspond to the samples: | 1,000 | [
{
"input": "4",
"output": "3"
},
{
"input": "9",
"output": "5"
},
{
"input": "10",
"output": "5"
},
{
"input": "12",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "19",
"output": "7"
},
{
"input": "3",
"output": "5"
},
... | 1,669,899,702 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | x=int(input())
n=1
#一定是奇数边
while n*n+1<x:n+=2
print(n if x!=3 else 5) | Title: Clear Symmetry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll den... | ```python
x=int(input())
n=1
#一定是奇数边
while n*n+1<x:n+=2
print(n if x!=3 else 5)
``` | 0 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,685,334,662 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 77 | 0 | n, m = map(int, input().split())
flag = True
for i in range(1, n + 1):
if i % 2 == 0 and flag:
print('.' * (m - 1) + '#')
flag = False
elif i % 2 == 0 and not flag:
print('#' + '.' * (m - 1))
flag = True
else:
print('#' * m)
| 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())
flag = True
for i in range(1, n + 1):
if i % 2 == 0 and flag:
print('.' * (m - 1) + '#')
flag = False
elif i % 2 == 0 and not flag:
print('#' + '.' * (m - 1))
flag = True
else:
print('#' * m)
``` | 3 | |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,694,028,285 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | x1,y1,x2,y2=map(int,input().split())
if(x1!=x2 and y1==y2):
d=abs(x1-x2)
print(x1,y1+d,x2,y2+d)
elif(y1!=y2 and x1==x2):
d=abs(y1-y2)
print(x1+d,y1,x2+d,y2)
else:
print(x1,y2,x2,y1) | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
x1,y1,x2,y2=map(int,input().split())
if(x1!=x2 and y1==y2):
d=abs(x1-x2)
print(x1,y1+d,x2,y2+d)
elif(y1!=y2 and x1==x2):
d=abs(y1-y2)
print(x1+d,y1,x2+d,y2)
else:
print(x1,y2,x2,y1)
``` | 0 | |
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO"... | 1,667,531,073 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 46 | 0 | n=input()
if n==n[::-1] and "Z" not in n and "S" not in n and "R" not in n and "Q" not in n and "P" not in n and "N" not in n and "L" not in n and "K" not in n and "J" not in n and "G" not in n and "F" not in n and "E" not in n and "D" not in n and "C" not in n and "B" not in n: print("YES")
else: print("NO") | Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of ... | ```python
n=input()
if n==n[::-1] and "Z" not in n and "S" not in n and "R" not in n and "Q" not in n and "P" not in n and "N" not in n and "L" not in n and "K" not in n and "J" not in n and "G" not in n and "F" not in n and "E" not in n and "D" not in n and "C" not in n and "B" not in n: print("YES")
else: print("NO... | 3 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,546,079,821 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 0 | input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [element for element in a if element in b]
for i in c:
print(i, end=' ')
| Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [element for element in a if element in b]
for i in c:
print(i, end=' ')
``` | 3 | |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,537,982,474 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 |
# coding: utf-8
# In[ ]:
def Suffix(t,s):
if t==s[:len(t)]:
return True
return False
def Preffix(t,s):
if t==s[-len(t):]:
return True
return False
def Obelix(t,s):
obel=s[len(t):-len(t)]
if t in obel:
return True
return False
def Password(s):
for i in range(le... | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
# coding: utf-8
# In[ ]:
def Suffix(t,s):
if t==s[:len(t)]:
return True
return False
def Preffix(t,s):
if t==s[-len(t):]:
return True
return False
def Obelix(t,s):
obel=s[len(t):-len(t)]
if t in obel:
return True
return False
def Password(s):
for i i... | 0 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,617,979,334 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 622 | 7,577,600 | def solution():
n=int(input())
k=[]
mn=float('Inf')
mx=float('-Inf')
for i in range(n):
l,r=map(int,input().split())
k.append((l,r))
mn=min(l,mn)
mx=max(r, mx)
for i in range(n):
if k[i][0]==mn and k[i][1]==mx:
print(i+1)
return
print(-1)
return
solution()
| Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
def solution():
n=int(input())
k=[]
mn=float('Inf')
mx=float('-Inf')
for i in range(n):
l,r=map(int,input().split())
k.append((l,r))
mn=min(l,mn)
mx=max(r, mx)
for i in range(n):
if k[i][0]==mn and k[i][1]==mx:
print(i+1)
return
print(-1)
return
solution()
``` | 3 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,694,965,566 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n,t = map(int,input().split())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
t -= 86400 - l[i]
ans += 1
if t == 0:
break
print(ans) | Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n,t = map(int,input().split())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
t -= 86400 - l[i]
ans += 1
if t == 0:
break
print(ans)
``` | 0 | |
678 | B | The Same Calendar | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ... | The only line contains integer *y* (1000<=≤<=*y*<=<<=100'000) — the year of the calendar. | Print the only integer *y*' — the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar. | [
"2016\n",
"2000\n",
"50501\n"
] | [
"2044\n",
"2028\n",
"50507\n"
] | Today is Monday, the 13th of June, 2016. | 0 | [
{
"input": "2016",
"output": "2044"
},
{
"input": "2000",
"output": "2028"
},
{
"input": "50501",
"output": "50507"
},
{
"input": "1000",
"output": "1006"
},
{
"input": "1900",
"output": "1906"
},
{
"input": "1899",
"output": "1905"
},
{
"i... | 1,531,920,911 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
if(n%4==0):
print(n+28)
else if(n%4==1 or n%4==2):
print(n+6)
else if(n%4==3):
print(n+11) | Title: The Same Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful t... | ```python
n=int(input())
if(n%4==0):
print(n+28)
else if(n%4==1 or n%4==2):
print(n+6)
else if(n%4==3):
print(n+11)
``` | -1 | |
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<... | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t... | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5... | 1,699,426,025 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 716 | 9,523,200 | s = input()
m = int(input())
ans = []
n = len(s)
dp = [0 for _ in range(n)]
t = 0
for i in range(1, n):
if s[i] == s[i - 1]:
t += 1
dp[i] = t
for _ in range(m):
l, r = map(int, input().split())
t = dp[r - 1] - dp[l - 1]
ans.append(t)
for j in range(m):
print(ans[j]) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ... | ```python
s = input()
m = int(input())
ans = []
n = len(s)
dp = [0 for _ in range(n)]
t = 0
for i in range(1, n):
if s[i] == s[i - 1]:
t += 1
dp[i] = t
for _ in range(m):
l, r = map(int, input().split())
t = dp[r - 1] - dp[l - 1]
ans.append(t)
for j in range(m):
print(... | 3 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,672,438,602 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n, m = [int(i) for i in input().split()]
l = m
k = [int(i) for i in input().split()]
mn = sum(k[:m])
p = 0
for i in range(0, n-m):
if n-i < m:
m = n-i
if mn > mn - k[i]+k[i+m]:
mn = mn - k[i]+k[i+m]
p = i
if mn == m:
break
print(p+2) | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n, m = [int(i) for i in input().split()]
l = m
k = [int(i) for i in input().split()]
mn = sum(k[:m])
p = 0
for i in range(0, n-m):
if n-i < m:
m = n-i
if mn > mn - k[i]+k[i+m]:
mn = mn - k[i]+k[i+m]
p = i
if mn == m:
break
print(p+2)
``` | 0 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,570,713,373 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 342 | 409,600 | from sys import stdin
from collections import defaultdict
n=int(stdin.readline().rstrip())
df=defaultdict(int)
for i in range(n):
s=stdin.readline().rstrip()
df[s]+=1
m=0
p=""
for i in df.keys():
if m<df[i]:
p=i
m=df[i]
print(p) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
from sys import stdin
from collections import defaultdict
n=int(stdin.readline().rstrip())
df=defaultdict(int)
for i in range(n):
s=stdin.readline().rstrip()
df[s]+=1
m=0
p=""
for i in df.keys():
if m<df[i]:
p=i
m=df[i]
print(p)
``` | 3.913737 |
587 | A | Duff and Weight Lifting | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values. | Print the minimum number of steps in a single line. | [
"5\n1 1 2 3 3\n",
"4\n0 1 2 3\n"
] | [
"2\n",
"4\n"
] | In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not po... | 500 | [
{
"input": "5\n1 1 2 3 3",
"output": "2"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "1\n120287",
"output": "1"
},
{
"input": "2\n28288 0",
"output": "2"
},
{
"input": "2\n95745 95745",
"output": "1"
},
{
"input": "13\n92 194 580495 0 10855... | 1,689,003,552 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 77 | 2,764,800 |
from collections import *
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
def read_array(factory):
return [factory(num) for num in input().strip().split()]
def print_array(arr):
print(" ".join(map(str, arr)))
def bit_count(x):
ans = 0
while x > 0:
x &= x-1
ans += 1
return a... | Title: Duff and Weight Lifting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of th... | ```python
from collections import *
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
def read_array(factory):
return [factory(num) for num in input().strip().split()]
def print_array(arr):
print(" ".join(map(str, arr)))
def bit_count(x):
ans = 0
while x > 0:
x &= x-1
ans += 1
... | -1 | |
113 | A | Grammar Lessons | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | A. Grammar Lessons | 5 | 256 | Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:
- There are three parts of spee... | The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.
It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible tha... | If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). | [
"petr\n",
"etis atis animatis etis atis amatis\n",
"nataliala kataliala vetra feinites\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "petr",
"output": "YES"
},
{
"input": "etis atis animatis etis atis amatis",
"output": "NO"
},
{
"input": "nataliala kataliala vetra feinites",
"output": "YES"
},
{
"input": "qweasbvflios",
"output": "YES"
},
{
"input": "lios lios petr initis qwe",
... | 1,574,235,999 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | s = input()
a = s.find("AB")
b = s.find("BA")
if(abs(a-b)>=2 and (a!=-1 and b!=-1)):
print("YES")
else:
print("NO")
| Title: Grammar Lessons
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the lang... | ```python
s = input()
a = s.find("AB")
b = s.find("BA")
if(abs(a-b)>=2 and (a!=-1 and b!=-1)):
print("YES")
else:
print("NO")
``` | 0 |
888 | A | Local Extrema | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=><=*... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*. | Print the number of local extrema in the given array. | [
"3\n1 2 3\n",
"4\n1 5 2 5\n"
] | [
"0\n",
"2\n"
] | none | 0 | [
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "4\n1 5 2 5",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n548",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n3 2 3",
"output": "1"
},
{
"inp... | 1,690,349,327 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 46 | 0 | a=int(input())
l=list(map(int,input().split()))
p=0
for k in range(1,a-1):
if l[k-1]<l[k] and l[k]>l[k+1]:
p+=1
elif l[k-1]>l[k] and l[k]<l[k+1]:
p+=1
print(p)
| Title: Local Extrema
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element c... | ```python
a=int(input())
l=list(map(int,input().split()))
p=0
for k in range(1,a-1):
if l[k-1]<l[k] and l[k]>l[k+1]:
p+=1
elif l[k-1]>l[k] and l[k]<l[k+1]:
p+=1
print(p)
``` | 3 | |
522 | B | Photo to Remember | PROGRAMMING | 1,100 | [
"*special",
"data structures",
"dp",
"implementation"
] | null | null | One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangl... | The first line contains integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of friends.
Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=10,<=1<=≤<=*h**i*<=≤<=1000) — the width and height in pixels of the correspo... | Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* — the total number of pixels on the minimum photo containing all friends expect for the *i*-th one. | [
"3\n1 10\n5 5\n10 1\n",
"3\n2 1\n1 2\n2 1\n"
] | [
"75 110 60 ",
"6 4 6 "
] | none | 1,000 | [
{
"input": "3\n1 10\n5 5\n10 1",
"output": "75 110 60 "
},
{
"input": "3\n2 1\n1 2\n2 1",
"output": "6 4 6 "
},
{
"input": "2\n1 5\n2 3",
"output": "6 5 "
},
{
"input": "2\n2 3\n1 1",
"output": "1 6 "
},
{
"input": "3\n1 10\n2 10\n3 10",
"output": "50 40 30 "
... | 1,457,629,812 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 2,000 | 19,865,600 | def read_data():
n = int(input())
data = []
for i in range(0, n):
data.append([int(x) for x in input().split(" ")])
return data
def foo(data):
g_width = []
g_height = []
for row in data:
g_width.append(row[0])
g_height.append(row[1])
g_width = sum(g_width)
... | Title: Photo to Remember
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the p... | ```python
def read_data():
n = int(input())
data = []
for i in range(0, n):
data.append([int(x) for x in input().split(" ")])
return data
def foo(data):
g_width = []
g_height = []
for row in data:
g_width.append(row[0])
g_height.append(row[1])
g_width = sum(g_w... | 0 | |
578 | B | "Or" Game | PROGRAMMING | 1,700 | [
"brute force",
"greedy"
] | null | null | You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR.
Find the maximum possible value of after performing at most *k* operations optimally. | The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output the maximum value of a bitwise OR of sequence elements after performing operations. | [
"3 1 2\n1 1 1\n",
"4 2 3\n1 2 4 8\n"
] | [
"3\n",
"79\n"
] | For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample... | 500 | [
{
"input": "3 1 2\n1 1 1",
"output": "3"
},
{
"input": "4 2 3\n1 2 4 8",
"output": "79"
},
{
"input": "2 1 2\n12 9",
"output": "30"
},
{
"input": "2 1 2\n12 7",
"output": "31"
},
{
"input": "3 1 3\n3 2 0",
"output": "11"
},
{
"input": "5 10 8\n10000000... | 1,517,357,022 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,632,000 | import sys
[n,k,x] = [int(i) for i in sys.stdin.readline().rstrip('\n').split()]
nums = [int(i) for i in sys.stdin.readline().rstrip('\n').split()]
m = max(nums)
nums.remove(m)
for i in range(k):
m = m*x
ans = m
for i in nums:
ans = ans|i
sys.stdout.write(str(ans)+'\n') | Title: "Or" Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR... | ```python
import sys
[n,k,x] = [int(i) for i in sys.stdin.readline().rstrip('\n').split()]
nums = [int(i) for i in sys.stdin.readline().rstrip('\n').split()]
m = max(nums)
nums.remove(m)
for i in range(k):
m = m*x
ans = m
for i in nums:
ans = ans|i
sys.stdout.write(str(ans)+'\n')
``` | 0 | |
682 | B | Alyona and Mex | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | [
"5\n1 3 3 3 6\n",
"2\n2 1\n"
] | [
"5\n",
"3\n"
] | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | 1,000 | [
{
"input": "5\n1 3 3 3 6",
"output": "5"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "1\n1000000000",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"... | 1,520,952,026 | 2,147,483,647 | Python 3 | OK | TESTS | 127 | 155 | 14,438,400 | input();m=1
for i in (sorted(list(map(int,input().split())))):
if i>=m:m+=1
print(m)
| Title: Alyona and Mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is small... | ```python
input();m=1
for i in (sorted(list(map(int,input().split())))):
if i>=m:m+=1
print(m)
``` | 3 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,671,555,031 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | a=int(input())
org=input()
goal=input()
count=0
re=0
for i in range(a):
if(int(org[i])>int(goal[i])):
re=min(int(org[i])-int(goal[i]) ,10-int(org[i])+int(goal[i]))
elif(int(org[i]) < int(goal[i])) :
re=min(int(goal[i])-int(org[i]), 10-int(goal[i])+int(org[i]))
9-1+7
count=... | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
a=int(input())
org=input()
goal=input()
count=0
re=0
for i in range(a):
if(int(org[i])>int(goal[i])):
re=min(int(org[i])-int(goal[i]) ,10-int(org[i])+int(goal[i]))
elif(int(org[i]) < int(goal[i])) :
re=min(int(goal[i])-int(org[i]), 10-int(goal[i])+int(org[i]))
9-1+7
... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.