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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,652,554,048 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 307,200 | from collections import Counter
from collections import defaultdict
from re import L
a=input()
b=input()
l=[]
if Counter(a)==Counter(b):
c=0
for x in range(len(a)):
if a[x]!=b[x]:
c+=1
l.append(a[x])
l.append(b[x])
if c==2:
if l[0]==l[2] and ... | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
from collections import Counter
from collections import defaultdict
from re import L
a=input()
b=input()
l=[]
if Counter(a)==Counter(b):
c=0
for x in range(len(a)):
if a[x]!=b[x]:
c+=1
l.append(a[x])
l.append(b[x])
if c==2:
if l[0]=... | 0 | |
846 | A | Curriculum Vitae | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. | Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | 0 | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "100\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,593,501,054 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 6,656,000 | _ = input()
string = input().split()
a = ''
a = a.join(string)
print(len(a) - a.count('10')) | Title: Curriculum Vitae
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* g... | ```python
_ = input()
string = input().split()
a = ''
a = a.join(string)
print(len(a) - a.count('10'))
``` | 0 | |
312 | A | Whose sentence is it? | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of ... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditi... | [
"5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n"
] | [
"Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\n"
] | none | 500 | [
{
"input": "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .",
"output": "Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iape... | 1,666,598,086 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 62 | 0 | f = 'lala.'
r = 'miao.'
for i in range(int(input())):
a = input()
n = len(a)
if a[n - 5::] == f and a[:5:] != r:
print("Freda's")
elif a[:5:] == r and a[n - 5::] != f:
print("Rainbow's")
else:
print("OMG>.< I don't know!")
| Title: Whose sentence is it?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Fr... | ```python
f = 'lala.'
r = 'miao.'
for i in range(int(input())):
a = input()
n = len(a)
if a[n - 5::] == f and a[:5:] != r:
print("Freda's")
elif a[:5:] == r and a[n - 5::] != f:
print("Rainbow's")
else:
print("OMG>.< I don't know!")
``` | 3 | |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,695,653,940 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | a=str(input())
b=str(input())
e=a.split()
c=e[0]
d=e[1]
for n in range(int(d)):
if "BG" in b:
f=b.split("BG")
i=len(f)-1
print(f)
while i>=1:
f.insert(i,"GB")
i=i-2
print(f)
if b[0]=="B" and b[1]=="G":
f.insert(... | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
a=str(input())
b=str(input())
e=a.split()
c=e[0]
d=e[1]
for n in range(int(d)):
if "BG" in b:
f=b.split("BG")
i=len(f)-1
print(f)
while i>=1:
f.insert(i,"GB")
i=i-2
print(f)
if b[0]=="B" and b[1]=="G":
... | 0 | |
182 | D | Common Divisors | PROGRAMMING | 1,400 | [
"brute force",
"hashing",
"implementation",
"math",
"strings"
] | null | null | Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String *a* is the divisor of string *b* if and only if there exists a positive integer *x* such that if we write out string *a* consecutively *x* times, we get string *b*. For exam... | The first input line contains a non-empty string *s*1.
The second input line contains a non-empty string *s*2.
Lengths of strings *s*1 and *s*2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters. | Print the number of common divisors of strings *s*1 and *s*2. | [
"abcdabcd\nabcdabcdabcdabcd\n",
"aaa\naa\n"
] | [
"2\n",
"1\n"
] | In first sample the common divisors are strings "abcd" and "abcdabcd".
In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa". | 1,000 | [
{
"input": "abcdabcd\nabcdabcdabcdabcd",
"output": "2"
},
{
"input": "aaa\naa",
"output": "1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "3"
},
{
"input": "aaaaaaaaaaaaaa\naaaaaaaaaaaaaa",
"output": "4"
},
{
"input": "a\nb",
... | 1,645,586,308 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 186 | 9,011,200 | import sys
input = sys.stdin.readline
s1 = input().strip('\n')
s2 = input().strip('\n')
set1, set2 = set(), set()
for i in range(1, len(s1) + 1):
if len(s1) % i == 0:
if s1[:i] * (len(s1) // i) == s1:
set1.add(s1[:i])
for i in range(1, len(s2) + 1):
if len(s2) % i =... | Title: Common Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String *a* is the divisor of string *b* if and only if there exists a positive ... | ```python
import sys
input = sys.stdin.readline
s1 = input().strip('\n')
s2 = input().strip('\n')
set1, set2 = set(), set()
for i in range(1, len(s1) + 1):
if len(s1) % i == 0:
if s1[:i] * (len(s1) // i) == s1:
set1.add(s1[:i])
for i in range(1, len(s2) + 1):
if len... | 3 | |
492 | A | Vanya and Cubes | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must... | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"outpu... | 1,685,807,400 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n=int(input())
sum=1
i=1
c=0
while n>0:
n-=sum
i+=1
sum+=i
c+=1
print(c)
| Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t... | ```python
n=int(input())
sum=1
i=1
c=0
while n>0:
n-=sum
i+=1
sum+=i
c+=1
print(c)
``` | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,696,988,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a,b=[int(i)for i in (input().split())]
min_socks = min(a, b)
max_socks = max(a, b)
if max_socks%2==0:
c=max_socks/2
else:
c=(max_socks-1)/2
print(min_socks,c)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a,b=[int(i)for i in (input().split())]
min_socks = min(a, b)
max_socks = max(a, b)
if max_socks%2==0:
c=max_socks/2
else:
c=(max_socks-1)/2
print(min_socks,c)
``` | 0 | |
611 | B | New Year and Old Property | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"implementation"
] | null | null | The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Lim... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. | Print one integer – the number of years Limak will count in his chosen interval. | [
"5 10\n",
"2015 2015\n",
"100 105\n",
"72057594000000000 72057595000000000\n"
] | [
"2\n",
"1\n",
"0\n",
"26\n"
] | In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<su... | 750 | [
{
"input": "5 10",
"output": "2"
},
{
"input": "2015 2015",
"output": "1"
},
{
"input": "100 105",
"output": "0"
},
{
"input": "72057594000000000 72057595000000000",
"output": "26"
},
{
"input": "1 100",
"output": "16"
},
{
"input": "100000000000000000... | 1,610,328,124 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 108 | 0 | def getbit(n, k):
return (n >> k) & 1
def sum(n) :
return n*(n + 1) // 2
def Cal(n):
if n == 0:
return 0
end = 63
while n < (1 << end):
end -= 1
cnt = 0
rs = 0
first = end
while end >= 0:
if getbit(n, end) == 1:
if cnt == 0:
if end == ... | Title: New Year and Old Property
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2... | ```python
def getbit(n, k):
return (n >> k) & 1
def sum(n) :
return n*(n + 1) // 2
def Cal(n):
if n == 0:
return 0
end = 63
while n < (1 << end):
end -= 1
cnt = 0
rs = 0
first = end
while end >= 0:
if getbit(n, end) == 1:
if cnt == 0:
... | 0 | |
140 | A | New Year Table | PROGRAMMING | 1,700 | [
"geometry",
"math"
] | null | null | Gerald is setting the New Year table. The table has the form of a circle; its radius equals *R*. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal *r*. Each plate must be completely inside th... | The first line contains three integers *n*, *R* and *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*r*,<=*R*<=≤<=1000) — the number of plates, the radius of the table and the plates' radius. | Print "YES" (without the quotes) if it is possible to place *n* plates on the table by the rules given above. If it is impossible, print "NO".
Remember, that each plate must touch the edge of the table. | [
"4 10 4\n",
"5 10 4\n",
"1 10 10\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | The possible arrangement of the plates for the first sample is: | 500 | [
{
"input": "4 10 4",
"output": "YES"
},
{
"input": "5 10 4",
"output": "NO"
},
{
"input": "1 10 10",
"output": "YES"
},
{
"input": "3 10 20",
"output": "NO"
},
{
"input": "2 20 11",
"output": "NO"
},
{
"input": "6 9 3",
"output": "YES"
},
{
... | 1,622,322,858 | 198 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 0 | list1 = [a,b] | Title: New Year Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald is setting the New Year table. The table has the form of a circle; its radius equals *R*. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider al... | ```python
list1 = [a,b]
``` | -1 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,681,739,749 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 1,433,600 | mx = set()
for _ in range(int(input().split()[0])):
mx.update(input().split())
print(['#Black&White','#Color'][bool(mx&{'C','M','Y'})]) | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
mx = set()
for _ in range(int(input().split()[0])):
mx.update(input().split())
print(['#Black&White','#Color'][bool(mx&{'C','M','Y'})])
``` | 3 | |
317 | A | Perfect Pair | PROGRAMMING | 1,600 | [
"brute force"
] | null | null | Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.
Two integers *x*, *y* are written on the blackboard. It is allowed to erase one of them and replace it with the sum of th... | Single line of the input contains three integers *x*, *y* and *m* (<=-<=1018<=≤<=*x*, *y*, *m*<=≤<=1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier. | Print the minimum number of operations or "-1" (without quotes), if it is impossible to transform the given pair to the *m*-perfect one. | [
"1 2 5\n",
"-1 4 15\n",
"0 -1 5\n"
] | [
"2\n",
"4\n",
"-1\n"
] | In the first sample the following sequence of operations is suitable: (1, 2) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (3, 2) <img align="middle" class="tex-formula" src="https://espresso.cod... | 500 | [
{
"input": "1 2 5",
"output": "2"
},
{
"input": "-1 4 15",
"output": "4"
},
{
"input": "0 -1 5",
"output": "-1"
},
{
"input": "0 1 8",
"output": "5"
},
{
"input": "-134 -345 -134",
"output": "0"
},
{
"input": "-134 -345 -133",
"output": "-1"
},
... | 1,371,670,170 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 102,400 | x, y, m = [int(x) for x in input().split()]
x, y = min(x, y), max(x, y)
if y <= 0:
print(-1)
exit(0)
if y >= m:
print(0)
exit(0)
c = 0
if x < 0 and y > 0:
if m <= 0:
c = (m - x) // y
else:
c = -x // y
x += c * y
while x < m and y < m:
xx = x + y
if xx <= min(x, y):
print(-1)
exit(0)
... | Title: Perfect Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.
Two integers *x*, *y* a... | ```python
x, y, m = [int(x) for x in input().split()]
x, y = min(x, y), max(x, y)
if y <= 0:
print(-1)
exit(0)
if y >= m:
print(0)
exit(0)
c = 0
if x < 0 and y > 0:
if m <= 0:
c = (m - x) // y
else:
c = -x // y
x += c * y
while x < m and y < m:
xx = x + y
if xx <= min(x, y):
print(-1)
... | 0 | |
412 | B | Network Configuration | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* deno... | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | [
"3 2\n40 20 30\n",
"6 4\n100 20 40 20 50 50\n"
] | [
"30\n",
"40\n"
] | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | 1,000 | [
{
"input": "3 2\n40 20 30",
"output": "30"
},
{
"input": "6 4\n100 20 40 20 50 50",
"output": "40"
},
{
"input": "1 1\n16",
"output": "16"
},
{
"input": "2 1\n10000 17",
"output": "10000"
},
{
"input": "2 2\n200 300",
"output": "200"
},
{
"input": "3 1... | 1,657,385,513 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | if __name__ == '__main__':
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
print(a[n - k])
| Title: Network Configuration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly a... | ```python
if __name__ == '__main__':
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
print(a[n - k])
``` | 3 | |
797 | D | Broken BST | PROGRAMMING | 2,100 | [
"data structures",
"dfs and similar"
] | null | null | Let *T* be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree *T*:
1. S... | First line contains integer number *n* (1<=≤<=*n*<=≤<=105) — number of vertices in the tree.
Each of the next *n* lines contains 3 numbers *v*, *l*, *r* (0<=≤<=*v*<=≤<=109) — value on current vertex, index of the left child of the vertex and index of the right child of the vertex, respectively. If some child doesn't e... | Print number of times when search algorithm will fail. | [
"3\n15 -1 -1\n10 1 3\n5 -1 -1\n",
"8\n6 2 3\n3 4 5\n12 6 7\n1 -1 8\n4 -1 -1\n5 -1 -1\n14 -1 -1\n2 -1 -1\n"
] | [
"2\n",
"1\n"
] | In the example the root of the tree in vertex 2. Search of numbers 5 and 15 will return fail because on the first step algorithm will choose the subtree which doesn't contain numbers you are looking for. | 0 | [
{
"input": "3\n15 -1 -1\n10 1 3\n5 -1 -1",
"output": "2"
},
{
"input": "8\n6 2 3\n3 4 5\n12 6 7\n1 -1 8\n4 -1 -1\n5 -1 -1\n14 -1 -1\n2 -1 -1",
"output": "1"
},
{
"input": "1\n493041212 -1 -1",
"output": "0"
},
{
"input": "10\n921294733 5 9\n341281094 -1 -1\n35060484 10 -1\n36... | 1,676,296,025 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def init(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def find(root, x):
if not root:
return False
if root.value == x:
return True
if x < root.value:
return find(root.left, x)
else:
return find(root.right, x)
root = TreeNode(value=10,
left=TreeNode(value=... | Title: Broken BST
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let *T* be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an i... | ```python
def init(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def find(root, x):
if not root:
return False
if root.value == x:
return True
if x < root.value:
return find(root.left, x)
else:
return find(root.right, x)
root = TreeNode(value=10,
left=TreeN... | -1 | |
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards wi... | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20... | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output"... | 1,618,308,773 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | def main_function():
cards = [int(i) for i in input().split(" ")]
sums = sum(cards)
dict = {}
for i in cards:
if not i in dict:
dict[i] = 1
else:
dict[i] += 1
max = -1000
for i in dict:
if (dict[i]== 2 or dict[i] == 3) and i * dict[i] > ... | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers... | ```python
def main_function():
cards = [int(i) for i in input().split(" ")]
sums = sum(cards)
dict = {}
for i in cards:
if not i in dict:
dict[i] = 1
else:
dict[i] += 1
max = -1000
for i in dict:
if (dict[i]== 2 or dict[i] == 3) and i * ... | 0 | |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,563,172,602 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 108 | 0 | # import sys
# sys.stdin = open("test.in","r")
# sys.stdout = open("test.out","w")
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s1=0
s2=0
for i in range(n):
s1+=s1+max(0,a[i]-b[i]*k)
s2+=s2+max(0,a[n-i-1]-b[i]*k)
if s1>s2:
print('Rdewoosh')
elif s2>s1:
... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
# import sys
# sys.stdin = open("test.in","r")
# sys.stdout = open("test.out","w")
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s1=0
s2=0
for i in range(n):
s1+=s1+max(0,a[i]-b[i]*k)
s2+=s2+max(0,a[n-i-1]-b[i]*k)
if s1>s2:
print('Rdewoosh')
eli... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation... | First line contains single integer *n* (2<=≤<=*n*<=≤<=106) — the length of the permutation.
The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation. It is guaranteed that all elements are distinct. | Print two integers: the minimum deviation of cyclic shifts of permutation *p* and the id of such shift. If there are multiple solutions, print any of them. | [
"3\n1 2 3\n",
"3\n2 3 1\n",
"3\n3 2 1\n"
] | [
"0 0\n",
"0 1\n",
"2 1\n"
] | In the first sample test the given permutation *p* is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well.
In the second sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1,... | 0 | [
{
"input": "3\n1 2 3",
"output": "0 0"
},
{
"input": "3\n2 3 1",
"output": "0 1"
},
{
"input": "3\n3 2 1",
"output": "2 1"
},
{
"input": "2\n1 2",
"output": "0 0"
},
{
"input": "2\n2 1",
"output": "0 1"
},
{
"input": "10\n10 1 9 2 8 3 7 4 6 5",
"ou... | 1,498,578,365 | 4,265 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 6 | 2,000 | 64,819,200 | n = int(input())
a = list(map(int, input().split()))
inf = [0] * (n + 1)
curr = 0
d = 0
for i in range(n):
curr += abs(i + 1 - a[i])
if a[i] > i + 1:
d += 1
inf[a[i] - i - 1] += 1
elif a[i] <= i + 1:
d -= 1
if a[i] == i + 1:
inf[0] += 1
else:
i... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation ... | ```python
n = int(input())
a = list(map(int, input().split()))
inf = [0] * (n + 1)
curr = 0
d = 0
for i in range(n):
curr += abs(i + 1 - a[i])
if a[i] > i + 1:
d += 1
inf[a[i] - i - 1] += 1
elif a[i] <= i + 1:
d -= 1
if a[i] == i + 1:
inf[0] += 1
else:
... | 0 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,618,954,395 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n,k = map(int,input().split())
l = list(map(int,input().split()))
a = set(l)
l2 = []
for x in a:
l2.append(l.index(x)+1)
if len(l2)<k:
print("No")
else:
l2.sort()
print("YES")
print(*l2[:k])
| Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
n,k = map(int,input().split())
l = list(map(int,input().split()))
a = set(l)
l2 = []
for x in a:
l2.append(l.index(x)+1)
if len(l2)<k:
print("No")
else:
l2.sort()
print("YES")
print(*l2[:k])
``` | 0 | |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,678,995,763 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n = int(input())
l = list(map(int, input().split()))
prefix=[0]*(n)
for i in range(n):
if (prefix[i-1]+l[i])!=0:
prefix[i]=prefix[i-1]+l[i]
count=0
for i in range(len(prefix)):
if prefix[i]==0:
count+=1
print(count-1) | Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
n = int(input())
l = list(map(int, input().split()))
prefix=[0]*(n)
for i in range(n):
if (prefix[i-1]+l[i])!=0:
prefix[i]=prefix[i-1]+l[i]
count=0
for i in range(len(prefix)):
if prefix[i]==0:
count+=1
print(count-1)
``` | 0 |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,699,719,611 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 187 | 12,083,200 | n=int(input())
string=input()
a=string.split()
for i in range(n):
a[i]=int(a[i])
b=[]
for i in range(n-1):
b.append(a[i]+a[i+1])
b.append(a[n-1])
for i in range(n):
print(b[i],end=" ")
| Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
n=int(input())
string=input()
a=string.split()
for i in range(n):
a[i]=int(a[i])
b=[]
for i in range(n-1):
b.append(a[i]+a[i+1])
b.append(a[n-1])
for i in range(n):
print(b[i],end=" ")
``` | 3 | |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,659,880,232 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 15 | 140 | 10,854,400 | #Navneet Kumar
#Indian Institute Of Technology, Jodhpur
def exe():
n=int(input())
l=list(map(int,input().split()))
maxm=max(l)
index=l.index(maxm)
l1=l.copy()
l2=l[index+1:]+l[:index+1]
l.sort()
if(l==l1):
print(0)
return
elif(l2==l):
print(n-ind... | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
#Navneet Kumar
#Indian Institute Of Technology, Jodhpur
def exe():
n=int(input())
l=list(map(int,input().split()))
maxm=max(l)
index=l.index(maxm)
l1=l.copy()
l2=l[index+1:]+l[:index+1]
l.sort()
if(l==l1):
print(0)
return
elif(l2==l):
p... | 0 | |
999 | A | Mishka and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ... | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are... | Print one integer — the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, M... | 0 | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1... | 1,612,343,057 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 62 | 0 | n, k = map(int, input().split())
arr = list(map(int, input().split()))
ct = 0
for i in arr:
if i <= k:
ct += 1
else:
break
arr = arr[::-1]
for i in arr:
if i <= k:
ct += 1
else:
break
print(min(ct, len(arr)))
| Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his... | ```python
n, k = map(int, input().split())
arr = list(map(int, input().split()))
ct = 0
for i in arr:
if i <= k:
ct += 1
else:
break
arr = arr[::-1]
for i in arr:
if i <= k:
ct += 1
else:
break
print(min(ct, len(arr)))
``` | 3 | |
165 | E | Compatible Numbers | PROGRAMMING | 2,200 | [
"bitmasks",
"brute force",
"dfs and similar",
"dp"
] | null | null | Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* & *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002<==<=02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 & 1102<==<=102.
You are given an... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the number of elements in the given array. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=4·106) — the elements of the given array. The numbers in the array can coincide. | Print *n* integers *ans**i*. If *a**i* isn't compatible with any other element of the given array *a*1,<=*a*2,<=...,<=*a**n*, then *ans**i* should be equal to -1. Otherwise *ans**i* is any such number, that *a**i* & *ans**i*<==<=0, and also *ans**i* occurs in the array *a*1,<=*a*2,<=...,<=*a**n*. | [
"2\n90 36\n",
"4\n3 6 3 6\n",
"5\n10 6 9 8 2\n"
] | [
"36 90",
"-1 -1 -1 -1",
"-1 8 2 2 8"
] | none | 2,500 | [
{
"input": "2\n90 36",
"output": "36 90"
},
{
"input": "4\n3 6 3 6",
"output": "-1 -1 -1 -1"
},
{
"input": "5\n10 6 9 8 2",
"output": "-1 8 2 2 8"
},
{
"input": "10\n4 9 8 3 2 6 8 2 9 7",
"output": "8 4 4 8 8 8 4 8 4 8"
},
{
"input": "10\n3 5 18 12 4 20 11 19 15 6... | 1,681,743,770 | 3,770 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 1,246 | 35,737,600 | n = int(input())
a = list(map(int,input().split()))
for i in range(n):
print(bin(a[i]))
t = 22
x = [-1]*(1<<t)
for i in range(n):
x[a[i]] = a[i]
for bit in range(1 << t):
for j in range(t):
if (bit >> j) & 1:
x[bit]= max(x[bit], x[bit-(1<<j)])
ans = []
for i in r... | Title: Compatible Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* & *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002<=... | ```python
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
print(bin(a[i]))
t = 22
x = [-1]*(1<<t)
for i in range(n):
x[a[i]] = a[i]
for bit in range(1 << t):
for j in range(t):
if (bit >> j) & 1:
x[bit]= max(x[bit], x[bit-(1<<j)])
ans = []
... | 0 | |
80 | B | Depression | PROGRAMMING | 1,200 | [
"geometry",
"math"
] | B. Depression | 1 | 256 | Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful ... | The only line of input contains current time according to the digital clock, formatted as HH:MM (00<=≤<=HH<=≤<=23, 00<=≤<=MM<=≤<=59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia. | Print two numbers *x* and *y* — the angles of turning the hour and minute hands, respectively (0<=≤<=*x*,<=*y*<=<<=360). The absolute or relative error in the answer should not exceed 10<=-<=9. | [
"12:00\n",
"04:30\n",
"08:17\n"
] | [
"0 0",
"135 180",
"248.5 102"
] | A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5. | 1,000 | [
{
"input": "12:00",
"output": "0 0"
},
{
"input": "04:30",
"output": "135 180"
},
{
"input": "08:17",
"output": "248.5 102"
},
{
"input": "07:20",
"output": "220 120"
},
{
"input": "09:55",
"output": "297.5 330"
},
{
"input": "11:59",
"output": "35... | 1,594,642,855 | 2,147,483,647 | PyPy 3 | OK | TESTS | 66 | 155 | 20,172,800 | h,m = list(map(int,input().split(':')))
print((h*30+m/2)%360,m*6)
| Title: Depression
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the Wes... | ```python
h,m = list(map(int,input().split(':')))
print((h*30+m/2)%360,m*6)
``` | 3.884925 |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,613,959,932 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 109 | 0 | n, d = map(int, input().split())
t = list(map(int, input().split()))
total_song_time = sum(t)
d -= total_song_time
total_required_breaks = d//10
if total_required_breaks<n-1:
print(-1)
else:
print( d//5 ) | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
n, d = map(int, input().split())
t = list(map(int, input().split()))
total_song_time = sum(t)
d -= total_song_time
total_required_breaks = d//10
if total_required_breaks<n-1:
print(-1)
else:
print( d//5 )
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,491,591,004 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 5,529,600 | unsplitedwords = input()
words = unsplitedwords.split(' ')
def countLower(string):
return sum(1 for c in string if c.islower())
def countuper(string):
return sum(1 for c in string if c.isupper())
finalwords = []
for w in words:
#print(" minusculas %i mayhusculas %i " % (countLower(w)... | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
unsplitedwords = input()
words = unsplitedwords.split(' ')
def countLower(string):
return sum(1 for c in string if c.islower())
def countuper(string):
return sum(1 for c in string if c.isupper())
finalwords = []
for w in words:
#print(" minusculas %i mayhusculas %i " % (cou... | 3.9587 |
193 | E | Fibonacci Number | PROGRAMMING | 2,900 | [
"brute force",
"math",
"matrices"
] | null | null | John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibonacci numbers' list by replacing each number there by the remainder when div... | The first line contains the single integer *f* (0<=≤<=*f*<=<<=1013) — the number, which position in the list we should find.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print a single number — the number of the first occurrence of the given number in John's list. If this number doesn't occur in John's list, print -1. | [
"13\n",
"377\n"
] | [
"7\n",
"14\n"
] | none | 2,500 | [
{
"input": "13",
"output": "7"
},
{
"input": "377",
"output": "14"
},
{
"input": "2406684390626",
"output": "999999"
},
{
"input": "1",
"output": "1"
},
{
"input": "3705587146357",
"output": "3224323"
},
{
"input": "2644848607501",
"output": "4999"... | 1,611,067,943 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
x, y,z,s = 0,1,0,10000000000000
res = -1
for i in range(2, s):
z = x + y
x = y
y = z
y = y % s
if(y == n):
res = i
break
elif(y > n):
break
if(res != -1):
print(res)
else:
print(-1) | Title: Fibonacci Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's ... | ```python
n = int(input())
x, y,z,s = 0,1,0,10000000000000
res = -1
for i in range(2, s):
z = x + y
x = y
y = z
y = y % s
if(y == n):
res = i
break
elif(y > n):
break
if(res != -1):
print(res)
else:
print(-1)
``` | 0 | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,629,925,923 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 186 | 7,168,000 | n=int(input())
lCup=[]
rCup=[]
open=0
closed=0
left=0
right=0
while n:
l,*r=input().split(' ')
lCup.append(int(l))
rCup.append(int(*r))
n-=1
for i in lCup:
if i==0:
closed+=1
else:
open+=1
left = min(closed, open)
closed=0
open=0
for x in rCup:
if x==0:
... | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n=int(input())
lCup=[]
rCup=[]
open=0
closed=0
left=0
right=0
while n:
l,*r=input().split(' ')
lCup.append(int(l))
rCup.append(int(*r))
n-=1
for i in lCup:
if i==0:
closed+=1
else:
open+=1
left = min(closed, open)
closed=0
open=0
for x in rCup:
... | 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,657,801,761 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n, m, a = list(map(int, input().rstrip().split()))
width = round(n/a)
hieght = round(m/a)
print(width + hieght) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = list(map(int, input().rstrip().split()))
width = round(n/a)
hieght = round(m/a)
print(width + hieght)
``` | 0 |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,626,003,634 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 108 | 102,400 | from math import sqrt
r, x1, y1, x2, y2 = map(int, input().split())
d = sqrt((x2 - x1)**2 + (y2 - y1) ** 2)
d = int(d) + 1 if d > int(d) else int(d)
print(d // (2 * r) + (1 if d % (2 * r) != 0 else 0)) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
from math import sqrt
r, x1, y1, x2, y2 = map(int, input().split())
d = sqrt((x2 - x1)**2 + (y2 - y1) ** 2)
d = int(d) + 1 if d > int(d) else int(d)
print(d // (2 * r) + (1 if d % (2 * r) != 0 else 0))
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,571,528,144 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | user_inputs = input()
theword = "hello"
for i in range(len(user_inputs)):
if theword == "": break
if user_inputs[i] == theword[0]:
theword = theword[1:]
if theword == "":
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
user_inputs = input()
theword = "hello"
for i in range(len(user_inputs)):
if theword == "": break
if user_inputs[i] == theword[0]:
theword = theword[1:]
if theword == "":
print("YES")
else:
print("NO")
``` | 3.938 |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,698,218,888 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | a=int(input())
b=int(input())
c=int(input())
r=0
r=max(r,a+(b*c))
r=max(r,a*(b+c))
r=max(r,a*b*c)
r=max(r,a+b+c)
r=max(r,(a+b)*c)
print(r)
""" 1+2*3=7
1*(2+3)=5
1*2*3=6
(1+2)*3=9 """ | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a=int(input())
b=int(input())
c=int(input())
r=0
r=max(r,a+(b*c))
r=max(r,a*(b+c))
r=max(r,a*b*c)
r=max(r,a+b+c)
r=max(r,(a+b)*c)
print(r)
""" 1+2*3=7
1*(2+3)=5
1*2*3=6
(1+2)*3=9 """
``` | 3 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,659,666,529 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | n = int(input())
if n == 6:
print("0")
exit()
count = {'purple': 'Power', 'green': 'Time', 'blue': 'Space', 'orange': 'Soul', 'red': 'Reality', 'yellow': 'Mind'}
for i in range(0, n):
s = input()
if s in count.keys():
del count[s]
print(len(count))
for key,value in count.items():
print(value)
| Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
n = int(input())
if n == 6:
print("0")
exit()
count = {'purple': 'Power', 'green': 'Time', 'blue': 'Space', 'orange': 'Soul', 'red': 'Reality', 'yellow': 'Mind'}
for i in range(0, n):
s = input()
if s in count.keys():
del count[s]
print(len(count))
for key,value in count.items():
prin... | 3 | |
779 | A | Pupils Redistribution | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and ... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains se... | Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. | [
"4\n5 4 4 4\n5 5 4 5\n",
"6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"1\n5\n3\n",
"9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n"
] | [
"1\n",
"3\n",
"-1\n",
"4\n"
] | none | 500 | [
{
"input": "4\n5 4 4 4\n5 5 4 5",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5",
"output": "3"
},
{
"input": "1\n5\n3",
"output": "-1"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1",
"output": "4"
},
{
"input": "1\n1\n2",
"output": "-1"
... | 1,488,812,292 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 62 | 4,608,000 | n = int(input())
G = {}
s = 0
for i in range(1, 6):
G[i] = 0
for x in map(int, input().split()):
G[x] += 1
for x in map(int, input().split()):
G[x] -= 1
for i in range(1,6):
if G[i] % 2 == 1:
print(-1)
exit(0)
s += abs(G[i])
print(s // 4) | Title: Pupils Redistribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consis... | ```python
n = int(input())
G = {}
s = 0
for i in range(1, 6):
G[i] = 0
for x in map(int, input().split()):
G[x] += 1
for x in map(int, input().split()):
G[x] -= 1
for i in range(1,6):
if G[i] % 2 == 1:
print(-1)
exit(0)
s += abs(G[i])
print(s // 4)... | 3 | |
177 | A1 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which ha... | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 po... | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 30 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
... | 1,547,038,765 | 2,147,483,647 | Python 3 | OK | TESTS1 | 17 | 216 | 0 | n = int(input())
m = []
for i in range(n):
m.append(list(map(int, input().split())))
s = 0
middle = (n - 1) // 2
for i in range(n):
s += m[i][i] + m[i][-(i + 1)] + m[i][middle]
s -= 2 * m[middle][middle]
s += sum(m[middle])
s -= m[middle][middle]
print(s)
| Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the ... | ```python
n = int(input())
m = []
for i in range(n):
m.append(list(map(int, input().split())))
s = 0
middle = (n - 1) // 2
for i in range(n):
s += m[i][i] + m[i][-(i + 1)] + m[i][middle]
s -= 2 * m[middle][middle]
s += sum(m[middle])
s -= m[middle][middle]
print(s)
``` | 3 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,676,239,723 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 61 | 0 | a,b=map(int,input().split())
for i in range(a):
d=input().split()
if "C"in d or "Y" in d or "M" in d:
print("#Color")
break
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
a,b=map(int,input().split())
for i in range(a):
d=input().split()
if "C"in d or "Y" in d or "M" in d:
print("#Color")
break
else:
print("#Black&White")
``` | 3 | |
903 | C | Boxes Packing | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. | Print the minimum possible number of visible boxes. | [
"3\n1 2 3\n",
"4\n4 2 4 3\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | 0 | [
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "4\n4 2 4 3",
"output": "2"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58",
"output": "10"
},
{
"input": "10\n86 89 89 86 86 89 86 86 89 89",
"output": "5"
},
{
"input": "100\n981 288 186 186 292 876 341 288 98... | 1,605,534,073 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 307,200 | n = int(input())
arr = list(map(int,input().split()))
arr.sort()
count = 0
for i in range(n):
if arr[i]!=-1:
selected = arr[i]
count+=1
else:
continue
for j in range(i+1,n):
if(arr[j]>selected):
selected = arr[j]
arr[j]=-1
print... | Title: Boxes Packing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not pu... | ```python
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
count = 0
for i in range(n):
if arr[i]!=-1:
selected = arr[i]
count+=1
else:
continue
for j in range(i+1,n):
if(arr[j]>selected):
selected = arr[j]
arr[j]... | 0 | |
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,585,376,961 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 280 | 1,638,400 | import sys
import array
s = sys.stdin.readline().replace("\n", "")
all = ""
n = len(s)
dp = array.array('i', range(n))
m = "z"
for i in range(n-1, -1, -1):
m = min(m, s[i])
dp[i] = ord(m)
t = ""
lt = 0
ans = ""
i = 0
while i < n:
if s[i] == chr(dp[i]):
if lt > 0 and chr(dp[i]) <= t[-... | 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
import sys
import array
s = sys.stdin.readline().replace("\n", "")
all = ""
n = len(s)
dp = array.array('i', range(n))
m = "z"
for i in range(n-1, -1, -1):
m = min(m, s[i])
dp[i] = ord(m)
t = ""
lt = 0
ans = ""
i = 0
while i < n:
if s[i] == chr(dp[i]):
if lt > 0 and chr(dp[... | 0 | |
691 | B | s-palindrome | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the ... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters. | Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise. | [
"oXoxoXo\n",
"bod\n",
"ER\n"
] | [
"TAK\n",
"TAK\n",
"NIE\n"
] | none | 0 | [
{
"input": "oXoxoXo",
"output": "TAK"
},
{
"input": "bod",
"output": "TAK"
},
{
"input": "ER",
"output": "NIE"
},
{
"input": "o",
"output": "TAK"
},
{
"input": "a",
"output": "NIE"
},
{
"input": "opo",
"output": "NIE"
},
{
"input": "HCMoxkg... | 1,598,719,083 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 307,200 | import math
s=input()
if len(s)>=1 and len(s)<=1000:
b=len(s)/2
c=math.ceil(b)
p1=(s[0:c-1])
p2=(s[c::])
if (p1=='b' and p2=='d') or (p1=='p' and p2=='q') or (p1=='d' and p2=='b') or (p1=='q' and p2=='p') or (p1=='o' and p2=='o') or (p1=='A' and p2=="A") or (p1=='H' and p2=='H') or (p1=='I' and p2=... | Title: s-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second h... | ```python
import math
s=input()
if len(s)>=1 and len(s)<=1000:
b=len(s)/2
c=math.ceil(b)
p1=(s[0:c-1])
p2=(s[c::])
if (p1=='b' and p2=='d') or (p1=='p' and p2=='q') or (p1=='d' and p2=='b') or (p1=='q' and p2=='p') or (p1=='o' and p2=='o') or (p1=='A' and p2=="A") or (p1=='H' and p2=='H') or (p1=='... | 0 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,659,558,705 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 4,300,800 | from fractions import Fraction
def reducefract(n, d):
def gcd(n, d):
while d != 0:
t = d
d = n % d
n = t
return n
greatest = gcd(n, d)
n //= greatest
d //= greatest
return f"{n}/{d}"
d, w, b = list(map(int, input().split(' ')))
t... | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
from fractions import Fraction
def reducefract(n, d):
def gcd(n, d):
while d != 0:
t = d
d = n % d
n = t
return n
greatest = gcd(n, d)
n //= greatest
d //= greatest
return f"{n}/{d}"
d, w, b = list(map(int, input().split... | 0 | |
999 | C | Alphabetic Removals | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | 0 | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"i... | 1,654,909,199 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 140 | 8,601,600 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()[:-1]
x = 97
while k > 0:
a = s.count(chr(x))
s = s.replace(chr(x),'',min(a,k))
k -= min(a,k)
x += 1
print(s) | Title: Alphabetic Removals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is... | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()[:-1]
x = 97
while k > 0:
a = s.count(chr(x))
s = s.replace(chr(x),'',min(a,k))
k -= min(a,k)
x += 1
print(s)
``` | 3 | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,697,997,752 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,867,200 | from math import *
a = int(input())
b = int(input())
set1=set()
set2=set()
i = 1
while i<=sqrt(a):
if a%i != 0:
i=i+1
continue
else:
set1.add(i)
set1.add(a//i)
i=i+1
i = 1
while i<=sqrt(b):
if b%i != 0:
i=i+1
continue
else:
set2.add(i)
set2.add(b/... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
from math import *
a = int(input())
b = int(input())
set1=set()
set2=set()
i = 1
while i<=sqrt(a):
if a%i != 0:
i=i+1
continue
else:
set1.add(i)
set1.add(a//i)
i=i+1
i = 1
while i<=sqrt(b):
if b%i != 0:
i=i+1
continue
else:
set2.add(i)
s... | -1 |
83 | A | Magical Array | PROGRAMMING | 1,300 | [
"math"
] | A. Magical Array | 2 | 256 | Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutel... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator). | [
"4\n2 1 1 4\n",
"5\n-2 -2 -2 0 1\n"
] | [
"5\n",
"8\n"
] | Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3]. | 500 | [
{
"input": "4\n2 1 1 4",
"output": "5"
},
{
"input": "5\n-2 -2 -2 0 1",
"output": "8"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n5 6",
"output": "2"
},
{
"input": "5\n5 5 4 5 5",
"output": "7"
},
{
"input": "8\n1 2 0 0 0 0 3 3",
"output... | 1,610,705,087 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 404 | 11,264,000 | def magical(arr):
curr=None
currn=0
ans=[]
for i in arr:
if curr!=i:
ans.append(currn)
currn=1
curr=i
else:
currn+=1
ans.append(currn)
cnt=0
for i in ans:
cnt+=((i)*(i+1))//2
return cnt
a=input()
lst=... | Title: Magical Array
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a re... | ```python
def magical(arr):
curr=None
currn=0
ans=[]
for i in arr:
if curr!=i:
ans.append(currn)
currn=1
curr=i
else:
currn+=1
ans.append(currn)
cnt=0
for i in ans:
cnt+=((i)*(i+1))//2
return cnt
a=inp... | 3.878019 |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,687,089,867 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | guest = input()
host = input()
letters = input()
santa = "SANTACLAUS"
banta = "DEDMOROZ"
for letter in letters:
if letter in santa:
santa = santa.replace(letter, "", 1)
elif letter in banta:
banta = banta.replace(letter, "", 1)
if len(santa) == 0 and len(banta) == 0:
print("... | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
guest = input()
host = input()
letters = input()
santa = "SANTACLAUS"
banta = "DEDMOROZ"
for letter in letters:
if letter in santa:
santa = santa.replace(letter, "", 1)
elif letter in banta:
banta = banta.replace(letter, "", 1)
if len(santa) == 0 and len(banta) == 0:
... | 0 | |
291 | E | Tree-String Problem | PROGRAMMING | 2,000 | [
"*special",
"dfs and similar",
"hashing",
"strings"
] | null | null | A rooted tree is a non-directed connected graph without any cycles with a distinguished vertex, which is called the tree root. Consider the vertices of a rooted tree, that consists of *n* vertices, numbered from 1 to *n*. In this problem the tree root is the vertex number 1.
Let's represent the length of the shortest ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices of Polycarpus's tree. Next *n*<=-<=1 lines contain the tree edges. The *i*-th of them contains number *p**i*<=+<=1 and string *s**i*<=+<=1 (1<=≤<=*p**i*<=+<=1<=≤<=*n*; *p**i*<=+<=1<=≠<=(*i*<=+<=1)). String *s**i*<=+<=1 is non-empty and con... | Print a single integer — the required number.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"7\n1 ab\n5 bacaba\n1 abacaba\n2 aca\n5 ba\n2 ba\naba\n",
"7\n1 ab\n5 bacaba\n1 abacaba\n2 aca\n5 ba\n2 ba\nbacaba\n"
] | [
"6\n",
"4\n"
] | In the first test case string "aba" is determined by the pairs of positions: (2, 0) and (5, 0); (5, 2) and (6, 1); (5, 2) and (3, 1); (4, 0) and (4, 2); (4, 4) and (4, 6); (3, 3) and (3, 5).
Note that the string is not defined by the pair of positions (7, 1) and (5, 0), as the way between them doesn't always go down. | 2,500 | [
{
"input": "7\n1 ab\n5 bacaba\n1 abacaba\n2 aca\n5 ba\n2 ba\naba",
"output": "6"
},
{
"input": "7\n1 ab\n5 bacaba\n1 abacaba\n2 aca\n5 ba\n2 ba\nbacaba",
"output": "4"
},
{
"input": "4\n1 a\n4 b\n1 b\naab",
"output": "0"
},
{
"input": "4\n1 a\n1 b\n1 a\nbba",
"output": "0... | 1,689,247,941 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689247940.957978")# 1689247940.957995 | Title: Tree-String Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A rooted tree is a non-directed connected graph without any cycles with a distinguished vertex, which is called the tree root. Consider the vertices of a rooted tree, that consists of *n* vertices, numbered from 1 t... | ```python
print("_RANDOM_GUESS_1689247940.957978")# 1689247940.957995
``` | 0 | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,698,320,633 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 92 | 0 | n = input()
f=0
if(n[0]!='1'):
print('NO')
else:
for j in range(1,len(n)):
if(n[j]!='1' and n[j]!='4'):
print('NO')
f=1
break
elif(n[j]=='4' and n[j-1]!='1'):
if(n[j-1]=='4' and n[j-2]=='1'):
continue
else:... | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
n = input()
f=0
if(n[0]!='1'):
print('NO')
else:
for j in range(1,len(n)):
if(n[j]!='1' and n[j]!='4'):
print('NO')
f=1
break
elif(n[j]=='4' and n[j-1]!='1'):
if(n[j-1]=='4' and n[j-2]=='1'):
continue
... | 3 | |
845 | B | Luba And The Ticket | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of las... | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one re... | 0 | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "... | 1,503,627,521 | 2,147,483,647 | Python 3 | OK | TESTS | 145 | 62 | 0 | digits = [int(i) for i in input()]
sm = digits[:3]
gr = digits[3:]
if sum(sm) > sum(gr):
sm, gr = gr, sm
iters = 0
diff = sum(gr) - sum(sm)
while diff:
iters += 1
bestSm = sm.index(min(sm))
bestGr = gr.index(max(gr))
if 9-sm[bestSm] > gr[bestGr]:
sm[bestSm] = 9 if sm[bestSm] + diff > 9 else... | Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th... | ```python
digits = [int(i) for i in input()]
sm = digits[:3]
gr = digits[3:]
if sum(sm) > sum(gr):
sm, gr = gr, sm
iters = 0
diff = sum(gr) - sum(sm)
while diff:
iters += 1
bestSm = sm.index(min(sm))
bestGr = gr.index(max(gr))
if 9-sm[bestSm] > gr[bestGr]:
sm[bestSm] = 9 if sm[bestSm] + dif... | 3 | |
777 | C | Alyona and Spreadsheet | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"greedy",
"implementation",
"two pointers"
] | null | null | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the tab... | The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the followi... | Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | [
"5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n"
] | [
"Yes\nNo\nYes\nYes\nYes\nNo\n"
] | In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | 1,500 | [
{
"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5",
"output": "Yes\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "Yes"
},
{
"input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n38686565... | 1,614,584,949 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 9,625,600 | a, b = map(int, input().split())
x = []
for i in range(a):
y = []
y = (list(map(int, input().split())))
x.append(y[::])
n = int(input())
f = 1
for i in range(n):
l, r = map(int, input().split())
for k in range(b):
f = 1
for j in range(l - 1, r - 1):
if x[j]... | Title: Alyona and Spreadsheet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By ... | ```python
a, b = map(int, input().split())
x = []
for i in range(a):
y = []
y = (list(map(int, input().split())))
x.append(y[::])
n = int(input())
f = 1
for i in range(n):
l, r = map(int, input().split())
for k in range(b):
f = 1
for j in range(l - 1, r - 1):
... | 0 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,695,630,907 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | m,n = map(int,input().split())
cnt=0
for i in range(1,m+1):
if i%2!=0:
for i in range(n):
print("#",end="")
elif i%2==0 and cnt%2==0:
for j in range(n-1):
print(".",end="")
print("#",end="")
cnt+=1
elif i%2==0 and cnt%2!=0:
print("#... | 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
m,n = map(int,input().split())
cnt=0
for i in range(1,m+1):
if i%2!=0:
for i in range(n):
print("#",end="")
elif i%2==0 and cnt%2==0:
for j in range(n-1):
print(".",end="")
print("#",end="")
cnt+=1
elif i%2==0 and cnt%2!=0:
... | 3 | |
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas... | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBB... | 1,619,316,997 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 62 | 0 | s=input()
o="Bulbbasaur"
q={}
for i in o:q[i]=0
for i in s:
if i in q:q[i]+=1
for i in {*o}:
q[i]//=o.count(i)
print(min(q.values())) | Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsess... | ```python
s=input()
o="Bulbbasaur"
q={}
for i in o:q[i]=0
for i in s:
if i in q:q[i]+=1
for i in {*o}:
q[i]//=o.count(i)
print(min(q.values()))
``` | 0 | |
999 | C | Alphabetic Removals | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | 0 | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"i... | 1,629,986,582 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 22,220,800 | import string
n, k = map(int, input().split())
s = input()
alphabets = list(string.ascii_lowercase)
for i in range(k):
temp = s
for j in s:
for alphabet in alphabets:
if j == alphabet:
s = s.replace(alphabet, "", 1)
break
if temp != s:
... | Title: Alphabetic Removals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is... | ```python
import string
n, k = map(int, input().split())
s = input()
alphabets = list(string.ascii_lowercase)
for i in range(k):
temp = s
for j in s:
for alphabet in alphabets:
if j == alphabet:
s = s.replace(alphabet, "", 1)
break
if te... | 0 | |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pie... | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
... | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,571,071,377 | 777 | PyPy 3 | WRONG_ANSWER | TESTS | 48 | 202 | 9,113,600 | x = [0]*(100010)
for i in range(2, 100010):
if(x[i]==0):
j = 2*i
while(j < 100010):
x[j] = 1
j += i
n = int(input())
if(n == 1):
print(1)
print(1)
exit()
print(2)
for i in range(2, n+2):
if(x[i] == 0):
print(1, end = ' ')
else:
print(2, end = ' ')
print()
| Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ... | ```python
x = [0]*(100010)
for i in range(2, 100010):
if(x[i]==0):
j = 2*i
while(j < 100010):
x[j] = 1
j += i
n = int(input())
if(n == 1):
print(1)
print(1)
exit()
print(2)
for i in range(2, n+2):
if(x[i] == 0):
print(1, end = ' ')
else:
print(2, end = ' ')
print()
``` | 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,603,629,632 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 307,200 |
n = int(input())
height = input()
list = height
height = height.split()
list = list.split()
list.sort()
p1 = 0
p2 = 0
n = int(n)
for i in range(0,n, 1):
if height[i] == list[0]:
p1 = i
break
for i in range(n-1, 0, -1):
if height[i] == list[1]:
p2 = i
bre... | 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())
height = input()
list = height
height = height.split()
list = list.split()
list.sort()
p1 = 0
p2 = 0
n = int(n)
for i in range(0,n, 1):
if height[i] == list[0]:
p1 = i
break
for i in range(n-1, 0, -1):
if height[i] == list[1]:
p2 = i
... | 0 |
799 | C | Fountains | PROGRAMMING | 1,800 | [
"binary search",
"data structures",
"implementation"
] | null | null | Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are *n* available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are all... | The first line contains three integers *n*, *c* and *d* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*c*,<=*d*<=≤<=100<=000) — the number of fountains, the number of coins and diamonds Arkady has.
The next *n* lines describe fountains. Each of these lines contain two integers *b**i* and *p**i* (1<=≤<=*b**i*,<=*p**i*<=≤<=100<=000) —... | Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0. | [
"3 7 6\n10 8 C\n4 3 C\n5 6 D\n",
"2 4 5\n2 5 C\n2 1 D\n",
"3 10 10\n5 5 C\n5 5 C\n10 11 D\n"
] | [
"9\n",
"0\n",
"10\n"
] | In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example t... | 1,500 | [
{
"input": "3 7 6\n10 8 C\n4 3 C\n5 6 D",
"output": "9"
},
{
"input": "2 4 5\n2 5 C\n2 1 D",
"output": "0"
},
{
"input": "3 10 10\n5 5 C\n5 5 C\n10 11 D",
"output": "10"
},
{
"input": "6 68 40\n1 18 D\n6 16 D\n11 16 D\n7 23 D\n16 30 D\n2 20 D",
"output": "18"
},
{
... | 1,625,398,873 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | from bisect import bisect_right as br
def f(Coin,Diamond,c,d):
Coin=sorted(Coin,key=lambda s:s[1])
Coin=sorted(Coin,key=lambda s:s[0])
Diamond=sorted(Diamond,key=lambda s:s[1])
Diamond=sorted(Diamond,key=lambda s:s[0])
l=[]
for i in range(2):
rr=br(Coin,(c,float("inf")))-1
if rr>=0:
l.append(Coi... | Title: Fountains
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are *n* available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so ea... | ```python
from bisect import bisect_right as br
def f(Coin,Diamond,c,d):
Coin=sorted(Coin,key=lambda s:s[1])
Coin=sorted(Coin,key=lambda s:s[0])
Diamond=sorted(Diamond,key=lambda s:s[1])
Diamond=sorted(Diamond,key=lambda s:s[0])
l=[]
for i in range(2):
rr=br(Coin,(c,float("inf")))-1
if rr>=0:
l.... | 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,545,842,965 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 278 | 0 | x,y,z=0,0,0
for _ in range(int(input())):
a,b,c=map(int,input().split())
x+=a
y+=b
z+=c
print("YES" if x==0 and y==0 and 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
x,y,z=0,0,0
for _ in range(int(input())):
a,b,c=map(int,input().split())
x+=a
y+=b
z+=c
print("YES" if x==0 and y==0 and z==0 else "NO")
``` | 3.9305 |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,588,833,942 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 109 | 6,656,000 | def s(n):
j = 1
sm = 0
counter = 0
ans = []
while sm + j <= n:
ans.append(j)
sm += j
j += 1
counter += 1
if n - sm != 0:
ans[-1] = n - sm + ans[-1]
print(counter)
for x in ans:
print(str(x),end = " ")
print()
n = int(i... | Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
def s(n):
j = 1
sm = 0
counter = 0
ans = []
while sm + j <= n:
ans.append(j)
sm += j
j += 1
counter += 1
if n - sm != 0:
ans[-1] = n - sm + ans[-1]
print(counter)
for x in ans:
print(str(x),end = " ")
print()
... | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,647,457,170 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 0 | n1, n2 = [int(i) for i in input().split()]
n1w = 0
d = 0
n2w = 0
for i in range(1, 7):
if abs(n1 - i) < abs(n2 - i):
n1w += 1
elif abs(n1 - i) == abs(n2 - i):
d += 1
else:
n2w += 1
print(str(n1w) + ' ' + str(d) + ' ' + str(n2w)) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
n1, n2 = [int(i) for i in input().split()]
n1w = 0
d = 0
n2w = 0
for i in range(1, 7):
if abs(n1 - i) < abs(n2 - i):
n1w += 1
elif abs(n1 - i) == abs(n2 - i):
d += 1
else:
n2w += 1
print(str(n1w) + ' ' + str(d) + ' ' + str(n2w))
``` | 3 | |
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,685,552,267 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 122 | 0 | m, n= input().split()
m=int(m)
n=int(n)
print(int((m*n)/2)) | 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
m, n= input().split()
m=int(m)
n=int(n)
print(int((m*n)/2))
``` | 3.9695 |
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,603,331,010 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 186 | 0 | n = int(input())
def new(x):
x %= 2
return x
lst = list(map(new, list(map(int, input().split()))))
if lst.count(1) == 1:
print(lst.index(1) + 1)
else:
print(lst.index(0) + 1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
def new(x):
x %= 2
return x
lst = list(map(new, list(map(int, input().split()))))
if lst.count(1) == 1:
print(lst.index(1) + 1)
else:
print(lst.index(0) + 1)
``` | 3.9535 |
507 | A | Amr and Music | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"sortings"
] | null | null | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for ... | The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. | In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use al... | [
"4 10\n4 3 1 2\n",
"5 6\n4 3 1 1 2\n",
"1 3\n4\n"
] | [
"4\n1 2 3 4",
"3\n1 3 4",
"0\n"
] | In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | 500 | [
{
"input": "4 10\n4 3 1 2",
"output": "4\n1 2 3 4"
},
{
"input": "5 6\n4 3 1 1 2",
"output": "3\n3 4 5"
},
{
"input": "1 3\n4",
"output": "0"
},
{
"input": "2 100\n100 100",
"output": "1\n1"
},
{
"input": "3 150\n50 50 50",
"output": "3\n1 2 3"
},
{
"i... | 1,683,639,561 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a=list(map(int,input().split()))
f=1
for i in range(a[0]):
if i%2==0:
print("#"*a[1])
else:
if f:
print('.'*(a[1]-1)+'#')
f=0
else:
print('#'+'.'*(a[1]-1))
f=1 | Title: Amr and Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr ... | ```python
a=list(map(int,input().split()))
f=1
for i in range(a[0]):
if i%2==0:
print("#"*a[1])
else:
if f:
print('.'*(a[1]-1)+'#')
f=0
else:
print('#'+'.'*(a[1]-1))
f=1
``` | 0 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,627,904,099 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 17 | 2,000 | 16,076,800 | n=int(input())
l=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
v=0
p=0
b=sorted(b)
if(sorted(l)==b):
b=sum(list(range(1,m+1)))
print("%d %d"%(b,b))
else:
for i in b:
ind=l.index(i)
v=v+ind+1
p=p+(n-ind)
print("%d %d"%(v,p)) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n=int(input())
l=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
v=0
p=0
b=sorted(b)
if(sorted(l)==b):
b=sum(list(range(1,m+1)))
print("%d %d"%(b,b))
else:
for i in b:
ind=l.index(i)
v=v+ind+1
p=p+(n-ind)
print("%d %d"... | 0 | |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,630,369,781 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 7,372,800 | #for this problem, I used a BFS algorithm although I don't believe that it would make a difference in time complexity if I were to use a DFS since we have to explore all the vertices anyway to get all the distances of end cities. Once again the time and space complexity of this algorithm is O(|V|)
from collections impo... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
#for this problem, I used a BFS algorithm although I don't believe that it would make a difference in time complexity if I were to use a DFS since we have to explore all the vertices anyway to get all the distances of end cities. Once again the time and space complexity of this algorithm is O(|V|)
from collec... | 0 | |
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that... | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so t... | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
... | 1,630,782,860 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 6,963,200 | import sys
import numpy as np
from collections import Counter
n = int(input())
c = {2:0,3:0,4:0,5:0}
grids = [int(i) for i in input().split(" ")]
for i in grids:
c[i]+=1
count = 0
def calc_mean_counter(c:dict)->float:
return (2*c[2]+3*c[3]+4*c[4]+5*c[5])/(c[2]+c[3]+c[4]+c[5])
while calc_mean_counter(c)<4.5:
... | Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming t... | ```python
import sys
import numpy as np
from collections import Counter
n = int(input())
c = {2:0,3:0,4:0,5:0}
grids = [int(i) for i in input().split(" ")]
for i in grids:
c[i]+=1
count = 0
def calc_mean_counter(c:dict)->float:
return (2*c[2]+3*c[3]+4*c[4]+5*c[5])/(c[2]+c[3]+c[4]+c[5])
while calc_mean_counte... | -1 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,692,080,976 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 409,600 | # LUOGU_RID: 120992711
sx=input();s0=input();s1=input();s2=input();s3=input();s4=input();s5=input();s6=input();s7=input();s8=input();s9=input()
a1=sx[0]+sx[1]+sx[2]+sx[3]+sx[4]+sx[5]+sx[6]+sx[7]+sx[8]+sx[9]
a2=sx[10]+sx[11]+sx[12]+sx[13]+sx[14]+sx[15]+sx[16]+sx[17]+sx[18]+sx[19]
a3=sx[20]+sx[21]+sx[22]+sx[23]+sx[24]+sx... | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
# LUOGU_RID: 120992711
sx=input();s0=input();s1=input();s2=input();s3=input();s4=input();s5=input();s6=input();s7=input();s8=input();s9=input()
a1=sx[0]+sx[1]+sx[2]+sx[3]+sx[4]+sx[5]+sx[6]+sx[7]+sx[8]+sx[9]
a2=sx[10]+sx[11]+sx[12]+sx[13]+sx[14]+sx[15]+sx[16]+sx[17]+sx[18]+sx[19]
a3=sx[20]+sx[21]+sx[22]+sx[23]... | 3.976237 |
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,588,494,249 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 155 | 0 | buckets, length = map(int,input().split())
data = list(map(int,input().split()))
data.sort(reverse=True)
for element in data:
if length % element == 0:
print(length // element)
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
buckets, length = map(int,input().split())
data = list(map(int,input().split()))
data.sort(reverse=True)
for element in data:
if length % element == 0:
print(length // element)
break
``` | 3 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,613,056,843 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | n=input()
m=len(n)
c=0
for i in range(1,m):
c+=2**i
s=n.replace('4','0')
s=s.replace('7','1')
print(c+1+int(s,2)) | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
n=input()
m=len(n)
c=0
for i in range(1,m):
c+=2**i
s=n.replace('4','0')
s=s.replace('7','1')
print(c+1+int(s,2))
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,458,811,222 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 124 | 4,812,800 | _Str=input()
Big=0
Small=0
for i in _Str:
if 81<=ord(i)<106:
Big+=1
else:
Small+=1
if Big> Small:
print(_Str.upper())
else:
print(_Str.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
_Str=input()
Big=0
Small=0
for i in _Str:
if 81<=ord(i)<106:
Big+=1
else:
Small+=1
if Big> Small:
print(_Str.upper())
else:
print(_Str.lower())
``` | 0 |
276 | D | Little Girl and Maximum XOR | PROGRAMMING | 1,700 | [
"bitmasks",
"dp",
"greedy",
"implementation",
"math"
] | null | null | A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitw... | The single line contains space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print a single integer — the maximum value of for all pairs of integers *a*, *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). | [
"1 2\n",
"8 16\n",
"1 1\n"
] | [
"3\n",
"31\n",
"0\n"
] | none | 2,000 | [
{
"input": "1 2",
"output": "3"
},
{
"input": "8 16",
"output": "31"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "506 677",
"output": "1023"
},
{
"input": "33 910",
"output": "1023"
},
{
"input": "36 94",
"output": "127"
},
{
"input": ... | 1,680,552,506 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 31 | 0 | import math
left, right = map(int,input().split())
#if this value is between left and right then we have an answer
flag = False
while left < right:
value = math.log(right,2)
value = math.floor(value)
if 2**value > left:
print(2**value ^ (2**value - 1))
flag = True
break
... | Title: Little Girl and Maximum XOR
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<... | ```python
import math
left, right = map(int,input().split())
#if this value is between left and right then we have an answer
flag = False
while left < right:
value = math.log(right,2)
value = math.floor(value)
if 2**value > left:
print(2**value ^ (2**value - 1))
flag = True
... | -1 | |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t... | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guarant... | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ... | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "3... | 1,621,839,672 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n=int(input())
negative=[]
positive=[]
for i in range(n):
x,y=map(int, input().split(" "))
if x<0:
negative.append([x,y])
else:
positive.append([x,y])
lenN=len(negative)
lenP=len(positive)
if lenN==lenP:
sum=0
for i in range(lenP):
sum+=positive[i][1]
for... | Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree num... | ```python
n=int(input())
negative=[]
positive=[]
for i in range(n):
x,y=map(int, input().split(" "))
if x<0:
negative.append([x,y])
else:
positive.append([x,y])
lenN=len(negative)
lenP=len(positive)
if lenN==lenP:
sum=0
for i in range(lenP):
sum+=positive[i][1... | 0 | |
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub... | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
... | 1,560,257,233 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | n = int(input())
num = input().split()
num = [int(x) for x in num]
while(max(num)!= min(num)):
maior = num.index(max(num))
num[maior] -= min(num)
soma = 0
for n in num:
soma += n
print(soma)
| Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that ... | ```python
n = int(input())
num = input().split()
num = [int(x) for x in num]
while(max(num)!= min(num)):
maior = num.index(max(num))
num[maior] -= min(num)
soma = 0
for n in num:
soma += n
print(soma)
``` | 3 | |
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,643,305,442 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | m=int (input())
n=int (input())
print ((m*n)//2)
| 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
m=int (input())
n=int (input())
print ((m*n)//2)
``` | -1 |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half... | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the... | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,503,284,076 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 124 | 0 | n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i]=map(int,input().split())
k=h=0
for i in range(n):
if(a[i]%2):
k+=1
if(b[i]%2):
h+=1
if((h+k)%2 or (n==1 and (h%2 or k%2))):
print(-1)
elif(h%2 and k%2):
print(1)
else:
print(0) | Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n... | ```python
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i]=map(int,input().split())
k=h=0
for i in range(n):
if(a[i]%2):
k+=1
if(b[i]%2):
h+=1
if((h+k)%2 or (n==1 and (h%2 or k%2))):
print(-1)
elif(h%2 and k%2):
print(1)
else:
print(0)
``` | 0 | |
981 | B | Businessmen Problems | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the ... | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) — the index of the $i$-th element and the income of its usage on the exhibitio... | Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets. | [
"3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n",
"1\n1000000000 239\n3\n14 15\n92 65\n35 89\n"
] | [
"24\n",
"408\n"
] | In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + ... | 750 | [
{
"input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4",
"output": "24"
},
{
"input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89",
"output": "408"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\... | 1,527,586,511 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 77 | 0 | n = int(input())
chemForcesEl = []
for i in range(n):
elInfo = input().split(" ")
chemForcesEl.append((int(elInfo[0]), int(elInfo[1])))
m = int(input())
topChemEl = []
for i in range(m):
elInfo = input().split(" ")
topChemEl.append((int(elInfo[0]), int(elInfo[1])))
chemForcesEl = sorted(ch... | Title: Businessmen Problems
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both... | ```python
n = int(input())
chemForcesEl = []
for i in range(n):
elInfo = input().split(" ")
chemForcesEl.append((int(elInfo[0]), int(elInfo[1])))
m = int(input())
topChemEl = []
for i in range(m):
elInfo = input().split(" ")
topChemEl.append((int(elInfo[0]), int(elInfo[1])))
chemForcesEl =... | -1 | |
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,695,995,119 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 154 | 1,433,600 | s=input()
c=0
for i in range(len(s)):
for j in range(i+1,len(s)):
if s[i]==s[j]:
c+=1
if (len(s)-c)%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
s=input()
c=0
for i in range(len(s)):
for j in range(i+1,len(s)):
if s[i]==s[j]:
c+=1
if (len(s)-c)%2==0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!")
``` | 0 | |
978 | A | Remove Duplicates | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. | In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the... | 0 | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
... | 1,655,622,987 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n=int(input())
l=list(map(int,input().split()))
s=set(l)
print(len(s))
for i in s:
print(i,end=" ")
| Title: Remove Duplicates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the re... | ```python
n=int(input())
l=list(map(int,input().split()))
s=set(l)
print(len(s))
for i in s:
print(i,end=" ")
``` | 0 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,599,652,143 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 108 | 307,200 | n = int(input())
pole = [[int(1) for x in range(n)] for y in range(n)]
for i in range(1, len(pole)):
for j in range(len(pole[i])):
if j == 0:
pole[i][j] = pole[i-1][j]
else:
pole[i][j] = pole[i][j-1] + pole[i-1][j]
print(pole[-1][-1]) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
n = int(input())
pole = [[int(1) for x in range(n)] for y in range(n)]
for i in range(1, len(pole)):
for j in range(len(pole[i])):
if j == 0:
pole[i][j] = pole[i-1][j]
else:
pole[i][j] = pole[i][j-1] + pole[i-1][j]
print(pole[-1][-1])
``` | 3 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,553,357,260 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 108 | 0 | # val(s) == length(s)
#1010111100000111001
#1111111111000000000
#1000000000
n=int(input())
s=input()
a=s.count('0')
if s[0]!='0':
print('1'+''.join('0'*a))
else:
print(0)
| Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
# val(s) == length(s)
#1010111100000111001
#1111111111000000000
#1000000000
n=int(input())
s=input()
a=s.count('0')
if s[0]!='0':
print('1'+''.join('0'*a))
else:
print(0)
``` | 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,680,706,913 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | import math
n,m,a = map(int,input().split())
x = math.ceil(n / a) * math.ceil(m / a)
print(x)
| 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
n,m,a = map(int,input().split())
x = math.ceil(n / a) * math.ceil(m / a)
print(x)
``` | 3.977 |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,679,390,001 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 1,058 | 16,896,000 | n = int(input())
v_list = list()
for i in range(n):
v_list.append(int(input()))
def create_graph(v_list):
graph = [[0] * len(v_list) for v in v_list]
for i in range(len(v_list)):
if v_list[i] != -1:
graph[i][v_list[i]-1] = 1
graph[v_list[i]-1][i] = 1
return graph
gr... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
n = int(input())
v_list = list()
for i in range(n):
v_list.append(int(input()))
def create_graph(v_list):
graph = [[0] * len(v_list) for v in v_list]
for i in range(len(v_list)):
if v_list[i] != -1:
graph[i][v_list[i]-1] = 1
graph[v_list[i]-1][i] = 1
return... | 0 | |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,603,343,916 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 140 | 0 | n=int(input())
m=1
p=0
if n%2!=0 and n>1:
print(n)
elif n%2!=0 and n==1:
print(3)
elif n==2:
print(4)
elif n%2==0 and n>2:
if (n*(n-2))+1==(n-1)*(n-1):
print(n-2) | Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
n=int(input())
m=1
p=0
if n%2!=0 and n>1:
print(n)
elif n%2!=0 and n==1:
print(3)
elif n==2:
print(4)
elif n%2==0 and n>2:
if (n*(n-2))+1==(n-1)*(n-1):
print(n-2)
``` | 3 | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,560,721,828 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 124 | 0 | n=int(input())
ans=0
for i in range(1,len(str(n))):
ans+=9*(10**(i-1))*i
#print("eeee",ans)
a=(n+1-(10**(len(str(n))-1)))*len(str(n))
print(ans+a) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
n=int(input())
ans=0
for i in range(1,len(str(n))):
ans+=9*(10**(i-1))*i
#print("eeee",ans)
a=(n+1-(10**(len(str(n))-1)))*len(str(n))
print(ans+a)
``` | 3 | |
8 | B | Obsession with Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ... | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | 0 | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"... | 1,668,024,865 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | s = input()
u = s.count("U")
r = s.count("R")
l = s.count("L")
d = s.count("D")
if u == d or r == l:
print("BUG")
else:
print("OK") | Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path fr... | ```python
s = input()
u = s.count("U")
r = s.count("R")
l = s.count("L")
d = s.count("D")
if u == d or r == l:
print("BUG")
else:
print("OK")
``` | 0 |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,692,536,855 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | n = int(input())
coins = list(map(int, input().split()))
total_sum = sum(coins)
coins.sort(reverse=True)
my_sum = 0
coins_taken = 0
for coin in coins:
my_sum += coin
coins_taken += 1
if my_sum > total_sum - my_sum:
break
pr... | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n = int(input())
coins = list(map(int, input().split()))
total_sum = sum(coins)
coins.sort(reverse=True)
my_sum = 0
coins_taken = 0
for coin in coins:
my_sum += coin
coins_taken += 1
if my_sum > total_sum - my_sum:
... | 3 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,548,775,049 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 109 | 204,800 | from sys import stdin,stdout
import math
a,b,n=map(int,stdin.readline().split())
y=1
a=a*10
i=0
flag=0
for i in range(10):
k=a+i
if k%b==0:
a=k
flag=1
break
if flag==0:
stdout.write("-1")
else:
a=str(a)
a=a+('0'*(n-1))
stdout.write(a) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
from sys import stdin,stdout
import math
a,b,n=map(int,stdin.readline().split())
y=1
a=a*10
i=0
flag=0
for i in range(10):
k=a+i
if k%b==0:
a=k
flag=1
break
if flag==0:
stdout.write("-1")
else:
a=str(a)
a=a+('0'*(n-1))
stdou... | 3 | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,495,906,900 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | r = raw_input().split(" ")
a = int(r[0])
b = int(r[1])
current = a
give = 1
while current - give >= 0:
current = current - give
#print current
if give % 2 == 0:
b = b - give
current = a
else:
a = a-give
current = b
give = give + 1
if give % 2 == 0:
print ("Valera")
else:
print ("Vladik"... | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
r = raw_input().split(" ")
a = int(r[0])
b = int(r[1])
current = a
give = 1
while current - give >= 0:
current = current - give
#print current
if give % 2 == 0:
b = b - give
current = a
else:
a = a-give
current = b
give = give + 1
if give % 2 == 0:
print ("Valera")
else:
print... | -1 | |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,666,435,485 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
lis=list(map(int,input().split()))
maxi=max(lis)
ind=lis.index(maxi)
lis.sort().pop()
print((ind+1)+" "+(lis[-1)) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
n=int(input())
lis=list(map(int,input().split()))
maxi=max(lis)
ind=lis.index(maxi)
lis.sort().pop()
print((ind+1)+" "+(lis[-1))
``` | -1 | |
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,628,829,667 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 31 | 77 | 6,963,200 | def checker_adjcency_test():
n = int(input())
board = []
for _ in range(n):
board.append(input())
for row in range(n):
adjacent_cells = []
for column in range(n):
if row - 1 >= 0:
adjacent_cells.append(board[row-1][column])
if row + 1 < n:
adjacent_cells.append(board[row+1][column])... | 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
def checker_adjcency_test():
n = int(input())
board = []
for _ in range(n):
board.append(input())
for row in range(n):
adjacent_cells = []
for column in range(n):
if row - 1 >= 0:
adjacent_cells.append(board[row-1][column])
if row + 1 < n:
adjacent_cells.append(board[row+1... | 0 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,689,095,805 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 62 | 1,638,400 | #707A
a,b=map(int,input().split())
l,l1=[],[]
for i in range(a):
l1=list(map(str,input().split()))
l.extend(l1)
if 'C' in l or 'M' in l or 'Y' in l:
print("#Color")
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
#707A
a,b=map(int,input().split())
l,l1=[],[]
for i in range(a):
l1=list(map(str,input().split()))
l.extend(l1)
if 'C' in l or 'M' in l or 'Y' in l:
print("#Color")
else:
print("#Black&White")
``` | 3 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,623,856,147 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | relation=[]
for i in range(3):
func=input()
if func[1]=='<':
relation.append((func[2],func[0]))
elif func[1]=='>':
relation.append((func[0],func[2]))
inorder=[0]*4
outorder=[0]*4
for c in relation:
if c[0]=='A':
outorder[0]+=1
if c... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
relation=[]
for i in range(3):
func=input()
if func[1]=='<':
relation.append((func[2],func[0]))
elif func[1]=='>':
relation.append((func[0],func[2]))
inorder=[0]*4
outorder=[0]*4
for c in relation:
if c[0]=='A':
outorder[0]+=1
... | 0 |
850 | C | Arpa and a game with Mojtaba | PROGRAMMING | 2,200 | [
"bitmasks",
"dp",
"games"
] | null | null | Mojtaba and Arpa are playing a game. They have a list of *n* numbers in the game.
In a player's turn, he chooses a number *p**k* (where *p* is a prime number and *k* is a positive integer) such that *p**k* divides at least one number in the list. For each number in the list divisible by *p**k*, call it *x*, the player... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the list.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the list. | If Mojtaba wins, print "Mojtaba", otherwise print "Arpa" (without quotes).
You can print each letter in any case (upper or lower). | [
"4\n1 1 1 1\n",
"4\n1 1 17 17\n",
"4\n1 1 17 289\n",
"5\n1 2 3 4 5\n"
] | [
"Arpa\n",
"Mojtaba\n",
"Arpa\n",
"Arpa\n"
] | In the first sample test, Mojtaba can't move.
In the second sample test, Mojtaba chooses *p* = 17 and *k* = 1, then the list changes to [1, 1, 1, 1].
In the third sample test, if Mojtaba chooses *p* = 17 and *k* = 1, then Arpa chooses *p* = 17 and *k* = 1 and wins, if Mojtaba chooses *p* = 17 and *k* = 2, then Arpa c... | 1,250 | [
{
"input": "4\n1 1 1 1",
"output": "Arpa"
},
{
"input": "4\n1 1 17 17",
"output": "Mojtaba"
},
{
"input": "4\n1 1 17 289",
"output": "Arpa"
},
{
"input": "5\n1 2 3 4 5",
"output": "Arpa"
},
{
"input": "10\n10 14 16 9 17 13 12 4 6 10",
"output": "Mojtaba"
},
... | 1,504,582,624 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 109 | 512,000 | def prime_factors(n):
i = 2
while i * i <= n:
if n % i:
i += 1
else:
n //= i
yield i
if n > 1:
yield n
from collections import defaultdict
from itertools import chain
memo = defaultdict(set)
def move_generator(P):
for i in ran... | Title: Arpa and a game with Mojtaba
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mojtaba and Arpa are playing a game. They have a list of *n* numbers in the game.
In a player's turn, he chooses a number *p**k* (where *p* is a prime number and *k* is a positive integer) such that *p**k*... | ```python
def prime_factors(n):
i = 2
while i * i <= n:
if n % i:
i += 1
else:
n //= i
yield i
if n > 1:
yield n
from collections import defaultdict
from itertools import chain
memo = defaultdict(set)
def move_generator(P):
fo... | 0 | |
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "37546069... | 1,661,886,195 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n=int(input())
if not(n%2):
print(n+1)
else:
print(n-1) | Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthd... | ```python
n=int(input())
if not(n%2):
print(n+1)
else:
print(n-1)
``` | 0 | |
652 | D | Nested Segments | PROGRAMMING | 1,800 | [
"data structures",
"sortings"
] | null | null | You are given *n* segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of segments on a line.
Each of the next *n* lines contains two integers *l**i* and *r**i* (<=-<=109<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — the coordinates of the left and the right ends of the *i*-th segment. It is guaranteed that there are n... | Print *n* lines. The *j*-th of them should contain the only integer *a**j* — the number of segments contained in the *j*-th segment. | [
"4\n1 8\n2 3\n4 7\n5 6\n",
"3\n3 4\n1 5\n2 6\n"
] | [
"3\n0\n1\n0\n",
"0\n1\n1\n"
] | none | 0 | [
{
"input": "4\n1 8\n2 3\n4 7\n5 6",
"output": "3\n0\n1\n0"
},
{
"input": "3\n3 4\n1 5\n2 6",
"output": "0\n1\n1"
},
{
"input": "1\n-1000000000 1000000000",
"output": "0"
},
{
"input": "2\n-1000000000 999999999\n-999999999 1000000000",
"output": "0\n0"
},
{
"input"... | 1,458,917,085 | 6,285 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 4,608,000 | n=int(input())
for i in range(n):
a=input().split()
dif=int(a[1])-int(a[0])
if dif%2==0:
dif-=1
print(int(dif/2)) | Title: Nested Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.
Input Specification:
The first line contains a single integer *n* (1<=≤<... | ```python
n=int(input())
for i in range(n):
a=input().split()
dif=int(a[1])-int(a[0])
if dif%2==0:
dif-=1
print(int(dif/2))
``` | 0 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,649,206,722 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 62 | 0 | import sys
import math
input = sys.stdin.readline
R, X1, Y1, X2, Y2 = map(int, input().split())
TD = math.sqrt((X2-X1)**2 + (Y2-Y1)**2)
print(math.ceil(TD/(R*2))) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
import sys
import math
input = sys.stdin.readline
R, X1, Y1, X2, Y2 = map(int, input().split())
TD = math.sqrt((X2-X1)**2 + (Y2-Y1)**2)
print(math.ceil(TD/(R*2)))
``` | 3 | |
400 | B | Inna and New Matrix of Candies | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"schedules"
] | null | null | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The g... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000).
Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a can... | In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. | [
"3 4\n*G*S\nG**S\n*G*S\n",
"1 3\nS*G\n"
] | [
"2\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3 4\n*G*S\nG**S\n*G*S",
"output": "2"
},
{
"input": "1 3\nS*G",
"output": "-1"
},
{
"input": "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S",
"output": "9"
},
{
"input": "5 10\nG***S**... | 1,622,655,017 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 233 | 6,553,600 | n, m = map(int, input().split())
matrix = []
dist = set()
for i in range(n):
line = list(input())
if line.index('G') > line.index('S'):
print(-1)
exit(0)
dist.add(line.index('S') - line.index('G'))
print(len(dist)) | Title: Inna and New Matrix of Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of th... | ```python
n, m = map(int, input().split())
matrix = []
dist = set()
for i in range(n):
line = list(input())
if line.index('G') > line.index('S'):
print(-1)
exit(0)
dist.add(line.index('S') - line.index('G'))
print(len(dist))
``` | 3 | |
999 | B | Reversing Encryption | PROGRAMMING | 900 | [
"implementation"
] | null | null | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algor... | The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. | Print a string $s$ such that the above algorithm results in $t$. | [
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] | [
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\nj... | 1,629,534,816 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 6,758,400 | n=int(input())
s=input()
l=list(s)
for i in range(1,n+1):
if n%i==0:
l[0:i]=reversed(l[0:i])
print(*l,sep="")
| Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$... | ```python
n=int(input())
s=input()
l=list(s)
for i in range(1,n+1):
if n%i==0:
l[0:i]=reversed(l[0:i])
print(*l,sep="")
``` | 3 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,587,628,230 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 1,228,800 | def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
t = int(input())
a = 0
for i in range(2, t):
b = t
while b != 0:
a += b % i
b //= i
p = gcd(a, t)
print(str(a // p) + '/' + (str((t - 2) // p)))
| Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
t = int(input())
a = 0
for i in range(2, t):
b = t
while b != 0:
a += b % i
b //= i
p = gcd(a, t)
print(str(a // p) + '/' + (str((t - 2) // p)))
``` | 0 |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,592,257,806 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 109 | 0 | import math
Candies=int(input())
def reparto(n):
m=(math.sqrt(8*n+1)-1)/2
print(int(m))
for i in range(1,int(m)):
n-=i
print(i)
return n
print(reparto(Candies)) | Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
import math
Candies=int(input())
def reparto(n):
m=(math.sqrt(8*n+1)-1)/2
print(int(m))
for i in range(1,int(m)):
n-=i
print(i)
return n
print(reparto(Candies))
``` | 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,677,022,367 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | import math
k, n, s, p= map(int,input().split())
if p == 1:
print(k)
else:
sheets = math.ceil(n/s)
pack = math.ceil(sheets*k / p)
print(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
import math
k, n, s, p= map(int,input().split())
if p == 1:
print(k)
else:
sheets = math.ceil(n/s)
pack = math.ceil(sheets*k / p)
print(pack)
``` | 0 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,606,122,115 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | n = int(input())
s = list(map(int,input().split()))
for x in range(1,n):
if s[x-1]>s[x]:
print ((-1,n-x)[sorted(s) == s[x:] + s[:x]])
break
else:
print(0)
| Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
n = int(input())
s = list(map(int,input().split()))
for x in range(1,n):
if s[x-1]>s[x]:
print ((-1,n-x)[sorted(s) == s[x:] + s[:x]])
break
else:
print(0)
``` | -1 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,587,009,591 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 218 | 307,200 | # -*- coding: utf-8 -*-
"""
Created on Wed Apr 15 22:54:40 2020
@author: alexi
"""
#https://codeforces.com/problemset/problem/296/A --- Alexis Galvan
def yaroslav():
length = int(input())
array = list(map(int, input().split()))
if len(array) == 1:
return 'YES'
... | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 15 22:54:40 2020
@author: alexi
"""
#https://codeforces.com/problemset/problem/296/A --- Alexis Galvan
def yaroslav():
length = int(input())
array = list(map(int, input().split()))
if len(array) == 1:
return '... | 0 | |
898 | B | Proper Nutrition | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"number theory"
] | null | null | Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* bu... | First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has.
Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola.
Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar. | If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly... | [
"7\n2\n3\n",
"100\n25\n10\n",
"15\n4\n8\n",
"9960594\n2551\n2557\n"
] | [
"YES\n2 1\n",
"YES\n0 10\n",
"NO\n",
"YES\n1951 1949\n"
] | In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly *n* burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola an... | 750 | [
{
"input": "7\n2\n3",
"output": "YES\n2 1"
},
{
"input": "100\n25\n10",
"output": "YES\n0 10"
},
{
"input": "15\n4\n8",
"output": "NO"
},
{
"input": "9960594\n2551\n2557",
"output": "YES\n1951 1949"
},
{
"input": "10000000\n1\n1",
"output": "YES\n0 10000000"
... | 1,591,375,705 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 29 | 109 | 0 | n = int(input())
a = int(input())
b = int(input())
for i in range(n // a):
if (n - i * a) % b == 0:
print("YES")
print(str(i) + " " + str(int((n - i * a) / b)))
break
else:
continue
else:
print('NO')
| Title: Proper Nutrition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find... | ```python
n = int(input())
a = int(input())
b = int(input())
for i in range(n // a):
if (n - i * a) % b == 0:
print("YES")
print(str(i) + " " + str(int((n - i * a) / b)))
break
else:
continue
else:
print('NO')
``` | 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.