contestId int64 0 1.01k | index stringclasses 40
values | name stringlengths 2 54 | type stringclasses 2
values | rating int64 0 3.4k | tags listlengths 0 7 | title stringclasses 393
values | time-limit stringclasses 7
values | memory-limit stringclasses 6
values | problem-description stringlengths 0 2.97k | input-specification stringlengths 4 1.87k | output-specification stringlengths 4 1.12k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 3.5k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 1
value | testset stringclasses 9
values | passedTestCount int64 1 402 | timeConsumedMillis int64 15 8.06k | memoryConsumedBytes int64 0 514M | code stringlengths 11 61.4k | prompt stringlengths 297 7.35k | response stringlengths 25 61.4k | score float64 2.82 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=β€<=*a*,<=*b*<=β€<=3500, 0<=β€<=*c*,<=*d*<=β€<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,577,636,657 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 156 | 0 | a,b,c,d=map(int,input().split())
ans,res=0,0
temp=max((3*a/10),a-(a/250)*c)
res=max((3*b/10),b-(b/250)*d)
if temp==res:
print("Tie")
elif temp<res:
print("Vasya")
else:
print("Misha") | Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
a,b,c,d=map(int,input().split())
ans,res=0,0
temp=max((3*a/10),a-(a/250)*c)
res=max((3*b/10),b-(b/250)*d)
if temp==res:
print("Tie")
elif temp<res:
print("Vasya")
else:
print("Misha")
``` | 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,641,564,917 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 46 | 0 | a,b,c,d=map(int,input().split())
if b%c!=0:
t=int(b/c)+1
else:
t=int(b/c)
if (t*a)%d!=0:
print(int((t*a)/d)+1)
else:
print(int((t*a)/d))
| 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
a,b,c,d=map(int,input().split())
if b%c!=0:
t=int(b/c)+1
else:
t=int(b/c)
if (t*a)%d!=0:
print(int((t*a)/d)+1)
else:
print(int((t*a)/d))
``` | 3 | |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=Γ<=*m*, each square should be of one of 10 colours, and the flag should be Β«stripedΒ»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100), *n* β the amount of rows, *m* β the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,642,596,366 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | a=[*open(0)][1:]
r=any(any(x!=y for x,y in zip(b,b[1:-1]))for b in a)
print('YNEOS'[r|any(x[0]==y[0] for x,y in zip(a,a[1:]))::2])
| Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=Γ<=*m*, each square should be of one of 10 colours, and the flag should be Β«stripedΒ»: each horizontal row of the flag should contain squares of... | ```python
a=[*open(0)][1:]
r=any(any(x!=y for x,y in zip(b,b[1:-1]))for b in a)
print('YNEOS'[r|any(x[0]==y[0] for x,y in zip(a,a[1:]))::2])
``` | 3.977 |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=β€<=*n*<=β€<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integerΒ β the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,609,497,146 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 0 | def fun(st):
count=0
for i in st:
if i=='Q':
count= count+1
ans=0
leftq=0
rightq=count
for i in st:
if i=='Q':
leftq+=1
rightq-=1
if i=='A':
ans+=leftq*rightq
print(ans)
st= input()
fun(st)
| Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
def fun(st):
count=0
for i in st:
if i=='Q':
count= count+1
ans=0
leftq=0
rightq=count
for i in st:
if i=='Q':
leftq+=1
rightq-=1
if i=='A':
ans+=leftq*rightq
print(ans)
st= input()
fun(st)
``` | 3 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=β€<=*n*<=β€<=100, 1<=β€<=*t*<=β€<=106) β the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=β€<=*a**i*<=β€<=86400) β the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,599,816,795 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 139 | 0 | n, t = [int(x) for x in input().split()]
a = [86400 - int(x) for x in input().split()]
s = 0
for i, x in enumerate(a):
s += x
if s >= t:
print(i+1)
break | Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n, t = [int(x) for x in input().split()]
a = [86400 - int(x) for x in input().split()]
s = 0
for i, x in enumerate(a):
s += x
if s >= t:
print(i+1)
break
``` | 3 | |
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruitsΒ β ... | The first line contains the positive integer *a* (1<=β€<=*a*<=β€<=1000)Β β the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=β€<=*b*<=β€<=1000)Β β the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=β€<=*c*<=β€<=1000)Β β the number of pears Nikolay has... | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1β+β2β+β4β=β7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3β+β6β+β12β=β21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
}... | 1,617,797,049 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 62 | 0 | l = int(input())
a = int(input())
p = int(input())
total=0
while(l>0 and a>1 and p>3):
total+=7
l = l - 1
a = a - 2
p = p - 4
print(total) | Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa... | ```python
l = int(input())
a = int(input())
p = int(input())
total=0
while(l>0 and a>1 and p>3):
total+=7
l = l - 1
a = a - 2
p = p - 4
print(total)
``` | 3 | |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,605,085,176 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 93 | 307,200 | choice=[]
for i in range(4):
choice.append(len(input(' ')[2:]))
Shortest=True
Longest=True
cc=0
ci=None
for i in range(4):
Shortest=True
Longest=True
for j in range(4):
if i==j:continue
if choice[i]<choice[j]*2:Longest=False
if choice[i]*2>choice[j]:Shortest=False
if Shor... | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
choice=[]
for i in range(4):
choice.append(len(input(' ')[2:]))
Shortest=True
Longest=True
cc=0
ci=None
for i in range(4):
Shortest=True
Longest=True
for j in range(4):
if i==j:continue
if choice[i]<choice[j]*2:Longest=False
if choice[i]*2>choice[j]:Shortest=False
... | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=β€<=*a*,<=*b*<=β€<=100) β the number of red and blue socks that Vasya's got. | Print two space-separated integers β the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,678,371,010 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 62 | 0 | a,b=map(int,input().split())
x=min(a,b)
c=max(a,b)
z=(c-x)//2
print(x,z) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a,b=map(int,input().split())
x=min(a,b)
c=max(a,b)
z=(c-x)//2
print(x,z)
``` | 3 | |
892 | B | Wrath | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=106) β the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=β€<=*L**i*<=β€<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer β the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | 1,000 | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0"... | 1,608,194,300 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 1,356 | 77,926,400 | n=int(input())
l=[int(x) for x in input().split()]
k=1;
j=n-l[-1]
for i in range(2, n+1):
if j>n-i+1 and l[-i+1]==0:
k+=1
j=min(j, n-i+1-l[-i])
print(k) | Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ... | ```python
n=int(input())
l=[int(x) for x in input().split()]
k=1;
j=n-l[-1]
for i in range(2, n+1):
if j>n-i+1 and l[-i+1]==0:
k+=1
j=min(j, n-i+1-l[-i])
print(k)
``` | 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,649,469,293 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 0 | a, b = [int(i) for i in input().split()]
c, d, e = 0, 0, 0
for i in range(1, 7):
if abs(a-i) < abs(b-i):
c += 1
elif abs(a-i) == abs(b-i):
d += 1
else:
e += 1
print(c, d, e)
| 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
a, b = [int(i) for i in input().split()]
c, d, e = 0, 0, 0
for i in range(1, 7):
if abs(a-i) < abs(b-i):
c += 1
elif abs(a-i) == abs(b-i):
d += 1
else:
e += 1
print(c, d, e)
``` | 3 | |
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessorΒ β as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno... | The first and only line of input contains two space-separated integers *a* and *b* (0<=β€<=*a*<=β€<=*b*<=β€<=1018). | Output one line containing a single decimal digitΒ β the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso... | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
... | 1,615,988,976 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 109 | 0 | ans = 1
a,b=map(int,input().split())
'''b!/a! (b>=a) = (a+x)!/a! = (a+x)(a+x-1)(a+x-2)(a+x-3).....(a+x-(x-1))(a+x-x)! / a!
= (a+x)(a+x-1)(a+x-2)(a+x-3).....(a+x-(x-1))
= (b)(b-1)(b-2)(b-3)(b-4)........(b-(x-1))
'''
... | Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessorΒ β as is known to many, the phoenix does it like... | ```python
ans = 1
a,b=map(int,input().split())
'''b!/a! (b>=a) = (a+x)!/a! = (a+x)(a+x-1)(a+x-2)(a+x-3).....(a+x-(x-1))(a+x-x)! / a!
= (a+x)(a+x-1)(a+x-2)(a+x-3).....(a+x-(x-1))
= (b)(b-1)(b-2)(b-3)(b-4)........(b-(x-1))
'''
... | 3 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=β€<=*n*<=β€<=50) β the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* β the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4ββ β7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,625,115,662 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 216 | 0 | def f(n, s):
for i in s:
if(i not in ['4', '7']):
print("NO")
return
s1 = s[:n//2]
s2 = s[n//2:]
ans1 = 0
ans2 = 0
for i in range(n//2):
ans1 += int(s1[i])
ans2 += int(s2[i])
if(ans1 == ans2):
print("YES")
else:
print("NO")
... | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
def f(n, s):
for i in s:
if(i not in ['4', '7']):
print("NO")
return
s1 = s[:n//2]
s2 = s[n//2:]
ans1 = 0
ans2 = 0
for i in range(n//2):
ans1 += int(s1[i])
ans2 += int(s2[i])
if(ans1 == ans2):
print("YES")
else:
pr... | 3 | |
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U β move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D β move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L β mo... | The first line contains one number *n* β the length of sequence of commands entered by Ivan (1<=β€<=*n*<=β€<=100).
The second line contains the sequence itself β a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDL... | 1,630,831,003 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 77 | 6,758,400 | #888B (62No. Problem B)
n = int(input())
seq = input()
l = seq.count('L')
r = seq.count('R')
u = seq.count('U')
d = seq.count('D')
steps = (min(l,r) + min(u,d)) * 2
print(steps) | Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U β move from the ce... | ```python
#888B (62No. Problem B)
n = int(input())
seq = input()
l = seq.count('L')
r = seq.count('R')
u = seq.count('U')
d = seq.count('D')
steps = (min(l,r) + min(u,d)) * 2
print(steps)
``` | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=β€<=*n*<=β€<=1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,668,194,717 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | a = int(input())
b = input().split()
sum1 = 0
sum2 = 0
i = 0
while len(b) != 0:
if int(b[0]) > int(b[-1]):
sum1+=int(b[0])
b.pop(0)
else:
sum1 +=int(b[-1])
b.pop()
if len(b) == 0:
break
if int(b[0]) > int(b[-1]):
sum2+=int(b[0])
b.p... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
a = int(input())
b = input().split()
sum1 = 0
sum2 = 0
i = 0
while len(b) != 0:
if int(b[0]) > int(b[-1]):
sum1+=int(b[0])
b.pop(0)
else:
sum1 +=int(b[-1])
b.pop()
if len(b) == 0:
break
if int(b[0]) > int(b[-1]):
sum2+=int(b[0])
... | 3 | |
39 | J | Spelling Check | PROGRAMMING | 1,500 | [
"hashing",
"implementation",
"strings"
] | J. Spelling Check | 2 | 256 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, thatβs why he d... | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible... | [
"abdrakadabra\nabrakadabra\n",
"aa\na\n",
"competition\ncodeforces\n"
] | [
"1\n3\n",
"2\n1 2\n",
"0\n"
] | none | 0 | [
{
"input": "abdrakadabra\nabrakadabra",
"output": "1\n3 "
},
{
"input": "aa\na",
"output": "2\n1 2 "
},
{
"input": "competition\ncodeforces",
"output": "0"
},
{
"input": "ab\na",
"output": "1\n2 "
},
{
"input": "bb\nb",
"output": "2\n1 2 "
},
{
"input"... | 1,688,333,005 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 872 | 10,547,200 | import sys
s1 = sys.stdin.readline().strip()
s2 = sys.stdin.readline().strip()
l = 0
while l < len(s2) and s1[l] == s2[l]:
l += 1
r = len(s1) - 1
while r>=1 and s1[r] == s2[r-1]:
r -= 1
r = len(s1) - r - 1
total = (l + 1) - (len(s1) - r) + 1
if total < 0:
total = 0
print(total... | Title: Spelling Check
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and ... | ```python
import sys
s1 = sys.stdin.readline().strip()
s2 = sys.stdin.readline().strip()
l = 0
while l < len(s2) and s1[l] == s2[l]:
l += 1
r = len(s1) - 1
while r>=1 and s1[r] == s2[r-1]:
r -= 1
r = len(s1) - r - 1
total = (l + 1) - (len(s1) - r) + 1
if total < 0:
total = 0
p... | 3.762354 |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=β€<=*n*<=β€<=105) β the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,683,992,571 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 202 | 23,142,400 | def cleaner(la, lb):
la.sort()
lb.sort()
for i, v in enumerate(la):
if i < len(lb) and lb[i] != v:
return v
return la[-1]
n = int(input())
f = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(cleaner(f, s))
print(cleane... | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
def cleaner(la, lb):
la.sort()
lb.sort()
for i, v in enumerate(la):
if i < len(lb) and lb[i] != v:
return v
return la[-1]
n = int(input())
f = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(cleaner(f, s))
pr... | 3 | |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates β integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=β€<=*n*<=β€<=2Β·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=β€<=*a**i*<=β€<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers β the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4β-β6|β=β2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,546,469,896 | 316 | Python 3 | OK | TESTS | 45 | 358 | 17,408,000 | import math
import os
import random
import re
import sys
def mindist(n, list):
list.sort()
lista = []
for i in range(n-1):
lista.append(list[i+1] - list[i])
mi = min(lista)
count = lista.count(mi)
return [mi, count]
if __name__ == '__main__':
n = int(input())
l... | Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates β integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
import math
import os
import random
import re
import sys
def mindist(n, list):
list.sort()
lista = []
for i in range(n-1):
lista.append(list[i+1] - list[i])
mi = min(lista)
count = lista.count(mi)
return [mi, count]
if __name__ == '__main__':
n = int(input... | 3 | |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=β€<=*d*,<=*h*,<=*v*,<=*e*<=β€<=104), where:
- *d* β the diameter of your cylindrical cup, - *h* β the initial level of water in the cup, - *v* β the speed of drinking process from the cup in milliliters per second, - *e* β the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number β time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,461,948,520 | 820 | Python 3 | OK | TESTS | 23 | 62 | 5,120,000 | import math
def first():
inp = input().split(" ")
d = float(inp[0])
h = float(inp[1])
v = float(inp[2])
e = float(inp[3])
h_y = v/(math.pi*(d/2)**2)
if(h_y > e):
print("YES")
print(h/(h_y - e))
else:
print("NO")
... | Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β when it rains, you go on the street and stay silent for a moment, cont... | ```python
import math
def first():
inp = input().split(" ")
d = float(inp[0])
h = float(inp[1])
v = float(inp[2])
e = float(inp[3])
h_y = v/(math.pi*(d/2)**2)
if(h_y > e):
print("YES")
print(h/(h_y - e))
else:
pr... | 3 | |
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,617,599,746 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 233 | 8,192,000 | n=int(input())
numbers=list(map(int,input().split()))
iN=list()
for i in range(n-1):
iN.append(numbers[i]+numbers[i+1])
iN.append(numbers[n-1])
print(*iN)
| 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())
numbers=list(map(int,input().split()))
iN=list()
for i in range(n-1):
iN.append(numbers[i]+numbers[i+1])
iN.append(numbers[n-1])
print(*iN)
``` | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=β€<=*n*<=β€<=1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,670,480,355 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n=int(input())
a=list(map(int,input().split()))
k=0
s=0
d=0
while len(a)>0:
a1=a[0]
a2=a[len(a)-1]
if a1>a2:
a.pop(0)
c=a1
else:
a.pop(len(a)-1)
c=a2
if k == 0:
k=1
s+=c
else:
k=0
d+=c
print(s,d)
| Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n=int(input())
a=list(map(int,input().split()))
k=0
s=0
d=0
while len(a)>0:
a1=a[0]
a2=a[len(a)-1]
if a1>a2:
a.pop(0)
c=a1
else:
a.pop(len(a)-1)
c=a2
if k == 0:
k=1
s+=c
else:
k=0
d+=c
print(s,d)
``` | 3 | |
784 | G | BF Calculator | PROGRAMMING | 2,000 | [
"*special"
] | null | null | In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, whe... | The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (res... | Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps. | [
"2+3\n",
"9-7\n"
] | [
"++>\n+++>\n<[<+>-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n",
"+++++++++>\n+++++++>\n<[<->-]<\n++++++++++++++++++++++++++++++++++++++++++++++++.\n"
] | You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs. | 0 | [
{
"input": "2+3",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "9-7",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "1+1+1",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++.>"
},
{
"input": "... | 1,498,196,157 | 5,336 | Python 3 | OK | TESTS | 20 | 46 | 5,529,600 | k=eval(input())
o=""
for i in str(k):
a=ord(i)
o+="+"*a+".[-]"
print(o) | Title: BF Calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of intege... | ```python
k=eval(input())
o=""
for i in str(k):
a=ord(i)
o+="+"*a+".[-]"
print(o)
``` | 3 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=β€<=*n*<=β€<=2000;Β 1<=β€<=*k*<=β€<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=β€<=*y**i*<=β€<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number β the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,664,024,432 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | a = input().split()
N = int(a[0])
K = int(a[1])
list = []
kord = input().split()
for i in range(N):
if int(kord[i]) + K > 5:
continue
else:
list.append(kord[i])
arv = len(list)/3
print(int(arv))
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
a = input().split()
N = int(a[0])
K = int(a[1])
list = []
kord = input().split()
for i in range(N):
if int(kord[i]) + K > 5:
continue
else:
list.append(kord[i])
arv = len(list)/3
print(int(arv))
``` | 3 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=β€<=*d*1,<=*d*2,<=*d*3<=β€<=108)Β β the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,636,818,571 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 4,300,800 | t = list(map(int,input().split(" ")))
print(min(sum(t),2*(t[1]+t[0]),2*(t[1]+t[2]),2*(t[0]+t[2])))
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
t = list(map(int,input().split(" ")))
print(min(sum(t),2*(t[1]+t[0]),2*(t[1]+t[2]),2*(t[0]+t[2])))
``` | 3 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* β the amount of eggs (7<=β€<=*n*<=β€<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,687,535,206 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 124 | 0 | n = int(input())
l = ["R","O","Y","G","B","I","V"]
s = ""
p = 0
while len(s) < n:
if p == 7:
diff = n - len(s)
if diff > 3:
p = 0
else:
p = 3
s += l[p]
p += 1
print(s) | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
n = int(input())
l = ["R","O","Y","G","B","I","V"]
s = ""
p = 0
while len(s) < n:
if p == 7:
diff = n - len(s)
if diff > 3:
p = 0
else:
p = 3
s += l[p]
p += 1
print(s)
``` | 3.969 |
725 | B | Food on the Plane | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats... | The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=β€<=*n*<=β€<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. | Print one integerΒ β the number of seconds Vasya has to wait until he gets his lunch. | [
"1f\n",
"2d\n",
"4a\n",
"5e\n"
] | [
"1\n",
"10\n",
"11\n",
"18\n"
] | In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisl... | 1,000 | [
{
"input": "1f",
"output": "1"
},
{
"input": "2d",
"output": "10"
},
{
"input": "4a",
"output": "11"
},
{
"input": "5e",
"output": "18"
},
{
"input": "2c",
"output": "13"
},
{
"input": "1b",
"output": "5"
},
{
"input": "1000000000000000000d... | 1,477,150,902 | 2,202 | Python 3 | OK | TESTS | 119 | 62 | 0 | ns = input()
trantab = str.maketrans('abcdef', '456321')
n = int(ns[:-1])
s = ns[-1]
m = int(s.translate(trantab))
ans = 0
if n % 4 == 1 or n % 4 == 3:
ans += (n // 4) * 16 + m
elif n % 2 == 2:
ans += (n // 4) * 16 + 7 + m
else:
ans += ((n - 1) // 4) * 16 + 7 + m
print(ans)
| Title: Food on the Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' ... | ```python
ns = input()
trantab = str.maketrans('abcdef', '456321')
n = int(ns[:-1])
s = ns[-1]
m = int(s.translate(trantab))
ans = 0
if n % 4 == 1 or n % 4 == 3:
ans += (n // 4) * 16 + m
elif n % 2 == 2:
ans += (n // 4) * 16 + 7 + m
else:
ans += ((n - 1) // 4) * 16 + 7 + m
print(an... | 3 | |
706 | A | Beru-taxi | PROGRAMMING | 900 | [
"brute force",
"geometry",
"implementation"
] | null | null | Vasiliy lives at point (*a*,<=*b*) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested *n* available Beru-taxi nearby. The *i*-th taxi is located at point (*x**i*,<=*y**i*) and moves with a speed *v**i*.
Consider that each of *n* drivers will m... | The first line of the input contains two integers *a* and *b* (<=-<=100<=β€<=*a*,<=*b*<=β€<=100)Β β coordinates of Vasiliy's home.
The second line contains a single integer *n* (1<=β€<=*n*<=β€<=1000)Β β the number of available Beru-taxi cars nearby.
The *i*-th of the following *n* lines contains three integers *x**i*, *y*... | Print a single real valueΒ β the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answ... | [
"0 0\n2\n2 0 1\n0 2 2\n",
"1 3\n3\n3 3 2\n-2 3 6\n-2 7 10\n"
] | [
"1.00000000000000000000",
"0.50000000000000000000"
] | In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer.
In the second sample, cars 2 and 3 will arrive simultaneously. | 500 | [
{
"input": "0 0\n2\n2 0 1\n0 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 3\n3\n3 3 2\n-2 3 6\n-2 7 10",
"output": "0.50000000000000000000"
},
{
"input": "2 2\n10\n8 10 1\n14 18 5\n2 2 1\n4 2 2\n5 2 1\n0 2 1\n2 10 4\n10 2 4\n14 18 20\n14 18 10",
"output": "0.000000000000... | 1,688,836,924 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 46 | 0 | import math
a,b=input().split()
a=int(a)
b=int(b)
number_of_cars=int(input())
mylist=[]
for i in range(number_of_cars):
e,f,g=input().split()
e=int(e)
f=int(f)
g=int(g)
distance_formula=math.sqrt((e-a)**2+(f-b)**2)
mylist.append(distance_formula/g)
print(min(mylist)) | Title: Beru-taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy lives at point (*a*,<=*b*) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested *n* available Beru-taxi nearby. The *i*-th taxi is located at po... | ```python
import math
a,b=input().split()
a=int(a)
b=int(b)
number_of_cars=int(input())
mylist=[]
for i in range(number_of_cars):
e,f,g=input().split()
e=int(e)
f=int(f)
g=int(g)
distance_formula=math.sqrt((e-a)**2+(f-b)**2)
mylist.append(distance_formula/g)
print(min(mylist))
``` | 3 | |
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,686,204,484 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | a = int(input())
b = int(input())
c = int(input())
num= [a, b, c]
print(max(a * b * c, a + b + c, a * b + c, a * (b + c), a + b * c, (a + b) * c))
| 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())
num= [a, b, c]
print(max(a * b * c, a + b + c, a * b + c, a * (b + c), a + b * c, (a + b) * c))
``` | 3 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=β€<=*k*,<=*l*<=β€<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number β the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,585,471,660 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 310 | 0 | x=int(input())
y=int(input())
c=0
while(y%x==0):
y=y//x
c=c+1
if(y>1):
print("NO")
else:
print("YES")
print(c-1) | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
x=int(input())
y=int(input())
c=0
while(y%x==0):
y=y//x
c=c+1
if(y>1):
print("NO")
else:
print("YES")
print(c-1)
``` | 3 | |
840 | A | Leha and Function | PROGRAMMING | 1,300 | [
"combinatorics",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) β mathematical expectation of the minimal element among all *k*-element subsets.
But only function does n... | First line of input data contains single integer *m* (1<=β€<=*m*<=β€<=2Β·105) β length of arrays *A* and *B*.
Next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=β€<=*a**i*<=β€<=109) β array *A*.
Next line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=β€<=*b**i*<=β€<=109) β array *B*. | Output *m* integers *a*'1,<=*a*'2,<=...,<=*a*'*m* β array *A*' which is permutation of the array *A*. | [
"5\n7 3 5 3 4\n2 1 3 2 3\n",
"7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2\n"
] | [
"4 7 3 5 3\n",
"2 6 4 5 8 8 6\n"
] | none | 500 | [
{
"input": "5\n7 3 5 3 4\n2 1 3 2 3",
"output": "4 7 3 5 3"
},
{
"input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2",
"output": "2 6 4 5 8 8 6"
}
] | 1,603,745,461 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 904 | 34,918,400 | m = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_streak = a.copy()
b_streak = b.copy()
a_streak.sort(reverse=True)
b_streak.sort()
mapping = {}
for ind, b_i in enumerate(b_streak):
if b_i not in mapping:
mapping[b_i] = [a_streak[ind]]
else... | Title: Leha and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) β m... | ```python
m = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_streak = a.copy()
b_streak = b.copy()
a_streak.sort(reverse=True)
b_streak.sort()
mapping = {}
for ind, b_i in enumerate(b_streak):
if b_i not in mapping:
mapping[b_i] = [a_streak[ind]]... | 3 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=β€<=*n*<=β€<=90)Β β the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=β€<=*t*1<=<<=*t*2<=<<=... *t**n*<=β€<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21,β22,β...,β35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,495,772,704 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | import sys
number_of_minutes = int(input())
time_range = input()
minutes = time_range.split()
tmp = 0
for i in range(number_of_minutes):
if int(tmp)+15 < int(minutes[i]):
print(str(int(tmp)+15))
sys.exit()
tmp = minutes[i]
#print("tmp la : " + str(tmp))
if int(tmp)+15>90:
print("90... | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
import sys
number_of_minutes = int(input())
time_range = input()
minutes = time_range.split()
tmp = 0
for i in range(number_of_minutes):
if int(tmp)+15 < int(minutes[i]):
print(str(int(tmp)+15))
sys.exit()
tmp = minutes[i]
#print("tmp la : " + str(tmp))
if int(tmp)+15>90:
... | 3 | |
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U β move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D β move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L β mo... | The first line contains one number *n* β the length of sequence of commands entered by Ivan (1<=β€<=*n*<=β€<=100).
The second line contains the sequence itself β a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDL... | 1,639,464,640 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 77 | 0 | n, s, l, r, u, d = int(input()), input(), 0, 0, 0, 0
for x in s:
if x == 'L': l += 1
elif x == 'R': r += 1
elif x == 'U': u += 1
else: d += 1
print(n - abs(l - r) - abs(u - d)) | Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U β move from the ce... | ```python
n, s, l, r, u, d = int(input()), input(), 0, 0, 0, 0
for x in s:
if x == 'L': l += 1
elif x == 'R': r += 1
elif x == 'U': u += 1
else: d += 1
print(n - abs(l - r) - abs(u - d))
``` | 3 | |
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,679,981,276 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 62 | 1,638,400 | [n, k] = list(map(int, input().split(" ")))
days = list(map(int, input().split(" ")))
order = []
i = 0
while (k > 0):
if (k - min(days) < 0):
break
minimum = min(days)
k -= minimum
i += 1
order.append(days.index(minimum) + 1)
days[days.index(minimum)] = 10001
print(i)
if(i > 0):
p... | 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
[n, k] = list(map(int, input().split(" ")))
days = list(map(int, input().split(" ")))
order = []
i = 0
while (k > 0):
if (k - min(days) < 0):
break
minimum = min(days)
k -= minimum
i += 1
order.append(days.index(minimum) + 1)
days[days.index(minimum)] = 10001
print(i)
if(i >... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for examp... | The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$)Β β length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consist... | Print a single integerΒ β the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. | [
"5 1 10\n01000\n",
"5 10 1\n01000\n",
"7 2 3\n1111111\n"
] | [
"11\n",
"2\n",
"0\n"
] | In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
Β«01000Β» $\to$ Β«10000Β» $\to$ Β«11111Β».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1... | 0 | [
{
"input": "5 1 10\n01000",
"output": "11"
},
{
"input": "5 10 1\n01000",
"output": "2"
},
{
"input": "7 2 3\n1111111",
"output": "0"
},
{
"input": "1 60754033 959739508\n0",
"output": "959739508"
},
{
"input": "1 431963980 493041212\n1",
"output": "0"
},
... | 1,530,460,369 | 6,469 | PyPy 3 | OK | TESTS | 115 | 171 | 3,788,800 | # -*- coding: utf-8 -*-
def problem():
in1 = input()
in2 = input()
# in1 = '5 5 10'
# in2 = '101010'
inp1 = list(map(int, in1.split()))
n = inp1[0]
exc_cost = inp1[1]
flip_cost = inp1[2]
s = in2;
zeros = 0
sign = s[0]
for num in s[1:]:
# ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the fo... | ```python
# -*- coding: utf-8 -*-
def problem():
in1 = input()
in2 = input()
# in1 = '5 5 10'
# in2 = '101010'
inp1 = list(map(int, in1.split()))
n = inp1[0]
exc_cost = inp1[1]
flip_cost = inp1[2]
s = in2;
zeros = 0
sign = s[0]
for num in s[... | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers β they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number β the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,694,659,945 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 122 | 0 | # n, k = [int(a) for a in input().split()]
# scores = list(map(int, input().split()))
#
# x = 0
#
# for i in range(n):
# if scores[i] >= scores[k-1] and scores[i] > 0:
# x += 1
#
# print(x)
#
############# Task 2
#
# print("+".join(list(map(str, sorted(input().split('+'))))))
amt = int(input... | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
# n, k = [int(a) for a in input().split()]
# scores = list(map(int, input().split()))
#
# x = 0
#
# for i in range(n):
# if scores[i] >= scores[k-1] and scores[i] > 0:
# x += 1
#
# print(x)
#
############# Task 2
#
# print("+".join(list(map(str, sorted(input().split('+'))))))
amt =... | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,685,872,462 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 124 | 0 | s=input()
d=s.split("WUB")
b=''
for i in d:
if (i==''):
continue
b+= (i+' ')
print(b) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
s=input()
d=s.split("WUB")
b=''
for i in d:
if (i==''):
continue
b+= (i+' ')
print(b)
``` | 3 | |
580 | B | Kefa and Company | PROGRAMMING | 1,500 | [
"binary search",
"sortings",
"two pointers"
] | null | null | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend... | The first line of the input contains two space-separated integers, *n* and *d* (1<=β€<=*n*<=β€<=105, ) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next *n* lines contain the descriptions of Kefa's friends, the (*i*<=+<=1)-th line contains the... | Print the maximum total friendship factir that can be reached. | [
"4 5\n75 5\n0 100\n150 20\n75 1\n",
"5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n"
] | [
"100\n",
"111\n"
] | In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends. | 1,250 | [
{
"input": "4 5\n75 5\n0 100\n150 20\n75 1",
"output": "100"
},
{
"input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54",
"output": "111"
},
{
"input": "1 1000000000\n15 12",
"output": "12"
},
{
"input": "5 1\n5 9\n2 10\n8 5\n18 12\n1 1",
"output": "12"
},
{
"input": "3... | 1,693,938,700 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 452 | 17,203,200 | import sys
input=sys.stdin.readline
ppl,diff = map(int,input().split())
lst = []
for i in range(ppl):
lst.append(list(map(int,input().split())))
lst.sort()
l,r,sm,mx = 0,0,0,0
while r<ppl:
sm+=lst[r][-1]
while lst[r][0]-lst[l][0]>=diff:
sm-=lst[l][-1]
l+=1
mx = max(mx,sm)
... | Title: Kefa and Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the a... | ```python
import sys
input=sys.stdin.readline
ppl,diff = map(int,input().split())
lst = []
for i in range(ppl):
lst.append(list(map(int,input().split())))
lst.sort()
l,r,sm,mx = 0,0,0,0
while r<ppl:
sm+=lst[r][-1]
while lst[r][0]-lst[l][0]>=diff:
sm-=lst[l][-1]
l+=1
mx = max... | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=β€<=*n*<=β€<=100) β amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,582,439,418 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 310 | 0 | def howManyDiffers(n, nums):
differs = [i for i in nums if i % 2 == 0]
evenness = [i for i in nums if i % 2 != 0]
if len(evenness) == 1:
return nums.index(evenness[0]) + 1
return nums.index(differs[0]) + 1
n = int(input())
nums = [int(i) for i in input().split()]
print(howManyDiffe... | 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
def howManyDiffers(n, nums):
differs = [i for i in nums if i % 2 == 0]
evenness = [i for i in nums if i % 2 != 0]
if len(evenness) == 1:
return nums.index(evenness[0]) + 1
return nums.index(differs[0]) + 1
n = int(input())
nums = [int(i) for i in input().split()]
print(ho... | 3.9225 |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | The first and only line of input contains an integer *n* (1<=β€<=*n*<=β€<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooo... | 1,666,977,208 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 46 | 0 | l=[1,1]
for z in range(15):
l.append(l[-1]+l[-2])
n=int(input())
s=""
for y in range(1,n+1):
if y not in l:
s+="o"
else :
s+="O"
print(s) | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
l=[1,1]
for z in range(15):
l.append(l[-1]+l[-2])
n=int(input())
s=""
for y in range(1,n+1):
if y not in l:
s+="o"
else :
s+="O"
print(s)
``` | 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,593,454,658 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 6,758,400 | s =input()
l,u = 0,0
for i in s:
if (i>='a'and i<='z'):
l=l+1 #counting lower case
if (i>='A'and i<='Z'):
u=u+1
if l>u or l==u:
print(s.lower())
else:
print(s.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s =input()
l,u = 0,0
for i in s:
if (i>='a'and i<='z'):
l=l+1 #counting lower case
if (i>='A'and i<='Z'):
u=u+1
if l>u or l==u:
print(s.lower())
else:
print(s.upper())
``` | 3.932911 |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number β the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,697,426,724 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 31 | 0 | base_list = input().split(' ')
n = int(base_list[0])
k = int(base_list[1])
for _ in range(k):
if n % 10 == 0:
n = n / 10
else:
n -= 1
print(int(n)) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
base_list = input().split(' ')
n = int(base_list[0])
k = int(base_list[1])
for _ in range(k):
if n % 10 == 0:
n = n / 10
else:
n -= 1
print(int(n))
``` | 3 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=105). The numbers are separated by spaces. | In the first line print integer *t* β the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub>β=β0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,665,348,764 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 810 | 10,342,400 | n = int(input())
a = [int(x) for x in input().split()]
b = list(set(a))
ind = [10000000]*(100001)
cd = [0]*(100001)
ans = []
for i in range(n):
if ind[a[i]] == 10000000:
ind[a[i]] = i
else:
if cd[a[i]] == 0:
cd[a[i]] = i - ind[a[i]]
ind[a[i]] = i
else:
if cd[a[i]] == (i-ind[a[i]]):
... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
n = int(input())
a = [int(x) for x in input().split()]
b = list(set(a))
ind = [10000000]*(100001)
cd = [0]*(100001)
ans = []
for i in range(n):
if ind[a[i]] == 10000000:
ind[a[i]] = i
else:
if cd[a[i]] == 0:
cd[a[i]] = i - ind[a[i]]
ind[a[i]] = i
else:
if cd[a[i]] == (i-ind[a[... | 3 | |
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,668,419,665 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 61 | 0 | from math import gcd
n = int(input())
g = 0
for i in map(int, input().split()): g = gcd(g,i)
print(g*n) | 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
from math import gcd
n = int(input())
g = 0
for i in map(int, input().split()): g = gcd(g,i)
print(g*n)
``` | 3 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=β€<=*n*<=β€<=1000, 1<=β€<=*h*<=β€<=1000)Β β the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integerΒ β the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.
In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,691,686,727 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n, h = map(int, input().split())
heights = list(map(int, input().split()))
width = n + sum(1 if height > h else 0 for height in heights)
print(width)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n, h = map(int, input().split())
heights = list(map(int, input().split()))
width = n + sum(1 if height > h else 0 for height in heights)
print(width)
``` | 3 | |
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,680,609,903 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 62 | 0 | import math
from collections import defaultdict
def I(): return int(input())
def II(): return map(int, input().split())
def IL(): return list(map(int, input().split()))
def SIL(): return sorted(map(int, input().split()))
def solve():
nums=IL()
nums.sort()
# obj=defaultdict(bool)
max_=0
... | 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
import math
from collections import defaultdict
def I(): return int(input())
def II(): return map(int, input().split())
def IL(): return list(map(int, input().split()))
def SIL(): return sorted(map(int, input().split()))
def solve():
nums=IL()
nums.sort()
# obj=defaultdict(bool)
m... | 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,671,255,711 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n = map(int, input().split())
a = m * n
if a % 2 == 0:
print(int(a / 2))
else:
a = a - 1
print(int(a / 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 = map(int, input().split())
a = m * n
if a % 2 == 0:
print(int(a / 2))
else:
a = a - 1
print(int(a / 2))
``` | 3.977 |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=β€<=*a*<=β€<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,652,610,010 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 4,300,800 | n = int(input())
i = 0
for i in range(16):
n += 1
i += 1
if '8' in str(n):
break
print(i) | Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
n = int(input())
i = 0
for i in range(16):
n += 1
i += 1
if '8' in str(n):
break
print(i)
``` | 3 | |
837 | D | Round Subset | PROGRAMMING | 2,100 | [
"dp",
"math"
] | null | null | Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible. | The first line contains two integer numbers *n* and *k* (1<=β€<=*n*<=β€<=200,<=1<=β€<=*k*<=β€<=*n*).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1018). | Print maximal roundness of product of the chosen subset of length *k*. | [
"3 2\n50 4 20\n",
"5 3\n15 16 3 25 9\n",
"3 3\n9 77 13\n"
] | [
"3\n",
"3\n",
"0\n"
] | In the first example there are 3 subsets of 2 numbers. [50,β4] has product 200 with roundness 2, [4,β20] β product 80, roundness 1, [50,β20] β product 1000, roundness 3.
In the second example subset [15,β16,β25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0. | 0 | [
{
"input": "3 2\n50 4 20",
"output": "3"
},
{
"input": "5 3\n15 16 3 25 9",
"output": "3"
},
{
"input": "3 3\n9 77 13",
"output": "0"
},
{
"input": "1 1\n200000000",
"output": "8"
},
{
"input": "1 1\n3",
"output": "0"
},
{
"input": "3 1\n10000000000000... | 1,649,482,658 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 99 | 1,326 | 14,028,800 |
n,k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [[-1 for i in range(5200)] for j in range(234)]
dp[0][0] = 0
for _ in range(n):
t,f = 0,0
p = arr[_]
while p%2 == 0:
t+=1
p//= 2
while p%5 == 0:
f += 1
p //= 5
for i in range(k-1... | Title: Round Subset
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected number... | ```python
n,k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [[-1 for i in range(5200)] for j in range(234)]
dp[0][0] = 0
for _ in range(n):
t,f = 0,0
p = arr[_]
while p%2 == 0:
t+=1
p//= 2
while p%5 == 0:
f += 1
p //= 5
for i in... | 3 | |
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,380,805,773 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 312 | 0 | #!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
s = [list(readln()) for _ in range(3)]
for x in range(1, 10**5 + 1):
ss = x + s[0][1] + s[0][2]
y = ss - s[1][0] - s[1][2]
z = ss - s[2][0] - s[2][1]
if x + y + z == ss:
s[0][0] = x
s[1][1] = y
s[2][2] = z... | 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
#!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
s = [list(readln()) for _ in range(3)]
for x in range(1, 10**5 + 1):
ss = x + s[0][1] + s[0][2]
y = ss - s[1][0] - s[1][2]
z = ss - s[2][0] - s[2][1]
if x + y + z == ss:
s[0][0] = x
s[1][1] = y
s... | 3 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=β€<=*l*<=β€<=*r*<=β€<=1018; *r*<=-<=*l*<=β€<=50). | Print three positive space-separated integers *a*, *b*, *c*Β β three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2,β4) is not coprime and pairs (2,β3) and (3,β4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,427,698,669 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 62 | 0 | def gcd(a, b):
if b == 0:
return a;
return gcd(b, a % b)
l, r = map(int, input().split())
found = False
for a in range(l, r-1):
for b in range(a+1, r):
if gcd(a, b) == 1:
for c in range(b+1, r+1):
if gcd(b, c) == 1 and gcd(a, c) != 1:
... | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
def gcd(a, b):
if b == 0:
return a;
return gcd(b, a % b)
l, r = map(int, input().split())
found = False
for a in range(l, r-1):
for b in range(a+1, r):
if gcd(a, b) == 1:
for c in range(b+1, r+1):
if gcd(b, c) == 1 and gcd(a, c) != 1:
... | 3 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=2Β·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,643,116,269 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 204,800 | n = int(input())
t = input()
kol1=t.count('0')
kol2=t.count('1')
print(n-(min(kol1,kol2)*2))
| Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n = int(input())
t = input()
kol1=t.count('0')
kol2=t.count('1')
print(n-(min(kol1,kol2)*2))
``` | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,698,685,387 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | a = str
a = input()
b = a[0].upper() + a[1:]
print(b)
# bce001
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
a = str
a = input()
b = a[0].upper() + a[1:]
print(b)
# bce001
``` | 3 | |
765 | C | Table Tennis Game 2 | PROGRAMMING | 1,200 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* poi... | The first line contains three space-separated integers *k*, *a* and *b* (1<=β€<=*k*<=β€<=109, 0<=β€<=*a*,<=*b*<=β€<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | 1,250 | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "... | 1,637,204,598 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 279 | 77 | 0 | k,a,b = [int(i) for i in input().split()]
t = int(a//k + b//k)
if a//k == 0 and b%k != 0:
print(-1)
elif b//k == 0 and a%k != 0:
print(-1)
else:
print(t if t != 0 or a+b == 0 else -1)
| Title: Table Tennis Game 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scor... | ```python
k,a,b = [int(i) for i in input().split()]
t = int(a//k + b//k)
if a//k == 0 and b%k != 0:
print(-1)
elif b//k == 0 and a%k != 0:
print(-1)
else:
print(t if t != 0 or a+b == 0 else -1)
``` | 3 | |
103 | A | Testing Pants for Sadness | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | A. Testing Pants for Sadness | 2 | 256 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=β€<=*a**i*<=β€<=109), the number of answer variants to question *i*. | Print a single number β the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] | [
"2",
"5",
"10"
] | Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the ... | 500 | [
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "... | 1,567,750,901 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 248 | 0 | n = int(input())
sum1 = 0
cnt = 1
s = input()
l = [int(i) for i in s.split()]
if n > 1:
for i in range(1, n):
cnt += 1
sum1 += 1 + (cnt * (l[i] - 1))
sum1 += l[0]
print(sum1)
else:
print(l[0])
| Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* q... | ```python
n = int(input())
sum1 = 0
cnt = 1
s = input()
l = [int(i) for i in s.split()]
if n > 1:
for i in range(1, n):
cnt += 1
sum1 += 1 + (cnt * (l[i] - 1))
sum1 += l[0]
print(sum1)
else:
print(l[0])
``` | 3.938 |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integersΒ β *n*, *m* and *z* (1<=β€<=*n*,<=*m*,<=*z*<=β€<=104). | Print single integerΒ β the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third testΒ β only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,570,114,657 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | def lcm(a,b):
if(a<b):
c=b
while(1):
if(c%a==0 and c%b==0):
return c
c+=1
else :
c=a
while(1):
if(c%a==0 and c%b==0):
return c
c+=1
x = input()
a = x.split(" ")
print(int(int(a[2])/(lcm(int(a[0]),int... | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
def lcm(a,b):
if(a<b):
c=b
while(1):
if(c%a==0 and c%b==0):
return c
c+=1
else :
c=a
while(1):
if(c%a==0 and c%b==0):
return c
c+=1
x = input()
a = x.split(" ")
print(int(int(a[2])/(lcm(int... | 3 | |
749 | C | Voting | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"two pointers"
] | null | null | There are *n* employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of employees.
The next line contains *n* characters. The *i*-th character is 'D' if the *i*-th employee is from depublicans fraction or 'R' if he is from remocrats. | Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win. | [
"5\nDDRRR\n",
"6\nDDRRRR\n"
] | [
"D\n",
"R\n"
] | Consider one of the voting scenarios for the first sample:
1. Employee 1 denies employee 5 to vote. 1. Employee 2 denies employee 3 to vote. 1. Employee 3 has no right to vote and skips his turn (he was denied by employee 2). 1. Employee 4 denies employee 2 to vote. 1. Employee 5 has no right to vote and skips h... | 1,500 | [
{
"input": "5\nDDRRR",
"output": "D"
},
{
"input": "6\nDDRRRR",
"output": "R"
},
{
"input": "1\nD",
"output": "D"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "2\nDR",
"output": "D"
},
{
"input": "3\nRDD",
"output": "D"
},
{
"input": "... | 1,668,507,065 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 144 | 124 | 12,595,200 | from collections import deque
n=int(input())
a=input()
q1=deque()
q2=deque()
for i in range(n):
if a[i]=='D':
q1.append(i)
else:
q2.append(i)
while q1 and q2:
# print(q1[0],q2[0])
if q1[0]<q2[0]:
q2.popleft()
q1.append(n+q1.popleft())
else:
q1.... | Title: Voting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to on... | ```python
from collections import deque
n=int(input())
a=input()
q1=deque()
q2=deque()
for i in range(n):
if a[i]=='D':
q1.append(i)
else:
q2.append(i)
while q1 and q2:
# print(q1[0],q2[0])
if q1[0]<q2[0]:
q2.popleft()
q1.append(n+q1.popleft())
else:
... | 3 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School β0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=β€<=*n*<=β€<=5000) β the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=β€<=*t**i*<=β€<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* β the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,699,912,238 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 307,200 | n = int(input())
user_input = input()
input_list = user_input.split(" ")
skills = {
'prog' : [],
'math' : [],
'PE' : []
}
for i,value in enumerate(input_list):
if value == '1':
skills['prog'].append(i+1)
if value == '2':
skills['math'].append(i+1)
if value == '... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School β0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n = int(input())
user_input = input()
input_list = user_input.split(" ")
skills = {
'prog' : [],
'math' : [],
'PE' : []
}
for i,value in enumerate(input_list):
if value == '1':
skills['prog'].append(i+1)
if value == '2':
skills['math'].append(i+1)
if ... | 3 | |
873 | C | Strange Game On Matrix | PROGRAMMING | 1,600 | [
"greedy",
"two pointers"
] | null | null | Ivan is playing a strange game.
He has a matrix *a* with *n* rows and *m* columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows:
1. Initially Ivan's... | The first line contains three integer numbers *n*, *m* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=100, 1<=β€<=*m*<=β€<=100).
Then *n* lines follow, *i*-th of them contains *m* integer numbers β the elements of *i*-th row of matrix *a*. Each number is either 0 or 1. | Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. | [
"4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1\n",
"3 2 1\n1 0\n0 1\n0 0\n"
] | [
"4 1\n",
"2 0\n"
] | In the first example Ivan will replace the element *a*<sub class="lower-index">1,β2</sub>. | 0 | [
{
"input": "4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1",
"output": "4 1"
},
{
"input": "3 2 1\n1 0\n0 1\n0 0",
"output": "2 0"
},
{
"input": "3 4 2\n0 1 1 1\n1 0 1 1\n1 0 0 1",
"output": "7 0"
},
{
"input": "3 57 3\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1... | 1,630,824,486 | 1,086 | PyPy 3 | OK | TESTS | 20 | 124 | 22,528,000 | import bisect
import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [0, 0]
for j in range(m):
x = []
for i in range(n):
if a[i][j] == 1:
x.append(i)
m, c = 0, 0
for i in range(len(x)):
... | Title: Strange Game On Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan is playing a strange game.
He has a matrix *a* with *n* rows and *m* columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in thi... | ```python
import bisect
import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [0, 0]
for j in range(m):
x = []
for i in range(n):
if a[i][j] == 1:
x.append(i)
m, c = 0, 0
for i in range(le... | 3 | |
557 | B | Pasha and Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys a... | The first line of the input contains two integers, *n* and *w* (1<=β€<=*n*<=β€<=105, 1<=β€<=*w*<=β€<=109)Β β the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *... | Print a single real number β the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] | [
"3",
"18",
"4.5"
] | Pasha also has candies that he is going to give to girls but that is another task... | 1,000 | [
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 ... | 1,436,315,611 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 404 | 20,480,000 | l2 = input().split()
n = int(l2[0])
w = int(l2[1])
l = map(int, input().split())
l = sorted(l, reverse=True)
minB = 2000000000
minG = 2000000000
for i in range(n):
minB = min(minB, l[i])
minG = min(minB, l[i+n])
x = min(minB/2, minG)
print(min(w,n*x*3))
| Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ... | ```python
l2 = input().split()
n = int(l2[0])
w = int(l2[1])
l = map(int, input().split())
l = sorted(l, reverse=True)
minB = 2000000000
minG = 2000000000
for i in range(n):
minB = min(minB, l[i])
minG = min(minB, l[i+n])
x = min(minB/2, minG)
print(min(w,n*x*3))
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,580,437,575 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | s=input()
t=list(reversed(list(input())))
for letter_s,letter_t in zip(s,t):
if letter_s!=letter_t:
print("NO")
break
else:
print("YES") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s=input()
t=list(reversed(list(input())))
for letter_s,letter_t in zip(s,t):
if letter_s!=letter_t:
print("NO")
break
else:
print("YES")
``` | 3.9455 |
603 | B | Moodular Arithmetic | PROGRAMMING | 1,800 | [
"combinatorics",
"dfs and similar",
"dsu",
"math",
"number theory"
] | null | null | As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers *k* and *p*, w... | The input consists of two space-separated integers *p* and *k* (3<=β€<=*p*<=β€<=1<=000<=000, 0<=β€<=*k*<=β€<=*p*<=-<=1) on a single line. It is guaranteed that *p* is an odd prime number. | Print a single integer, the number of distinct functions *f* modulo 109<=+<=7. | [
"3 2\n",
"5 4\n"
] | [
"3\n",
"25\n"
] | In the first sample, *p*β=β3 and *k*β=β2. The following functions work:
1. *f*(0)β=β0, *f*(1)β=β1, *f*(2)β=β2. 1. *f*(0)β=β0, *f*(1)β=β2, *f*(2)β=β1. 1. *f*(0)β=β*f*(1)β=β*f*(2)β=β0. | 1,000 | [
{
"input": "3 2",
"output": "3"
},
{
"input": "5 4",
"output": "25"
},
{
"input": "7 2",
"output": "49"
},
{
"input": "7 6",
"output": "343"
},
{
"input": "10007 25",
"output": "100140049"
},
{
"input": "40037 4",
"output": "602961362"
},
{
... | 1,481,717,275 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 139 | 307,200 | MOD=int(1e9+7)
n,k=map(int,input().split())
if k<2:p=n-(1-k)
else:
t=1
a=k
while a!=1:
a=a*k%n
t+=1
p=(n-1)//t
print(pow(n,p,MOD))
| Title: Moodular Arithmetic
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin w... | ```python
MOD=int(1e9+7)
n,k=map(int,input().split())
if k<2:p=n-(1-k)
else:
t=1
a=k
while a!=1:
a=a*k%n
t+=1
p=(n-1)//t
print(pow(n,p,MOD))
``` | 3 | |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=β€<=*n*<=β€<=100)Β β the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=β€<=*a**i*<=β€<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number β the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1,β6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1,β3,β7,β8), (1,β2,β7,β8), (1,β2,β3,β8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,524,061,650 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 78 | 7,065,600 | n=int(input())
v=[int(i) for i in input().split()]
mx=0
for i in range(1,len(v)):
mx=max(mx,v[i]-v[i-1])
mn=int(1e9)
for i in range(1,len(v)-1):
mn=min(mn,max(mx,v[i+1]-v[i-1]))
print(mn) | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n=int(input())
v=[int(i) for i in input().split()]
mx=0
for i in range(1,len(v)):
mx=max(mx,v[i]-v[i-1])
mn=int(1e9)
for i in range(1,len(v)-1):
mn=min(mn,max(mx,v[i+1]-v[i-1]))
print(mn)
``` | 3 | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=β€<=*n*<=β€<=105,<=0<=β€<=*m*<=β€<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*,<=1<=β€<=*w**i*<=β€<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,686,140,202 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 280 | 34,304,000 | from heapq import heappop, heappush
from math import inf
from sys import stdin
def dijkstra(graph, start):
dist = [inf] * len(graph)
dist[start] = 0
parent = [-1] * len(graph)
q = [(0, start)]
while q:
d, u = heappop(q)
if d > dist[u]:
continue
... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
from heapq import heappop, heappush
from math import inf
from sys import stdin
def dijkstra(graph, start):
dist = [inf] * len(graph)
dist[start] = 0
parent = [-1] * len(graph)
q = [(0, start)]
while q:
d, u = heappop(q)
if d > dist[u]:
continu... | 3.604415 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=β€<=*p**i*<=β€<=100) β the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,683,999,591 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | n = int(input())
p = list(map(int,input().split(maxsplit = n)))
c = 0
for i in range(n):
c += p[i]
print(c/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n = int(input())
p = list(map(int,input().split(maxsplit = n)))
c = 0
for i in range(n):
c += p[i]
print(c/n)
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* β the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,690,218,886 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | k=int(input())
t=list(map(int,input().split()))
p=[0]*k
for i in range(k):
p[t[i]-1]=i+1
print(' '.join(map(str,p))) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
k=int(input())
t=list(map(int,input().split()))
p=[0]*k
for i in range(k):
p[t[i]-1]=i+1
print(' '.join(map(str,p)))
``` | 3 | |
526 | B | Om Nom and Dark Park | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"implementation"
] | null | null | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so... | The first line contains integer *n* (1<=β€<=*n*<=β€<=10) β the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 β the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on th... | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | [
"2\n1 2 3 4 5 6\n"
] | [
"5\n"
] | Picture for the sample test. Green color denotes the additional street lights. | 500 | [
{
"input": "2\n1 2 3 4 5 6",
"output": "5"
},
{
"input": "2\n1 2 3 3 2 2",
"output": "0"
},
{
"input": "1\n39 52",
"output": "13"
},
{
"input": "2\n59 96 34 48 8 72",
"output": "139"
},
{
"input": "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89",
"output": "210"... | 1,684,464,712 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 77 | 3,481,600 | n=int(input())
a=[0,0]+list(map(int,input().split()))
# print(a)
ans=0
def dfs(i,d):
global ans
if d==n+1: return 0
# print(i,d)
left=dfs(2*i,d+1)
right=dfs(2*i+1,d+1)
ans+=abs(left-right)
return max(left,right)+a[i]
dfs(1,0)
print(ans) | Title: Om Nom and Dark Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless a... | ```python
n=int(input())
a=[0,0]+list(map(int,input().split()))
# print(a)
ans=0
def dfs(i,d):
global ans
if d==n+1: return 0
# print(i,d)
left=dfs(2*i,d+1)
right=dfs(2*i+1,d+1)
ans+=abs(left-right)
return max(left,right)+a[i]
dfs(1,0)
print(ans)
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,613,769,956 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 186 | 0 | '''
Jana Goodman6
6a construct triangle from 4 stick
'''
SPACE = ' '
TRI = 'TRIANGLE'
SEG = 'SEGMENT'
IMP = 'IMPOSSIBLE'
def case(a, b, c):
# good: long side < sum(2 shortest)
# SEGMENT: long side = sum(2 shortest)
if c < a + b:
return TRI
if c == a + b:
return SEG
... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
'''
Jana Goodman6
6a construct triangle from 4 stick
'''
SPACE = ' '
TRI = 'TRIANGLE'
SEG = 'SEGMENT'
IMP = 'IMPOSSIBLE'
def case(a, b, c):
# good: long side < sum(2 shortest)
# SEGMENT: long side = sum(2 shortest)
if c < a + b:
return TRI
if c == a + b:
r... | 3.9535 |
909 | B | Segments | PROGRAMMING | 1,300 | [
"constructive algorithms",
"math"
] | null | null | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoin... | The only input line contains a single integer *N* (1<=β€<=*N*<=β€<=100). | Output a single integer - the minimal number of layers required to draw the segments for the given *N*. | [
"2\n",
"3\n",
"4\n"
] | [
"2\n",
"4\n",
"6\n"
] | As an example, here are the segments and their optimal arrangement into layers for *N*β=β4. | 1,000 | [
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "4"
},
{
"input": "4",
"output": "6"
},
{
"input": "21",
"output": "121"
},
{
"input": "100",
"output": "2550"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
... | 1,514,452,611 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 5,529,600 | n = int(input())
print(round((n/2+1)*n/2))
| Title: Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in se... | ```python
n = int(input())
print(round((n/2+1)*n/2))
``` | 3 | |
369 | B | Valera and Contest | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valer... | The first line of the input contains exactly six integers *n*,<=*k*,<=*l*,<=*r*,<=*s**all*,<=*s**k* (1<=β€<=*n*,<=*k*,<=*l*,<=*r*<=β€<=1000; *l*<=β€<=*r*; *k*<=β€<=*n*; 1<=β€<=*s**k*<=β€<=*s**all*<=β€<=106).
It's guaranteed that the input is such that the answer exists. | Print exactly *n* integers *a*1,<=*a*2,<=...,<=*a**n* β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order. | [
"5 3 1 3 13 9\n",
"5 3 1 3 15 9\n"
] | [
"2 3 2 3 3 ",
"3 3 3 3 3 "
] | none | 1,000 | [
{
"input": "5 3 1 3 13 9",
"output": "2 3 2 3 3 "
},
{
"input": "5 3 1 3 15 9",
"output": "3 3 3 3 3 "
},
{
"input": "50 25 1 1 50 25",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1000 700 782... | 1,589,473,051 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 140 | 20,172,800 | n,k,l,r,sa,s=map(int,input().split())
rm=s%k
print((( (str(s//k)) +' ' )*(k-rm))+((str((s//k)+1)+' ')*rm),end='')
if sa !=s:
re=sa-s
z2=re%(n-k)
print(((str(re//(n-k))+' ')*(n-k-z2))+((str((re//(n-k))+1)+' ')*z2))
| Title: Valera and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual c... | ```python
n,k,l,r,sa,s=map(int,input().split())
rm=s%k
print((( (str(s//k)) +' ' )*(k-rm))+((str((s//k)+1)+' ')*rm),end='')
if sa !=s:
re=sa-s
z2=re%(n-k)
print(((str(re//(n-k))+' ')*(n-k-z2))+((str((re//(n-k))+1)+' ')*z2))
``` | 3 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=Γ<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,643,612,701 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | l=[[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
z=list(map(int,input().split()))
for j in range(3):
if z[j]%2==1:
if j+1<3:
l[i][j+1]=(l[i][j+1]+1)%2
if i+1<3:
l[i+1][j]=(l[i+1][j]+1)%2
if j-1>=0:
l[i][j-1]=(l[i][j-1]+1)%2
if i-1>=0:
l[i-1][j]=(l[i-1][j]+1)%2
l[i][j]=(l[i]... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=Γ<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
l=[[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
z=list(map(int,input().split()))
for j in range(3):
if z[j]%2==1:
if j+1<3:
l[i][j+1]=(l[i][j+1]+1)%2
if i+1<3:
l[i+1][j]=(l[i+1][j]+1)%2
if j-1>=0:
l[i][j-1]=(l[i][j-1]+1)%2
if i-1>=0:
l[i-1][j]=(l[i-1][j]+1)%2
l[i... | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W β the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β the numerator, and B β the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,593,680,498 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 280 | 0 | a, b = map(int, input().split(' '))
a = max(a, b)
if a == 1:
a = '1/1'
elif a == 2:
a = '5/6'
elif a == 3:
a = '2/3'
elif a == 4:
a = '1/2'
elif a == 5:
a = '1/3'
elif a == 6:
a = '1/6'
print(a)
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
a, b = map(int, input().split(' '))
a = max(a, b)
if a == 1:
a = '1/1'
elif a == 2:
a = '5/6'
elif a == 3:
a = '2/3'
elif a == 4:
a = '1/2'
elif a == 5:
a = '1/3'
elif a == 6:
a = '1/6'
print(a)
``` | 3.86 |
920 | B | Tea Queue | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th s... | The first line contains one integer *t* β the number of test cases to solve (1<=β€<=*t*<=β€<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=β€<=*n*<=β€<=1000) β the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=β€<=*l**i*<=β€<=... | For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea. | [
"2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n"
] | [
"1 2 \n1 0 2 \n"
] | The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and ... | 0 | [
{
"input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3",
"output": "1 2 \n1 0 2 "
},
{
"input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2... | 1,517,583,268 | 1,168 | Python 3 | OK | TESTS | 8 | 61 | 5,734,400 | t = int(input())
ans1 = []
for i in range(t):
n=int(input())
st=[]
for i in range(n):
l,r = map(int,input().split())
st.append((l,r,i))
st = sorted(st, key=lambda x: (x[0], x[2]))
ans = []
f = -1
for s in st:
if s[1] < f:
ans.append(0)
... | Title: Tea Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use ... | ```python
t = int(input())
ans1 = []
for i in range(t):
n=int(input())
st=[]
for i in range(n):
l,r = map(int,input().split())
st.append((l,r,i))
st = sorted(st, key=lambda x: (x[0], x[2]))
ans = []
f = -1
for s in st:
if s[1] < f:
ans.append(... | 3 | |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=β€<=*n*,<=*m*<=β€<=100) β the number of employees and the number of languages.
Then *n* lines follow β each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=β€<=*k**i*<=β€<=*m*) β the number of languages the *i*-th employee knows. Next... | Print a single integer β the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,672,814,063 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 186 | 3,379,200 | def main():
n, m = read_ints()
languages_per_employee = []
for _ in range(n):
k, *languages = read_ints()
languages_per_employee.append(set(languages))
if all(len(languages) == 0 for languages in languages_per_employee):
print(n)
return
dsu = DisjointSetU... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
def main():
n, m = read_ints()
languages_per_employee = []
for _ in range(n):
k, *languages = read_ints()
languages_per_employee.append(set(languages))
if all(len(languages) == 0 for languages in languages_per_employee):
print(n)
return
dsu = Di... | 3 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=β€<=*n*<=β€<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=25) β the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,639,293,096 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
eil = [sum(a[i::3]) for i in [0, 1, 2]]
if eil[0] == max(eil):
print("chest")
elif eil[1] == max(eil):
print("biceps")
else:
print("back") | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
a = list(map(int, input().split()))
eil = [sum(a[i::3]) for i in [0, 1, 2]]
if eil[0] == max(eil):
print("chest")
elif eil[1] == max(eil):
print("biceps")
else:
print("back")
``` | 3 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line β as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,561,744,728 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 280 | 0 | s = input()
letters = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
for i in range(len(s)):
if s[-i - 1].isalpha() and s[-i - 1] in letters:
print('YES')
exit()
if s[-i - 1].isalpha() and s[-i - 1] not in letters:
print('NO')
exit()
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s = input()
letters = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
for i in range(len(s)):
if s[-i - 1].isalpha() and s[-i - 1] in letters:
print('YES')
exit()
if s[-i - 1].isalpha() and s[-i - 1] not in letters:
print('NO')
exit()
``` | 3.93 |
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp... | The first line contains three integers *n*, *m*, *k* (1<=β€<=*n*,<=*m*,<=*k*<=β€<=50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=50) β... | Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to ... | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2... | 1,585,747,495 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 280 | 0 | from sys import stdin,stdout
ii1 = lambda: int(stdin.readline())
is1 = lambda: stdin.readline()
iia = lambda : map(int, stdin.readline().split())
isa = lambda: stdin.readline().split()
n, m, k = iia()
arr = sorted(iia(),reverse = True)
count = 0
for i in arr:
if m <= k:
print(count)
b... | Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his f... | ```python
from sys import stdin,stdout
ii1 = lambda: int(stdin.readline())
is1 = lambda: stdin.readline()
iia = lambda : map(int, stdin.readline().split())
isa = lambda: stdin.readline().split()
n, m, k = iia()
arr = sorted(iia(),reverse = True)
count = 0
for i in arr:
if m <= k:
print(count)
... | 3 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=600)Β β participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integerΒ β the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,584,684,029 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(len(l)):
if l[i]==0:
count += 1
for j in range(count):
l.remove(0)
print(len(set(l)))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(len(l)):
if l[i]==0:
count += 1
for j in range(count):
l.remove(0)
print(len(set(l)))
``` | 3 | |
979 | B | Treasure Hunt | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$)Β β the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the lengt... | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | [
"3\nKuroo\nShiro\nKatie\n",
"7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"1\nabcabc\ncbabac\nababca\n",
"15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n"
] | [
"Kuro\n",
"Shiro\n",
"Katie\n",
"Draw\n"
] | In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Th... | 1,000 | [
{
"input": "3\nKuroo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces",
"output": "Shiro"
},
{
"input": "1\nabcabc\ncbabac\nababca",
"output": "Katie"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE",
"output": "Draw"
},
{... | 1,666,098,147 | 1,047 | PyPy 3 | OK | TESTS | 184 | 93 | 4,505,600 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x = [0] * 3
for i in range(3):
s = list(input().rstrip())
cnt = [0] * 130
for j in s:
cnt[j] += 1
m = max(cnt)
c = min(m + n, len(s))
if m == len(s) and n == 1:
c = m - ... | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friend... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x = [0] * 3
for i in range(3):
s = list(input().rstrip())
cnt = [0] * 130
for j in s:
cnt[j] += 1
m = max(cnt)
c = min(m + n, len(s))
if m == len(s) and n == 1:
... | 3 | |
818 | E | Card Game Again | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"number theory",
"two pointers"
] | null | null | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck.
After re... | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=100<=000, 1<=β€<=*k*<=β€<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=109) β the numbers written on the cards. | Print the number of ways to choose *x* and *y* so the resulting deck is valid. | [
"3 4\n6 2 8\n",
"3 6\n9 1 14\n"
] | [
"4\n",
"1\n"
] | In the first example the possible values of *x* and *y* are:
1. *x*β=β0,β*y*β=β0; 1. *x*β=β1,β*y*β=β0; 1. *x*β=β2,β*y*β=β0; 1. *x*β=β0,β*y*β=β1. | 0 | [
{
"input": "3 4\n6 2 8",
"output": "4"
},
{
"input": "3 6\n9 1 14",
"output": "1"
},
{
"input": "5 1\n1 3 1 3 1",
"output": "15"
},
{
"input": "5 1\n5 5 5 5 5",
"output": "15"
},
{
"input": "5 1\n5 4 4 4 4",
"output": "15"
},
{
"input": "100 1\n1 1 1 1... | 1,630,601,457 | 3,657 | PyPy 3 | OK | TESTS | 135 | 373 | 31,744,000 | import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n == 1:
... | Title: Card Game Again
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Eac... | ```python
import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n ... | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* β the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,695,069,925 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 124 | 1,536,000 | n=int(input())
d={}
l=""
x=list(map(int, input().split(" ")))
for i in range(len(x)):
d[x[i]]=i+1
for i in range(1,n+1,1):
for j,k in d.items():
if j==i:
l+=str(k)+" "
print(l)
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n=int(input())
d={}
l=""
x=list(map(int, input().split(" ")))
for i in range(len(x)):
d[x[i]]=i+1
for i in range(1,n+1,1):
for j,k in d.items():
if j==i:
l+=str(k)+" "
print(l)
``` | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=β€<=*a*,<=*b*<=β€<=100) β the number of red and blue socks that Vasya's got. | Print two space-separated integers β the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,680,722,091 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | from math import floor
a,b = map(int,input().split())
f= min(a,b)
c= max(a,b)
c-=f
c= floor(c/2)
print(f,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
from math import floor
a,b = map(int,input().split())
f= min(a,b)
c= max(a,b)
c-=f
c= floor(c/2)
print(f,c)
``` | 3 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number β the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,645,889,819 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 124 | 0 | a=int(input())
d={}
for i in range(a):
a,b=map(str,input().split())
d.setdefault(b,[])
d[b].append(a)
c=0
for i,j in d.items():
j=set(j)
c+=len(j)
print(c)
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β she doesn't take a leaf if it matches the color and the specie... | ```python
a=int(input())
d={}
for i in range(a):
a,b=map(str,input().split())
d.setdefault(b,[])
d[b].append(a)
c=0
for i,j in d.items():
j=set(j)
c+=len(j)
print(c)
``` | 3.969 |
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,587,913,127 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 307,200 | n = int(input())
li = list(input().split())
le=[]
lo=[]
for i in li:
if(int(i)%2 == 0):
le.append(i)
else:
lo.append(i)
if(len(le) == 1):
for i in range(len(li)):
if(le[0] == li[i]):
print(i+1)
elif(len(lo) == 1):
for i in range(len(li)):
if(lo[... | 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())
li = list(input().split())
le=[]
lo=[]
for i in li:
if(int(i)%2 == 0):
le.append(i)
else:
lo.append(i)
if(len(le) == 1):
for i in range(len(li)):
if(le[0] == li[i]):
print(i+1)
elif(len(lo) == 1):
for i in range(len(li)):
... | 3.944928 |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=β€<=*n*<=β€<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4)β=ββ-β1β+β2β-β3β+β4β=β2
*f*(5)β=ββ-β1β+β2β-β3β+β4β-β5β=ββ-β3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,696,159,145 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 46 | 0 | n = int(input())
ans = (n+1)//2
if n % 2 == 1:
print(-ans)
else:
print(ans)
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n = int(input())
ans = (n+1)//2
if n % 2 == 1:
print(-ans)
else:
print(ans)
``` | 3 | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=β€<=*n*<=β€<=3000, 1<=β€<=*m*<=β€<=3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,595,941,624 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 7,372,800 | n, m = map(int, input().split())
words = {}
for _ in range(m):
a, b = map(str, input().split())
if len(a) < len(b) or len(a) == len(b):
words[b] = a
else:
words[a] = b
a = list(map(str, input().split()))
for i in range(n):
if a[i] in words:
a[i] = words[a[i]]
print(*a... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n, m = map(int, input().split())
words = {}
for _ in range(m):
a, b = map(str, input().split())
if len(a) < len(b) or len(a) == len(b):
words[b] = a
else:
words[a] = b
a = list(map(str, input().split()))
for i in range(n):
if a[i] in words:
a[i] = words[a[i]]... | 3 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=β€<=*n*<=β€<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer β the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,689,936,402 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 0 | n = int(input())
height = list(map(int, input().split()))
max = height[0]
min = height[0]
max_i = 0
min_i = 0
for i in range(n):
if height[i] > max: # κ°μ₯ μμ μλ μ΅λκ° κ΅¬νκΈ°
max = height[i]
max_i = i
if height[i] <= min: # κ°μ₯ λ€μ μλ μ΅λκ° κ΅¬νκΈ°
min = height[i]
min_i = i
... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n = int(input())
height = list(map(int, input().split()))
max = height[0]
min = height[0]
max_i = 0
min_i = 0
for i in range(n):
if height[i] > max: # κ°μ₯ μμ μλ μ΅λκ° κ΅¬νκΈ°
max = height[i]
max_i = i
if height[i] <= min: # κ°μ₯ λ€μ μλ μ΅λκ° κ΅¬νκΈ°
min = height[i]
m... | 3 | |
990 | A | Commentary Boxes | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil... | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes eq... | 0 | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "... | 1,535,703,058 | 2,147,483,647 | Python 3 | OK | TESTS | 109 | 124 | 0 | n, m, a, b = map(int, input().split())
aa = m - (n % m)
bb = n % m
print(min(aa*a, bb*b)) | Title: Commentary Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation shou... | ```python
n, m, a, b = map(int, input().split())
aa = m - (n % m)
bb = n % m
print(min(aa*a, bb*b))
``` | 3 | |
475 | A | Bayan Bus | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of *k* participants who should be picked up at the airport. When a... | The only line of input contains integer *k*, (0<=β€<=*k*<=β€<=34), denoting the number of participants. | Print the figure of a bus with *k* passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six ... | [
"9\n",
"20\n"
] | [
"+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n",
"+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|... | none | 500 | [
{
"input": "9",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "20",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.... | 1,414,050,618 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | from sys import stdin
def main():
n=int(stdin.readline().strip())
b=[['+','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','+'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','D','|',')'],['|','#','.','#','.','#'... | Title: Bayan Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The ... | ```python
from sys import stdin
def main():
n=int(stdin.readline().strip())
b=[['+','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','+'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','D','|',')'],['|','#','.','... | 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,633,402,160 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 61 | 6,963,200 | #https://codeforces.com/problemset/problem/58/A
s = input()
j = 0
if s[0] == "h":
j += 1
l_flag = True
for i in range(1, len(s)):
if s[i] == s[i-1] and l_flag:
continue
if s[i] == "hello"[j]:
if j == 4:
j += 1
break
j += 1
if j == 3: l_flag = False
else: l_flag = True
co... | 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
#https://codeforces.com/problemset/problem/58/A
s = input()
j = 0
if s[0] == "h":
j += 1
l_flag = True
for i in range(1, len(s)):
if s[i] == s[i-1] and l_flag:
continue
if s[i] == "hello"[j]:
if j == 4:
j += 1
break
j += 1
if j == 3: l_flag = False
else: l_flag = T... | 3.95653 |
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,624,332,947 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 62 | 0 |
a,b = [int(i) for i in input().split()]
pa =0
pb = 0
pd = 0
if a > b:
numdis = a-b-1
if numdis%2 !=0:
pd+=1
max_ = b + int(numdis/2)
pb = max_
pa = 6- max_ -pd
elif a == b:
pd = 6
else:
numdis = b-a-1
if numdis%2 !=0:
pd+=1
max_ = a + int(numdis/2)
pa = max_
pb = 6- max_ - pd
... | 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
a,b = [int(i) for i in input().split()]
pa =0
pb = 0
pd = 0
if a > b:
numdis = a-b-1
if numdis%2 !=0:
pd+=1
max_ = b + int(numdis/2)
pb = max_
pa = 6- max_ -pd
elif a == b:
pd = 6
else:
numdis = b-a-1
if numdis%2 !=0:
pd+=1
max_ = a + int(numdis/2)
pa = max_
pb = 6- ... | 3 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=β€<=*n*<=β€<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,677,242,305 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 92 | 0 | n = int(input())
sieve = [0 for i in range(n+1)]
for i in range(2,n+1):
if(sieve[i]==0):
x = 2*i
while(x<=n):
sieve[x]+=1
x+=i
c=0
for i in range(1,n+1):
if(sieve[i]==2):
c+=1
print(c) | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
n = int(input())
sieve = [0 for i in range(n+1)]
for i in range(2,n+1):
if(sieve[i]==0):
x = 2*i
while(x<=n):
sieve[x]+=1
x+=i
c=0
for i in range(1,n+1):
if(sieve[i]==2):
c+=1
print(c)
``` | 3.977 |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,695,355,058 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | n=int(input())
a=[]
for i in range(n):
if i%2==0:
a.append("I hate")
else:
a.append("I love")
if i!=n-1:
a.append("that")
a.append("it")
print(" ".join(a)) | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
n=int(input())
a=[]
for i in range(n):
if i%2==0:
a.append("I hate")
else:
a.append("I love")
if i!=n-1:
a.append("that")
a.append("it")
print(" ".join(a))
``` | 3 | |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=β€<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,578,466,177 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 1,980 | 49,971,200 | from collections import defaultdict
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
xCnt = defaultdict(int)
yCnt = defaultdict(int)
same = defaultdict(int)
for x, y in a:
xCnt[x] += 1
yCnt[y] += 1
same[(x, y)] += 1
ret = 0
for cnt in xCnt.values():
ret += cnt * ... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
from collections import defaultdict
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
xCnt = defaultdict(int)
yCnt = defaultdict(int)
same = defaultdict(int)
for x, y in a:
xCnt[x] += 1
yCnt[y] += 1
same[(x, y)] += 1
ret = 0
for cnt in xCnt.values():
ret... | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=β€<=*n*<=β€<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line β the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,621,610,265 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 0 | k=int(input())
a=["Sheldon","Leonard","Penny","Rajesh","Howard"]
r=1
while(r*5<k):
k-=r*5
r*=2
print(a[(k-1)//r])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
k=int(input())
a=["Sheldon","Leonard","Penny","Rajesh","Howard"]
r=1
while(r*5<k):
k-=r*5
r*=2
print(a[(k-1)//r])
``` | 3.969 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=β€<=*n*<=β€<=1000, 1<=β€<=*h*<=β€<=1000)Β β the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integerΒ β the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.
In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,697,544,972 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | tmp = input()
tmp = tmp.split()
n = int(tmp[0])
h = int(tmp[1])
friends = input()
friends = friends.split()
width = 0
for friend in friends:
if int(friend) > h:
width += 2
print(int(0.5 * width + len(friends))) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
tmp = input()
tmp = tmp.split()
n = int(tmp[0])
h = int(tmp[1])
friends = input()
friends = friends.split()
width = 0
for friend in friends:
if int(friend) > h:
width += 2
print(int(0.5 * width + len(friends)))
``` | 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,613,121,128 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | s = input()
p = 0
c = 0
for x in s:
if x.islower() == True: c += 1
else: p += 1
if p > c: print(s.upper())
if p < c or p == c: print(s.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
s = input()
p = 0
c = 0
for x in s:
if x.islower() == True: c += 1
else: p += 1
if p > c: print(s.upper())
if p < c or p == c: print(s.lower())
``` | 3.969 |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they donβt have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n*Β (1<=β€<=*n*<=β€<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,680,575,580 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 77 | 13,107,200 | I, IN, M, R, LN, LS, P, S, ST, A, SO, MX, MN = int, input, map, range, len, list, print, sum, str, abs, sorted, max, min; inp = lambda: LS(M(I, IN().split()))
n, a, s, m = I(IN()), inp(), 0, 0
for i in a: s += i; m = MN(m, s)
P(A(m)) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they donβt have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
I, IN, M, R, LN, LS, P, S, ST, A, SO, MX, MN = int, input, map, range, len, list, print, sum, str, abs, sorted, max, min; inp = lambda: LS(M(I, IN().split()))
n, a, s, m = I(IN()), inp(), 0, 0
for i in a: s += i; m = MN(m, s)
P(A(m))
``` | 3 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=β€<=*l*<=β€<=*r*<=β€<=1018; *r*<=-<=*l*<=β€<=50). | Print three positive space-separated integers *a*, *b*, *c*Β β three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2,β4) is not coprime and pairs (2,β3) and (3,β4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,687,466,425 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | minimum_number, maximum_number = map(int, input().split())
insuficient_number_in_interval = maximum_number - minimum_number + 1 < 3
is_minimum_number_odd = minimum_number % 2 == 1
if insuficient_number_in_interval or (is_minimum_number_odd and maximum_number - minimum_number + 1 < 4):
print('-1')
elif is_minimum... | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
minimum_number, maximum_number = map(int, input().split())
insuficient_number_in_interval = maximum_number - minimum_number + 1 < 3
is_minimum_number_odd = minimum_number % 2 == 1
if insuficient_number_in_interval or (is_minimum_number_odd and maximum_number - minimum_number + 1 < 4):
print('-1')
elif ... | 3 | |
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,642,108,986 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 124 | 409,600 | from re import match
print(match(r"^(14?4?)*$", input()) and 'YES' or 'NO') | 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
from re import match
print(match(r"^(14?4?)*$", input()) and 'YES' or 'NO')
``` | 3 | |
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ... | The first line contains two integers *n* and *k* (2<=β€<=*n*<=β€<=3Β·105,<=1<=β€<=*k*<=β€<=3Β·105). The next line contains *n* characters β the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters e... | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "Y... | 1,622,127,460 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 154 | 1,024,000 | n,k=map(int,input().split())
print('YNEOS'['#'*k in input()::2]) | Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to t... | ```python
n,k=map(int,input().split())
print('YNEOS'['#'*k in input()::2])
``` | 3 | |
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,583,400,380 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 155 | 0 | cards = list(map(int, input().split()))
cards.sort()
test=[]
for i in cards:
if cards.count(i)>1 and i not in test:
test.append(i)
compare=0
check=0
number=0
if test==[]:
print(sum(cards))
else:
for i in test:
compare= cards.count(i)*i
check=max(check, compare)
... | 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
cards = list(map(int, input().split()))
cards.sort()
test=[]
for i in cards:
if cards.count(i)>1 and i not in test:
test.append(i)
compare=0
check=0
number=0
if test==[]:
print(sum(cards))
else:
for i in test:
compare= cards.count(i)*i
check=max(check, compa... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.