contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,642,268,774 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = input()
c = 0
for i in range(len(n)) :
if n[i] == 'l' and n[i + 1] == 'l' :
c += 1
li= []
for i in n :
if i not in li :
li.append(i)
print(li)
l = []
for i in li :
if i == 'h' :
l.append(ord('h')-104)
if i == 'e' :
l.append(ord('e')-100)
if i == 'l' :
l.append(ord('l')... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
n = input()
c = 0
for i in range(len(n)) :
if n[i] == 'l' and n[i + 1] == 'l' :
c += 1
li= []
for i in n :
if i not in li :
li.append(i)
print(li)
l = []
for i in li :
if i == 'h' :
l.append(ord('h')-104)
if i == 'e' :
l.append(ord('e')-100)
if i == 'l' :
l.appen... | 0 |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,451,488,670 | 770 | Python 3 | OK | TESTS | 38 | 62 | 102,400 | inp = input().split()
if inp[-1] == 'week':
n = int(inp[0])
if n == 5 or n == 6:
print(53)
else:
print(52)
else:
n = int(inp[0])
if n <= 29:
print(12)
elif n == 30:
print(11)
else:
print(7)
| Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
inp = input().split()
if inp[-1] == 'week':
n = int(inp[0])
if n == 5 or n == 6:
print(53)
else:
print(52)
else:
n = int(inp[0])
if n <= 29:
print(12)
elif n == 30:
print(11)
else:
print(7)
``` | 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,678,883,369 | 2,147,483,647 | PyPy 3 | OK | TESTS | 144 | 124 | 7,782,400 | n = int(input())
s = list(input())
r, d =0, 0
while(True):
t=0
for i in range(n):
if s[i]=='D':
if d>0:
s[i]='0'
d-=1
t+=1
else:
r+=1
if s[i]=='R':
if r>0:
s[i]='0'
r-=1
t+=1
else:
d+=1
if t==0:
for i in range(n):
if s[i]!='0':
print(s[i... | 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
n = int(input())
s = list(input())
r, d =0, 0
while(True):
t=0
for i in range(n):
if s[i]=='D':
if d>0:
s[i]='0'
d-=1
t+=1
else:
r+=1
if s[i]=='R':
if r>0:
s[i]='0'
r-=1
t+=1
else:
d+=1
if t==0:
for i in range(n):
if s[i]!='0':
... | 3 | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,651,690,939 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | from math import pi
n = int(input())
circles = list(map(int, input().split(' ')))
circles.sort()
circles.reverse()
s = 0
for i in range(1, len(circles) + 1):
if i % 2 == 0:
s -= circles[i - 1] ** 2 * pi
else:
s += circles[i - 1] ** 2 * pi
print(s)
| Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
from math import pi
n = int(input())
circles = list(map(int, input().split(' ')))
circles.sort()
circles.reverse()
s = 0
for i in range(1, len(circles) + 1):
if i % 2 == 0:
s -= circles[i - 1] ** 2 * pi
else:
s += circles[i - 1] ** 2 * pi
print(s)
``` | 3 | |
891 | A | Pride | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"math",
"number theory"
] | null | null | You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
What is the mi... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array.
The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. | [
"5\n2 2 3 4 6\n",
"4\n2 4 6 8\n",
"3\n2 6 9\n"
] | [
"5\n",
"-1\n",
"4\n"
] | In the first sample you can turn all numbers to 1 using the following 5 moves:
- [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves. | 500 | [
{
"input": "5\n2 2 3 4 6",
"output": "5"
},
{
"input": "4\n2 4 6 8",
"output": "-1"
},
{
"input": "3\n2 6 9",
"output": "4"
},
{
"input": "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21",
"output": "15"
},
{
"input": "12\n10 10 14 14 14 14 14 14 14 14 21 21",
... | 1,633,789,055 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 30 | 108 | 23,347,200 | from math import gcd
n, a = int(input()), [int(x) for x in input().split()]
pre = a
if 1 in a:
print(n - 1)
else:
for j in range(2, n + 1):
u = []
for k in range(n - j + 1):
u.append(gcd(pre[k], a[k + j - 1]))
if 1 in u:
print(n + j - 2)
break
pre = u
else:
print(-1) | Title: Pride
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [great... | ```python
from math import gcd
n, a = int(input()), [int(x) for x in input().split()]
pre = a
if 1 in a:
print(n - 1)
else:
for j in range(2, n + 1):
u = []
for k in range(n - j + 1):
u.append(gcd(pre[k], a[k + j - 1]))
if 1 in u:
print(n + j - 2)
break
pre = u
else:
print(-1... | 0 | |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,509,831,055 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 62 | 0 | str = input()
counter = 0; mark = 0
for item in str:
if item == '0' and mark == 1:
counter += 1
elif item == '1' and mark == 0:
mark = 1
if counter >= 6 and len(str) > 7:
print("yes")
else:
print("no") | Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
str = input()
counter = 0; mark = 0
for item in str:
if item == '0' and mark == 1:
counter += 1
elif item == '1' and mark == 0:
mark = 1
if counter >= 6 and len(str) > 7:
print("yes")
else:
print("no")
``` | 0 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,672,082,713 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
import functools
weight = list(map(int, input().split(" ")))
weight.sort()
print(weight)
weight2 = weight.copy()
total = 0
diff = []
for i in range(n):
diff.append(weight[i * 2 + 1] - weight[i * 2])
print(functools.reduce(lambda a, b: a + b, diff) - max(diff))
"""
for i in ran... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
n = int(input())
import functools
weight = list(map(int, input().split(" ")))
weight.sort()
print(weight)
weight2 = weight.copy()
total = 0
diff = []
for i in range(n):
diff.append(weight[i * 2 + 1] - weight[i * 2])
print(functools.reduce(lambda a, b: a + b, diff) - max(diff))
"""
fo... | 0 | |
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are... | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15... | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n684... | 1,521,828,639 | 5,739 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 93 | 7,065,600 | import math
ho,mi = map(int,input().split())
h,d,c,n = map(int,input().split())
nr = int(h / n) + 1
nc = nr * c
des = False
if (ho >= 20 and ho <= 23) :
des = True
if(not des) :
dif = (60-mi)
dif += (19 - ho)*60
h += (dif*d)
rate = math.ceil(h/n) *.8
tc = rate * c
if ( tc < nc) :
print (tc)
... | Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without foo... | ```python
import math
ho,mi = map(int,input().split())
h,d,c,n = map(int,input().split())
nr = int(h / n) + 1
nc = nr * c
des = False
if (ho >= 20 and ho <= 23) :
des = True
if(not des) :
dif = (60-mi)
dif += (19 - ho)*60
h += (dif*d)
rate = math.ceil(h/n) *.8
tc = rate * c
if ( tc < nc) :
p... | 0 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,689,807,504 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 124 | 0 | W=int(input())
while not 1<=W<=100:
W=int(input())
if W%2==1 :
print("NO")
elif W==2 :
print("NO")
else :
print("YES") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
W=int(input())
while not 1<=W<=100:
W=int(input())
if W%2==1 :
print("NO")
elif W==2 :
print("NO")
else :
print("YES")
``` | 3.938 |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,680,896,415 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 93 | 716,800 | import sys
import math
import bisect
import heapq
import itertools
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict, Counter, deque
from bisect import bisect_left,bisect_right, insort_left, insort_right
mod=1000000007
def get_ints(): return map(int, sys.... | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
import sys
import math
import bisect
import heapq
import itertools
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict, Counter, deque
from bisect import bisect_left,bisect_right, insort_left, insort_right
mod=1000000007
def get_ints(): return map... | 3 | |
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,698,211,618 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 93 | 8,704,000 | def solve(x):
recruit = 0
untreated = 0
for i in range(len(x)):
if (int(x[i]) == -1) and recruit <=0:
untreated +=1
if(int(x[i]) == -1) and recruit>0:
recruit-=1
if (int(x[i])>0 and int(x[i])<=10):
recruit +=int(x[i])
# print("untreated:"... | 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
def solve(x):
recruit = 0
untreated = 0
for i in range(len(x)):
if (int(x[i]) == -1) and recruit <=0:
untreated +=1
if(int(x[i]) == -1) and recruit>0:
recruit-=1
if (int(x[i])>0 and int(x[i])<=10):
recruit +=int(x[i])
# print("u... | 3 | |
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,700,333,797 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 11 | 62 | 0 |
x, y = map(int, input().split(" "))
for i in range(y):
if x % 10 != 0:
x = x - 1
elif x % 10 == 0:
x = x / 10
print(int(x))
| 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
x, y = map(int, input().split(" "))
for i in range(y):
if x % 10 != 0:
x = x - 1
elif x % 10 == 0:
x = x / 10
print(int(x))
``` | 3 | |
175 | A | Robot Bicorn Attack | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided ... | The only line of input contains non-empty string *s* obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters. | Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1. | [
"1234\n",
"9000\n",
"0009\n"
] | [
"37\n",
"90\n",
"-1\n"
] | In the first example the string must be split into numbers 1, 2 and 34.
In the second example the string must be split into numbers 90, 0 and 0.
In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes. | 500 | [
{
"input": "1234",
"output": "37"
},
{
"input": "9000",
"output": "90"
},
{
"input": "0009",
"output": "-1"
},
{
"input": "100000010000001000000",
"output": "3000000"
},
{
"input": "1000000011",
"output": "1000011"
},
{
"input": "9991",
"output": "... | 1,449,601,132 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 77 | 0 | s = input().strip()
n = len(s)
big = 10 ** 6
result = -1
for i in range(1, n):
if s[0] == '0' and i > 1:
break
a = int(s[:i])
if a > big:
break
for j in range(i + 1, n):
if s[i] == '0' and j - i > 1:
break
b = int(s[i:j])
if b > big:
break... | Title: Robot Bicorn Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played thre... | ```python
s = input().strip()
n = len(s)
big = 10 ** 6
result = -1
for i in range(1, n):
if s[0] == '0' and i > 1:
break
a = int(s[:i])
if a > big:
break
for j in range(i + 1, n):
if s[i] == '0' and j - i > 1:
break
b = int(s[i:j])
if b > big:
... | 0 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,689,091,662 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | s=input()
m=s.replace("WUB"," ")
print(m) | 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()
m=s.replace("WUB"," ")
print(m)
``` | 3 | |
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,692,978,776 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | x = int(input())
total = 0
for i in range(x):
j = int(input())
total += j
print(total/x)
| 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
x = int(input())
total = 0
for i in range(x):
j = int(input())
total += j
print(total/x)
``` | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of *n* vertices and *m* edges. Vertices are numbered from 1 to *n*. Vertices 1 and *n* being the source and the sink respectively.
Howe... | The first line of input contains two space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, *n*<=-<=1<=≤<=*m*<=≤<=2·105), the number of vertices and edges in the graph. The following *m* lines contain three space-separated integers *a**i*, *b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*, 1<=≤<=*... | Output *m* lines, each containing one integer *d**i*, which should be 0 if the direction of the *i*-th edge is *a**i*<=→<=*b**i* (the flow goes from vertex *a**i* to vertex *b**i*) and should be 1 otherwise. The edges are numbered from 1 to *m* in the order they are given in the input.
If there are several solutions y... | [
"3 3\n3 2 10\n1 2 10\n3 1 5\n",
"4 5\n1 2 10\n1 3 10\n2 3 5\n4 2 15\n3 4 5\n"
] | [
"1\n0\n1\n",
"0\n0\n1\n1\n0\n"
] | In the first test case, 10 flow units pass through path <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/609340f155794c4e9eebcd9cdfa23c73cf982f28.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and 5 flow units pass directly from source to sink: <img align="middle" class="tex-formula" ... | 0 | [
{
"input": "3 3\n3 2 10\n1 2 10\n3 1 5",
"output": "1\n0\n1"
},
{
"input": "4 5\n1 2 10\n1 3 10\n2 3 5\n4 2 15\n3 4 5",
"output": "0\n0\n1\n1\n0"
},
{
"input": "10 17\n8 1 1\n4 8 2\n7 10 8\n1 4 1\n5 4 3\n6 9 6\n3 5 4\n1 9 1\n3 9 5\n7 1 1\n1 2 1\n1 3 1\n6 7 7\n8 2 1\n1 10 1\n1 5 1\n6 1 1"... | 1,636,670,434 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 67,174,400 |
from collections import deque
class Node:
def __init__(self, val):
self.val = val
self.fout = 0
self.fin = 0
self.vis = False
# debugging only
def __repr__(self):
return f"node {self.val}:" + ("" if self.vis else " not") + " visited\n"
class Ed... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of *n* vertices and *m* edges. Vertices are nu... | ```python
from collections import deque
class Node:
def __init__(self, val):
self.val = val
self.fout = 0
self.fin = 0
self.vis = False
# debugging only
def __repr__(self):
return f"node {self.val}:" + ("" if self.vis else " not") + " visited\n"
... | 0 | |
612 | B | HDD is Outdated Technology | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read s... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments.
The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector. | Print the only integer — the number of time units needed to read the file. | [
"3\n3 1 2\n",
"5\n1 3 5 4 2\n"
] | [
"3\n",
"10\n"
] | In the second example the head moves in the following way:
- 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time un... | 0 | [
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "5\n1 3 5 4 2",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "40"
... | 1,585,312,147 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 17 | 1,000 | 10,547,200 | n=int(input());a=list(map(int,input().split()));p=0
for i in range(n-1):p=p+abs(a.index(i+1)-a.index(i+2))
print(p) | Title: HDD is Outdated Technology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the ... | ```python
n=int(input());a=list(map(int,input().split()));p=0
for i in range(n-1):p=p+abs(a.index(i+1)-a.index(i+2))
print(p)
``` | 0 | |
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ... | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and... | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 ... | 1,662,570,931 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 18,329,600 | from collections import deque,Counter
from math import *
import sys
import random
from bisect import *
from functools import reduce
from sys import stdin
import copy
input = lambda: sys.stdin.readline().rstrip()
def count(i,j,grid):
dirs = [[1,0],[-1,0],[0,1],[0,-1]]
ans = 0
for x,y in dirs:
dx,dy ... | Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to pl... | ```python
from collections import deque,Counter
from math import *
import sys
import random
from bisect import *
from functools import reduce
from sys import stdin
import copy
input = lambda: sys.stdin.readline().rstrip()
def count(i,j,grid):
dirs = [[1,0],[-1,0],[0,1],[0,-1]]
ans = 0
for x,y in dirs:
... | 0 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,596,148,810 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 310 | 20,172,800 | a = input()
b = input()
c = input()
ans = dict()
weights = [a, b, c]
w1 = w2 = w3 = 0
for i in weights:
if 'A>' in i or '<A' in i:
w1 += 1
if 'B>' in i or '<B' in i:
w2 += 1
if 'C>' in i or '<C' in i:
w3 += 1
total = [w1, w2, w3]
if 2 not in total or 1 n... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
a = input()
b = input()
c = input()
ans = dict()
weights = [a, b, c]
w1 = w2 = w3 = 0
for i in weights:
if 'A>' in i or '<A' in i:
w1 += 1
if 'B>' in i or '<B' in i:
w2 += 1
if 'C>' in i or '<C' in i:
w3 += 1
total = [w1, w2, w3]
if 2 not in to... | 3.884925 |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,584,589,160 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin>>a>>b;
(a==b)?cout<<a:cout<<1;
} | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin>>a>>b;
(a==b)?cout<<a:cout<<1;
}
``` | -1 | |
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,699,700,321 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | n = int(input())
str = ""
i = 1
while i < n:
if i % 2 != 0:
print("I hate",end=" ")
if i % 2 == 0:
print("I love",end=" ")
print("that",end=" ")
i += 1
if n % 2 == 0:
print("I love it")
else:
print("I hate it")
| 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())
str = ""
i = 1
while i < n:
if i % 2 != 0:
print("I hate",end=" ")
if i % 2 == 0:
print("I love",end=" ")
print("that",end=" ")
i += 1
if n % 2 == 0:
print("I love it")
else:
print("I hate it")
``` | 3 | |
70 | A | Cookies | PROGRAMMING | 1,300 | [
"math"
] | A. Cookies | 1 | 256 | Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). | Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. | [
"3\n"
] | [
"9"
] | If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner: | 500 | [
{
"input": "3",
"output": "9"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "27"
},
{
"input": "6",
"output": "243"
},
{
"input": "11",
"output": "59049"
},
{
"input": "14",
"output": "59... | 1,657,782,987 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | from math import ceil
x = int(input())
print(ceil(3**(n-1))%1000003)
| Title: Cookies
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which li... | ```python
from math import ceil
x = int(input())
print(ceil(3**(n-1))%1000003)
``` | -1 |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,698,558,288 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 154 | 0 | year = int(input())
ans = str(year + 1)
while len(set(ans)) != 4:
ans = int(ans)
ans += 1
ans = str(ans)
print(ans) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
year = int(input())
ans = str(year + 1)
while len(set(ans)) != 4:
ans = int(ans)
ans += 1
ans = str(ans)
print(ans)
``` | 3 | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,616,429,889 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,m=map(int,raw_input().split())
r=n*[0]
c=m*[0]
for i in range(n):
s=raw_input()
for j in range(m):
if s[j]=='*':
r[i]+=1
c[j]+=1
print r.index(1)+1,c.index(1)+1 | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
n,m=map(int,raw_input().split())
r=n*[0]
c=m*[0]
for i in range(n):
s=raw_input()
for j in range(m):
if s[j]=='*':
r[i]+=1
c[j]+=1
print r.index(1)+1,c.index(1)+1
``` | -1 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,671,701,840 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | s=input()
t=input()
xdiff=ord(s[0])-ord(t[0])
ydiff=int(s[1])-int(t[1])
xchar="L"
ychar="D"
if xdiff<0:
xchar="R"
if ydiff<0:
ychar="U"
xdiff=abs(xdiff)
ydiff=abs(ydiff)
count=max(xdiff,ydiff)+(abs(xdiff-ydiff))
print(count)
for i in range(min(xdiff, ydiff)):
print(xchar+ychar)
if xdif... | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
s=input()
t=input()
xdiff=ord(s[0])-ord(t[0])
ydiff=int(s[1])-int(t[1])
xchar="L"
ychar="D"
if xdiff<0:
xchar="R"
if ydiff<0:
ychar="U"
xdiff=abs(xdiff)
ydiff=abs(ydiff)
count=max(xdiff,ydiff)+(abs(xdiff-ydiff))
print(count)
for i in range(min(xdiff, ydiff)):
print(xchar+ychar)
... | 0 |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,559,475,212 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 |
str1=input()
l1=list(str1)
for i in range(len(l1)-2):
if(l1[i]==l1[i+1]==l1[i+2]):
l1[i+1]=chr(ord(l1[i+1])+1)
else:
if(l1[i]==l1[i+1] and l1[i+1]!=l1[i+2]):
x=chr(ord(l1[i+2])+1)
print(x)
if(l1[i+1]!=x):
l1[i+1]=x
else:
l1[i+1]=chr(ord(l1[i+2])+2)
str2=""
for i in l1:
st... | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wa... | ```python
str1=input()
l1=list(str1)
for i in range(len(l1)-2):
if(l1[i]==l1[i+1]==l1[i+2]):
l1[i+1]=chr(ord(l1[i+1])+1)
else:
if(l1[i]==l1[i+1] and l1[i+1]!=l1[i+2]):
x=chr(ord(l1[i+2])+1)
print(x)
if(l1[i+1]!=x):
l1[i+1]=x
else:
l1[i+1]=chr(ord(l1[i+2])+2)
str2=""
for i i... | 0 | |
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. | Print one integer — the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing... | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\... | 1,580,809,629 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 187 | 0 | n, m = map(int, input().split())
l = list(map(int, input().split()))
w = []
for i in range(n):
w.append(l.count(i + 1))
w.sort()
print(w[0]) | Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo... | ```python
n, m = map(int, input().split())
l = list(map(int, input().split()))
w = []
for i in range(n):
w.append(l.count(i + 1))
w.sort()
print(w[0])
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Память компьютера состоит из *n* ячеек, которые выстроены в ряд. Пронумеруем ячейки от 1 до *n* слева направо. Про каждую ячейку известно, свободна она или принадлежит какому-либо процессу (в таком случае известен процесс, которому она принадлежит).
Для каждого процесса известно, что принадлежащие ему ячейки занимают ... | В первой строке входных данных записано число *n* (1<=≤<=*n*<=≤<=200<=000) — количество ячеек в памяти компьютера.
Во второй строке входных данных следуют *n* целых чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), где *a**i* равно либо 0 (это означает, что *i*-я ячейка памяти свободна), либо номеру процесса, к... | Выведите одно целое число — минимальное количество операций, которое нужно сделать для дефрагментации памяти. | [
"4\n0 2 2 1\n",
"8\n0 8 8 8 0 4 4 2\n"
] | [
"2\n",
"4\n"
] | В первом тестовом примере достаточно двух операций:
1. Переписать данные из третьей ячейки в первую. После этого память компьютера примет вид: 2 2 0 1. 1. Переписать данные из четвертой ячейки в третью. После этого память компьютера примет вид: 2 2 1 0. | 0 | [
{
"input": "4\n0 2 2 1",
"output": "2"
},
{
"input": "8\n0 8 8 8 0 4 4 2",
"output": "4"
},
{
"input": "5\n0 0 0 1 1",
"output": "2"
},
{
"input": "6\n0 0 0 3 0 0",
"output": "1"
},
{
"input": "10\n0 10 10 0 0 3 3 0 0 0",
"output": "3"
},
{
"input": "1... | 1,458,982,439 | 6,839 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 7 | 2,000 | 13,209,600 | n = int(input())
a = list(map(int,input().split()))
x = 0
k = 0
z = 0
while z != n:
if a[k] != 0:
k += 1
if k == n:
break
else:
z = k
while a[z] == 0:
z += 1
if z == n:
break
if z != n:
b = a... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Память компьютера состоит из *n* ячеек, которые выстроены в ряд. Пронумеруем ячейки от 1 до *n* слева направо. Про каждую ячейку известно, свободна она или принадлежит какому-либо процессу (в таком случае известен процесс, котором... | ```python
n = int(input())
a = list(map(int,input().split()))
x = 0
k = 0
z = 0
while z != n:
if a[k] != 0:
k += 1
if k == n:
break
else:
z = k
while a[z] == 0:
z += 1
if z == n:
break
if z != n:
... | 0 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,651,078,247 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 154 | 0 | flag = True
s = input()
while flag == True:
if '--' in s:
s = s.replace('--', '2')
elif '-.' in s:
s = s.replace('-.', '1')
elif '.' in s:
s = s.replace('.', '0')
else:
flag = False
print(s) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
flag = True
s = input()
while flag == True:
if '--' in s:
s = s.replace('--', '2')
elif '-.' in s:
s = s.replace('-.', '1')
elif '.' in s:
s = s.replace('.', '0')
else:
flag = False
print(s)
``` | 3.9615 |
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,684,321,083 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | a = int(input())
a += 1
k = 1
while "8" not in str(a):
k += 1
a += 1
print(k)
| 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
a = int(input())
a += 1
k = 1
while "8" not in str(a):
k += 1
a += 1
print(k)
``` | 3 | |
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S... | The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and... | Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second... | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1... | 1,693,701,762 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
alist=(input().split())
a=[int(x) for x in alist]
for i in range(1,7):
a[i]+=a[i-1]
print(a)
m=n%a[6]
if m==0:
print(7)
else:
for i in range(7):
if m <= a[i]:
print(i + 1)
break
| Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s... | ```python
n=int(input())
alist=(input().split())
a=[int(x) for x in alist]
for i in range(1,7):
a[i]+=a[i-1]
print(a)
m=n%a[6]
if m==0:
print(7)
else:
for i in range(7):
if m <= a[i]:
print(i + 1)
break
``` | 0 | |
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109... | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated ... | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\... | 1,662,215,405 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 92 | 4,403,200 | n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
i=1
L=[]
c=a[0]
ind=0
while m>0 and ind<n-1:
if i<c:
if m>=i:
L.append(i)
m-=i
i+=1
else:
break
elif i>=c:... | Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania h... | ```python
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
i=1
L=[]
c=a[0]
ind=0
while m>0 and ind<n-1:
if i<c:
if m>=i:
L.append(i)
m-=i
i+=1
else:
break
... | 0 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,697,482,619 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | b = int(input())
if b % 2 == 0: print(1)
else: print(2) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
b = int(input())
if b % 2 == 0: print(1)
else: print(2)
``` | 0 | |
998 | A | Balloons | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons insi... | The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons.
The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet. | If it's impossible to divide the balloons satisfying the conditions above, print $-1$.
Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons... | [
"3\n1 2 1\n",
"2\n5 5\n",
"1\n10\n"
] | [
"2\n1 2\n",
"-1\n",
"-1\n"
] | In the first test Grigory gets $3$ balloons in total while Andrey gets $1$.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | 500 | [
{
"input": "3\n1 2 1",
"output": "1\n1"
},
{
"input": "2\n5 5",
"output": "-1"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1\n1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 9",... | 1,530,688,131 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n = int(input())
ar = input().split()
mi = ar.index(min(ar))
print("-1" if (n == 2 and ar[0] == ar[1]) or n<2 else "1 " + str(mi)) | Title: Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bou... | ```python
n = int(input())
ar = input().split()
mi = ar.index(min(ar))
print("-1" if (n == 2 and ar[0] == ar[1]) or n<2 else "1 " + str(mi))
``` | 0 | |
255 | C | Almost Arithmetical Progression | PROGRAMMING | 1,500 | [
"brute force",
"dp"
] | null | null | Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
- *a*1<==<=*p*, where *p* is some integer; - *a**i*<==<=*a**i*<=-<=1<=+<=(<=-<=1)*i*<=+<=1·... | The first line contains integer *n* (1<=≤<=*n*<=≤<=4000). The next line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=106). | Print a single integer — the length of the required longest subsequence. | [
"2\n3 5\n",
"4\n10 20 10 30\n"
] | [
"2\n",
"3\n"
] | In the first test the sequence actually is the suitable subsequence.
In the second test the following subsequence fits: 10, 20, 10. | 1,500 | [
{
"input": "2\n3 5",
"output": "2"
},
{
"input": "4\n10 20 10 30",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "2"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "3"
},
{
"input": "2\n468 335",
... | 1,672,291,577 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 14 | 93 | 1,843,200 | from collections import Counter
def ss(a,x1,x2):
count = 0
term = 0
for i in a:
if count==0:
if i==x1:
count+=1
term = 2
elif i==x2:
count+=1
term = 1
if term==1:
if i==x1:
... | Title: Almost Arithmetical Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements ... | ```python
from collections import Counter
def ss(a,x1,x2):
count = 0
term = 0
for i in a:
if count==0:
if i==x1:
count+=1
term = 2
elif i==x2:
count+=1
term = 1
if term==1:
i... | 0 | |
90 | A | Cableway | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | A. Cableway | 2 | 256 | A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them ... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=100). It is guaranteed that *r*<=+<=*g*<=+<=*b*<=><=0, it means that the group consists of at least one student. | Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain. | [
"1 3 2\n",
"3 2 1\n"
] | [
"34",
"33"
] | Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the *r* group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the *g* group get on it; they get to the top at the moment of time 31.
At t... | 500 | [
{
"input": "1 3 2",
"output": "34"
},
{
"input": "3 2 1",
"output": "33"
},
{
"input": "3 5 2",
"output": "37"
},
{
"input": "10 10 10",
"output": "44"
},
{
"input": "29 7 24",
"output": "72"
},
{
"input": "28 94 13",
"output": "169"
},
{
"... | 1,598,986,683 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 218 | 0 | from math import ceil
a,b,c = map(int,input().split())
x,y,z = ceil(a/2),ceil(b/2),ceil(c/2)
maxi = max(x,y,z)
if maxi == z:
print(32+3*ceil((c-2)/2))
elif maxi == y:
print(31+3*ceil((b-2)/2))
elif maxi == x:
print(30+3*ceil((a-2)/2))
| Title: Cableway
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cabl... | ```python
from math import ceil
a,b,c = map(int,input().split())
x,y,z = ceil(a/2),ceil(b/2),ceil(c/2)
maxi = max(x,y,z)
if maxi == z:
print(32+3*ceil((c-2)/2))
elif maxi == y:
print(31+3*ceil((b-2)/2))
elif maxi == x:
print(30+3*ceil((a-2)/2))
``` | 3.9455 |
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times... | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {... | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",... | 1,614,505,971 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | l, r = map(int, input().split())
m = []
dict = {}
for i in range(l, r + 1):
for k in range(2, i + 1):
if i % k == 0:
m.append(k)
for i in set(m):
dict[i] = m.count(i)
print(dict.get(max(dict.values())))
| Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the... | ```python
l, r = map(int, input().split())
m = []
dict = {}
for i in range(l, r + 1):
for k in range(2, i + 1):
if i % k == 0:
m.append(k)
for i in set(m):
dict[i] = m.count(i)
print(dict.get(max(dict.values())))
``` | 0 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,602,962,385 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | def two_bags():
info = list(map(int,input().split()))
k = info[1]
posible = []
while k < info[2]:
if k>info[0]:
posible.append(k-info[0])
k += info[1]
if len(posible)== 0:
print(-1)
else:
for valor in posible:
p... | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
def two_bags():
info = list(map(int,input().split()))
k = info[1]
posible = []
while k < info[2]:
if k>info[0]:
posible.append(k-info[0])
k += info[1]
if len(posible)== 0:
print(-1)
else:
for valor in posible:
... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,688,391,178 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | string = input()
lst = []
for letter in string:
if letter not in lst:
lst.append(letter)
if len(lst)<(len(string)-1):
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
string = input()
lst = []
for letter in string:
if letter not in lst:
lst.append(letter)
if len(lst)<(len(string)-1):
print("YES")
else:
print("NO")
``` | 0 |
257 | B | Playing Cubes | PROGRAMMING | 1,300 | [
"games",
"greedy",
"implementation"
] | null | null | Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have *n*<=+<=*m* cubes). Petya moves first. Petya's task is to get as many pa... | The only line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of red and blue cubes, correspondingly. | On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well. | [
"3 1\n",
"2 4\n"
] | [
"2 1\n",
"3 2\n"
] | In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point.
If Petya would choose the red cu... | 500 | [
{
"input": "3 1",
"output": "2 1"
},
{
"input": "2 4",
"output": "3 2"
},
{
"input": "1 1",
"output": "0 1"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "4 4",
"output": "3 4"
},
{
"input": "10 7",
"output": "9 7"
},
{
"input": "5 13"... | 1,662,147,850 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 404 | 135,270,400 | from collections import defaultdict, deque
from functools import lru_cache
from heapq import heappush, heappop
from typing import Counter
import math
hpop = heappop
hpush = heappush
"""
num = int(input())
arr = list(map(int, input().split()))
a,b = map(int, input().split())
graph = defaultdict(list)
... | Title: Playing Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (... | ```python
from collections import defaultdict, deque
from functools import lru_cache
from heapq import heappush, heappop
from typing import Counter
import math
hpop = heappop
hpush = heappush
"""
num = int(input())
arr = list(map(int, input().split()))
a,b = map(int, input().split())
graph = defaultdict... | 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,667,394,822 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 61 | 1,638,400 | nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
count = 0
y = list(map(int, input().split()))
for i in y:
if k + i <= 5:
count += 1
print(count // 3)
| 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
nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
count = 0
y = list(map(int, input().split()))
for i in y:
if k + i <= 5:
count += 1
print(count // 3)
``` | 3 | |
597 | C | Subsequences | PROGRAMMING | 1,900 | [
"data structures",
"dp"
] | null | null | For the given sequence with *n* different elements find the number of increasing subsequences with *k*<=+<=1 elements. It is guaranteed that the answer is not greater than 8·1018. | First line contain two integer values *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=10) — the length of sequence and the number of elements in increasing subsequences.
Next *n* lines contains one integer *a**i* (1<=≤<=*a**i*<=≤<=*n*) each — elements of sequence. All values *a**i* are different. | Print one integer — the answer to the problem. | [
"5 2\n1\n2\n3\n5\n4\n"
] | [
"7\n"
] | none | 1,500 | [
{
"input": "5 2\n1\n2\n3\n5\n4",
"output": "7"
},
{
"input": "1 0\n1",
"output": "1"
},
{
"input": "2 1\n1\n2",
"output": "1"
},
{
"input": "2 1\n2\n1",
"output": "0"
},
{
"input": "3 2\n1\n2\n3",
"output": "1"
},
{
"input": "3 1\n1\n3\n2",
"output... | 1,449,617,736 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 17 | 1,000 | 2,150,400 | def solve (a, p, n, k):
for i in range(n - 1):
for j in range(i + 1, n):
if a[i] < a[j]:
for m in range(k):
p[j][m + 1] += p[i][m]
cnt = 0
for i in range(n):
cnt += p[i][k]
return cnt
n, k = map(int, input().... | Title: Subsequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For the given sequence with *n* different elements find the number of increasing subsequences with *k*<=+<=1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input Specification:
First line contain t... | ```python
def solve (a, p, n, k):
for i in range(n - 1):
for j in range(i + 1, n):
if a[i] < a[j]:
for m in range(k):
p[j][m + 1] += p[i][m]
cnt = 0
for i in range(n):
cnt += p[i][k]
return cnt
n, k = map(int... | 0 | |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,698,708,407 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n = int(input())
l1 = [0,0]
l2 = [0,0]
for _ in range(n):
a,s,f = map(int,input().split())
if a == 1:
l1[0] += s
l1[1] += f
elif a == 2:
l2[0] += s
l2[1] += f
if l1[0]/l1[1] >= 0.5:
print("LIVE")
else:
print("DEAD")
if l2[0]/l2[1] >= 0.5... | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
n = int(input())
l1 = [0,0]
l2 = [0,0]
for _ in range(n):
a,s,f = map(int,input().split())
if a == 1:
l1[0] += s
l1[1] += f
elif a == 2:
l2[0] += s
l2[1] += f
if l1[0]/l1[1] >= 0.5:
print("LIVE")
else:
print("DEAD")
if l2[0]/l2... | 0 | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,657,454,520 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 77 | 0 | input()
ss = input()
s = [int(i) for i in ss]
c = []
ans = ''
fact = 1
from math import factorial
for i in s:
fact *= factorial(i)
first = [7 , 5 , 3 , 2]
for i in first:
while fact%factorial(i) == 0:
c.append(i)
fact //= factorial(i)
c.sort(reverse=True)
for i in c:
ans += st... | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that cont... | ```python
input()
ss = input()
s = [int(i) for i in ss]
c = []
ans = ''
fact = 1
from math import factorial
for i in s:
fact *= factorial(i)
first = [7 , 5 , 3 , 2]
for i in first:
while fact%factorial(i) == 0:
c.append(i)
fact //= factorial(i)
c.sort(reverse=True)
for i in c:
... | 3 | |
893 | B | Beautiful Divisors | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes.
Some examples of beautiful numbers:
- 12 (110); - 1102 (610); - 11110002 (12010); - 1111100... | The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got. | Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. | [
"3\n",
"992\n"
] | [
"1\n",
"496\n"
] | none | 0 | [
{
"input": "3",
"output": "1"
},
{
"input": "992",
"output": "496"
},
{
"input": "81142",
"output": "1"
},
{
"input": "76920",
"output": "120"
},
{
"input": "2016",
"output": "2016"
},
{
"input": "1",
"output": "1"
},
{
"input": "6",
"o... | 1,667,585,322 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 46 | 0 | n=int(input())
for i in range(1,n):
if (2**i-1)*(2**(i-1))<=n:
if n%(2**i-1)*(2**(i-1))==0:
m=(2**i-1)*(2**(i-1))
else:
break
print(m)
| Title: Beautiful Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive ze... | ```python
n=int(input())
for i in range(1,n):
if (2**i-1)*(2**(i-1))<=n:
if n%(2**i-1)*(2**(i-1))==0:
m=(2**i-1)*(2**(i-1))
else:
break
print(m)
``` | -1 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,584,547,777 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 280 | 0 | n=int(input())
l=list(map(int,input().split()))
x,y=0,0
m=10**10
for i in range(n-1):
s=abs(l[i+1]-l[i])
if(s<m):
m=s
x=i+2
y=i+1
w=abs(l[n-1]-l[0])
if(w<m):
print(1,n)
else:
print(x,y)
| Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
n=int(input())
l=list(map(int,input().split()))
x,y=0,0
m=10**10
for i in range(n-1):
s=abs(l[i+1]-l[i])
if(s<m):
m=s
x=i+2
y=i+1
w=abs(l[n-1]-l[0])
if(w<m):
print(1,n)
else:
print(x,y)
``` | 3.93 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,612,599,506 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 124 | 0 | n = int(input().strip(" "))
forces = []
count = [0 for i in range(3)]
for i in range(n):
f = list(map(int,input().strip(" ").split(" ")))
count = [f[i] + count[i] for i in range(3)]
if count == [0,0,0]:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input().strip(" "))
forces = []
count = [0 for i in range(3)]
for i in range(n):
f = list(map(int,input().strip(" ").split(" ")))
count = [f[i] + count[i] for i in range(3)]
if count == [0,0,0]:
print("YES")
else:
print("NO")
``` | 3.969 |
932 | B | Recursive Queries | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"dfs and similar"
] | null | null | Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. | The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9). | For each query, print a single line containing the answer for that query. | [
"4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n",
"4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n"
] | [
"1\n4\n0\n8\n",
"3\n1\n1\n5\n"
] | In the first example:
- *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4 | 1,000 | [
{
"input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4",
"output": "1\n4\n0\n8"
},
{
"input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4",
"output": "3\n1\n1\n5"
}
] | 1,518,708,019 | 2,719 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 2,000 | 5,632,000 | a=int(input())
ans=[]
def f(x):
t=1
for i in range(len(x)):
if int(x[i])!=0:
t*=int(x[i])
return t
def g(x):
if int(x)<=9:
return int(x)
else:
return g(str(f(x)))
for i in range(a):
posl=input().split()
otvet=0
for i in range(int(posl[... | Title: Recursive Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x*... | ```python
a=int(input())
ans=[]
def f(x):
t=1
for i in range(len(x)):
if int(x[i])!=0:
t*=int(x[i])
return t
def g(x):
if int(x)<=9:
return int(x)
else:
return g(str(f(x)))
for i in range(a):
posl=input().split()
otvet=0
for i in range... | 0 | |
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,540,822,974 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 |
a = list(input())
a.pop(0)
a.pop(0)
b = list(input())
b.pop(0)
b.pop(0)
c = list(input())
c.pop(0)
c.pop(0)
d = list(input())
d.pop(0)
d.pop(0)
list1 = [b,c,d]
list2 = [a,c,d]
list3 = [a,b,c]
list4 = [a,b,d]
temp = 1
count = 0
for i in range(len(list1)):
if len(a) >= len(list1[i])*2 or len(a)<=len(list1[i... | 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
a = list(input())
a.pop(0)
a.pop(0)
b = list(input())
b.pop(0)
b.pop(0)
c = list(input())
c.pop(0)
c.pop(0)
d = list(input())
d.pop(0)
d.pop(0)
list1 = [b,c,d]
list2 = [a,c,d]
list3 = [a,b,c]
list4 = [a,b,d]
temp = 1
count = 0
for i in range(len(list1)):
if len(a) >= len(list1[i])*2 or len(a)<=l... | 0 | |
230 | A | Dragons | PROGRAMMING | 1,000 | [
"greedy",
"sortings"
] | null | null | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit... | The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | [
"2 2\n1 99\n100 0\n",
"10 1\n100 100\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | 500 | [
{
"input": "2 2\n1 99\n100 0",
"output": "YES"
},
{
"input": "10 1\n100 100",
"output": "NO"
},
{
"input": "123 2\n78 10\n130 0",
"output": "YES"
},
{
"input": "999 2\n1010 10\n67 89",
"output": "YES"
},
{
"input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1",
"output": "YE... | 1,697,523,311 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | s,n=map(int,input().split())
f=0
for i in range(n):
x,y=map(int,input().split())
if s>=x:
s+=y
else:
print("NO")
break
f=1
if f==0:
print("YES") | Title: Dragons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the du... | ```python
s,n=map(int,input().split())
f=0
for i in range(n):
x,y=map(int,input().split())
if s>=x:
s+=y
else:
print("NO")
break
f=1
if f==0:
print("YES")
``` | 0 | |
39 | B | Company Income Growth | PROGRAMMING | 1,300 | [
"greedy"
] | B. Company Income Growth | 2 | 64 | Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces. | Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0. | [
"10\n-2 1 1 3 2 3 4 -10 -2 5\n",
"3\n-1 -2 -3\n"
] | [
"5\n2002 2005 2006 2007 2010\n",
"0\n"
] | none | 0 | [
{
"input": "10\n-2 1 1 3 2 3 4 -10 -2 5",
"output": "5\n2002 2005 2006 2007 2010 "
},
{
"input": "3\n-1 -2 -3",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1\n2002 "
},
{
"in... | 1,522,705,144 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 218 | 7,065,600 | n = int(input())
l = list(map(int, input().split()))
k = 1
r = []
for i in range(n):
if l[i] == k:
k += 1
r.append(i + 2001)
print(len(r))
for item in r:
print(item, end = ' ')
| Title: Company Income Growth
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company... | ```python
n = int(input())
l = list(map(int, input().split()))
k = 1
r = []
for i in range(n):
if l[i] == k:
k += 1
r.append(i + 2001)
print(len(r))
for item in r:
print(item, end = ' ')
``` | 3.892857 |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,695,563,049 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 102,400 | n = int(input()) # Input: The number of games played
s = input() # Input: The outcome of each game (string)
# Count the occurrences of 'A' (Anton's wins) and 'D' (Danik's wins)
anton_wins = s.count('A')
danik_wins = s.count('D')
# Compare the counts to determine the winner
if anton_wins > danik_wins:
... | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
n = int(input()) # Input: The number of games played
s = input() # Input: The outcome of each game (string)
# Count the occurrences of 'A' (Anton's wins) and 'D' (Danik's wins)
anton_wins = s.count('A')
danik_wins = s.count('D')
# Compare the counts to determine the winner
if anton_wins > dan... | 3 | |
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a w... | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "... | 1,680,711,450 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | first_player_count, second_player_count = list((map(int, input().split())))
first_player_words = []
second_player_words = []
for count in range(first_player_count):
first_player_words.append(input())
for count in range(second_player_count):
second_player_words.append(input())
unique_second_player_words ... | Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You... | ```python
first_player_count, second_player_count = list((map(int, input().split())))
first_player_words = []
second_player_words = []
for count in range(first_player_count):
first_player_words.append(input())
for count in range(second_player_count):
second_player_words.append(input())
unique_second_pla... | 0 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,590,701,664 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 156 | 3,481,600 | f,s = map(int, input().split())
mem = [[0 for i in range(500)]for i in range(500)]
def check(a,b):
if(mem[a][b]):
return mem[a][b]
if(a <=0 or b<= 0):
return 0
else:
mem[a][b] = 1 + max(check(a-2, b+1), check(a+1, b-2))
return mem[a][b]
print(check(f, s))
| Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
f,s = map(int, input().split())
mem = [[0 for i in range(500)]for i in range(500)]
def check(a,b):
if(mem[a][b]):
return mem[a][b]
if(a <=0 or b<= 0):
return 0
else:
mem[a][b] = 1 + max(check(a-2, b+1), check(a+1, b-2))
return mem[a][b]
print(check(f, s))
... | 0 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,674,412,853 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 62 | 0 | x, y = map(int, input().split())
a = list(map(int, input().split()))
ans = 2
for i in range(x-1):
if a[i] + y <= a[i+1] - y:
ans += 1
if a[i+1] - y > a[i] + y:
ans += 1
print(ans) | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
x, y = map(int, input().split())
a = list(map(int, input().split()))
ans = 2
for i in range(x-1):
if a[i] + y <= a[i+1] - y:
ans += 1
if a[i+1] - y > a[i] + y:
ans += 1
print(ans)
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,635,753,323 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 4,505,600 | n = int(input())
dic = {}
for i in range(n):
name,s = [x for x in input().split(" ")]
if name in dic:
dic[name][0] += int(s)
else:
dic[name] = [0,0]
dic[name][0] = int(s)
dic[name][1] = i
ans = ""
maxi = -1000
minind = 1001
for k,v in dic.items():
if v[0... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n = int(input())
dic = {}
for i in range(n):
name,s = [x for x in input().split(" ")]
if name in dic:
dic[name][0] += int(s)
else:
dic[name] = [0,0]
dic[name][0] = int(s)
dic[name][1] = i
ans = ""
maxi = -1000
minind = 1001
for k,v in dic.items():
... | 0 |
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,601,026,201 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 218 | 409,600 | from collections import defaultdict
def DFS(graph,x,visited):
stack = [x]
while len(stack):
temp = stack.pop()
visited[temp] = 1
for j in graph[temp]:
if visited[j] == 0:
stack.append(j)
n,m = map(int,input().split())
d = defaultdict(set)
graph = defaultdict(list)
for j in range(n... | 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
from collections import defaultdict
def DFS(graph,x,visited):
stack = [x]
while len(stack):
temp = stack.pop()
visited[temp] = 1
for j in graph[temp]:
if visited[j] == 0:
stack.append(j)
n,m = map(int,input().split())
d = defaultdict(set)
graph = defaultdict(list)
for j ... | 0 | |
166 | C | Median | PROGRAMMING | 1,500 | [
"greedy",
"math",
"sortings"
] | null | null | A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,<=2,<=3) is the number 2, and a median of array (0,<=96,<=17,<=23) — the number 17.
We defi... | The first input line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=500, 1<=≤<=*x*<=≤<=105) — the initial array's length and the required median's value. The second line contains *n* space-separated numbers — the initial array. The elements of the array are integers from 1 to 105. The array elements a... | Print the only integer — the minimum number of elements Petya needs to add to the array so that its median equals *x*. | [
"3 10\n10 20 30\n",
"3 4\n1 2 3\n"
] | [
"1\n",
"4\n"
] | In the first sample we can add number 9 to array (10, 20, 30). The resulting array (9, 10, 20, 30) will have a median in position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7dd92241318a531b780c7783dfa446a3e413115e.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 10.
In t... | 1,000 | [
{
"input": "3 10\n10 20 30",
"output": "1"
},
{
"input": "3 4\n1 2 3",
"output": "4"
},
{
"input": "2 2\n3 2",
"output": "0"
},
{
"input": "5 1\n1 1 2 1 2",
"output": "0"
},
{
"input": "5 4\n5 5 4 3 5",
"output": "1"
},
{
"input": "10 2\n2 2 1 3 2 1 2 ... | 1,603,335,470 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 102,400 | n,m=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
arr.sort()
median=arr[(n+1)//2-1]
ans=0
while median!=m:
arr.append(m)
ans+=1
arr.sort()
median=arr[(n+1)//2-1]
print(ans) | Title: Median
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,... | ```python
n,m=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
arr.sort()
median=arr[(n+1)//2-1]
ans=0
while median!=m:
arr.append(m)
ans+=1
arr.sort()
median=arr[(n+1)//2-1]
print(ans)
``` | 0 | |
362 | E | Petya and Pipes | PROGRAMMING | 2,300 | [
"flows",
"graphs",
"shortest paths"
] | null | null | A little boy Petya dreams of growing up and becoming the Head Berland Plumber. He is thinking of the problems he will have to solve in the future. Unfortunately, Petya is too inexperienced, so you are about to solve one of such problems for Petya, the one he's the most interested in.
The Berland capital has *n* water ... | The first line contains two space-separated integers *n* and *k* (2<=≤<=*n*<=≤<=50, 0<=≤<=*k*<=≤<=1000). Then follow *n* lines, each line contains *n* integers separated by single spaces. The *i*<=+<=1-th row and *j*-th column contain number *c**ij* — the width of the pipe that goes from tank *i* to tank *j* (0<=≤<=*c*... | Print a single integer — the maximum amount of water that can be transmitted from the main tank to the sewer tank per a unit of time. | [
"5 7\n0 1 0 2 0\n0 0 4 10 0\n0 0 0 0 5\n0 0 0 0 10\n0 0 0 0 0\n",
"5 10\n0 1 0 0 0\n0 0 2 0 0\n0 0 0 3 0\n0 0 0 0 4\n100 0 0 0 0\n"
] | [
"10\n",
"5\n"
] | In the first test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 7 units.
In the second test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 4 units, from the 2nd to the 3rd water tank by 3 units, from the 3rd to the 4th water tank by 2 units a... | 3,000 | [] | 1,692,088,899 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1692088899.2331738")# 1692088899.2331903 | Title: Petya and Pipes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little boy Petya dreams of growing up and becoming the Head Berland Plumber. He is thinking of the problems he will have to solve in the future. Unfortunately, Petya is too inexperienced, so you are about to solve one... | ```python
print("_RANDOM_GUESS_1692088899.2331738")# 1692088899.2331903
``` | 0 | |
813 | C | The Tag Game | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs"
] | null | null | Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob go... | The first line contains two integer numbers *n* and *x* (2<=≤<=*n*<=≤<=2·105, 2<=≤<=*x*<=≤<=*n*).
Each of the next *n*<=-<=1 lines contains two integer numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*) — edges of the tree. It is guaranteed that the edges form a valid tree. | Print the total number of moves Alice and Bob will make. | [
"4 3\n1 2\n2 3\n2 4\n",
"5 2\n1 2\n2 3\n3 4\n2 5\n"
] | [
"4\n",
"6\n"
] | In the first example the tree looks like this:
The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:
B: stay at vertex 3
A: go to vertex 2
B: stay at vertex 3
A: go to vertex 3
In the secon... | 0 | [
{
"input": "4 3\n1 2\n2 3\n2 4",
"output": "4"
},
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "6"
},
{
"input": "2 2\n2 1",
"output": "2"
},
{
"input": "3 3\n2 1\n3 1",
"output": "2"
},
{
"input": "3 3\n1 2\n3 2",
"output": "4"
},
{
"input": "10 4\... | 1,647,269,322 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 30 | 102,400 | import sys
input = sys.stdin.readline
from collections import deque
def solve(n, x, edges):
# BFS, O(N) time and O(N) space
q = deque([(1, 0)])
vis = {1}
dis = 1
while q:
node, dis = q.popleft()
for nei in edges[node]:
if nei in vis:
continue
... | Title: The Tag Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alic... | ```python
import sys
input = sys.stdin.readline
from collections import deque
def solve(n, x, edges):
# BFS, O(N) time and O(N) space
q = deque([(1, 0)])
vis = {1}
dis = 1
while q:
node, dis = q.popleft()
for nei in edges[node]:
if nei in vis:
continue
... | 0 | |
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,693,885,806 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n, j = map(int, input().split())
h = list(map(int, input().split()))
w = 0
for i in h:
if i > h:
w += 2
else:
w += 1
print(w)
| 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, j = map(int, input().split())
h = list(map(int, input().split()))
w = 0
for i in h:
if i > h:
w += 2
else:
w += 1
print(w)
``` | -1 | |
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,653,943,444 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | l = input()
m = input()
n = ""
for i in l[::-1]:
c += i
if c == m:
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
l = input()
m = input()
n = ""
for i in l[::-1]:
c += i
if c == m:
print("YES")
else:
print("NO")
``` | -1 |
553 | A | Kyoya and Colored Balls | PROGRAMMING | 1,500 | [
"combinatorics",
"dp",
"math"
] | null | null | Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of... | The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors.
Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007. | [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n"
] | [
"3\n",
"1680\n"
] | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | 250 | [
{
"input": "3\n2\n2\n1",
"output": "3"
},
{
"input": "4\n1\n2\n3\n4",
"output": "1680"
},
{
"input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "12520708"
},
{
"input": "5\n10\n10\n10\n10\n10",
"output": "425711769"
},
{
"input": "11\n291\n3... | 1,604,579,859 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 389 | 614,400 | def fact(x):
r = 1
for i in range(1, x + 1): r *= i
return r
mod = int(1e9 + 7)
n = int(input())
arr = [0] * n
for i in range(n): arr[i] = int(input())
r = 1; s = 0
for i in range(1, n):
s += arr[i - 1]
r *= fact(s + arr[i] - 1) // fact(s) // fact(arr[i] - 1)
r %= mod
print(r)
| Title: Kyoya and Colored Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by o... | ```python
def fact(x):
r = 1
for i in range(1, x + 1): r *= i
return r
mod = int(1e9 + 7)
n = int(input())
arr = [0] * n
for i in range(n): arr[i] = int(input())
r = 1; s = 0
for i in range(1, n):
s += arr[i - 1]
r *= fact(s + arr[i] - 1) // fact(s) // fact(arr[i] - 1)
r %= mod
pr... | 3 | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,680,493,086 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 46 | 0 | n = int(input())
h = [0] * n
v = [0] * n
g = []
for i in range(n * n):
a, b = map(int, input().split())
if h[a - 1] == 0 and v[b - 1] == 0:
h[a - 1] = 1
v[b - 1] = 1
g.append(i+1)
print(*g) | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
n = int(input())
h = [0] * n
v = [0] * n
g = []
for i in range(n * n):
a, b = map(int, input().split())
if h[a - 1] == 0 and v[b - 1] == 0:
h[a - 1] = 1
v[b - 1] = 1
g.append(i+1)
print(*g)
``` | 3 | |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n010100101010100101001001010100101010010... | 1,625,293,672 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
s=input()
for i in range(n):
for j in range(i+1,n):
if s[i]==s[j]:
print("no")
else:
print("yes") | Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th... | ```python
n=int(input())
s=input()
for i in range(n):
for j in range(i+1,n):
if s[i]==s[j]:
print("no")
else:
print("yes")
``` | 0 | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,446,735,805 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 62 | 0 | l = int(input())
p = int(input())
q = int(input())
t = l/(p+q)
ans = p*t
print(ans)
| Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
l = int(input())
p = int(input())
q = int(input())
t = l/(p+q)
ans = p*t
print(ans)
``` | 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,655,322,865 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in a:
if n - i >= k:
ans += 1
print(ans//3) | 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
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in a:
if n - i >= k:
ans += 1
print(ans//3)
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,592,507,579 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | s=input()
t='hello'
n=len(s)
j=0
for i in range(n-1):
if(s[i]==t[j]):
j+=1
else:
continue
if(j==len(t)):
print('YES')
break
if(j!=len(t)):
print('NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
t='hello'
n=len(s)
j=0
for i in range(n-1):
if(s[i]==t[j]):
j+=1
else:
continue
if(j==len(t)):
print('YES')
break
if(j!=len(t)):
print('NO')
``` | 0 |
493 | A | Vasya and Football | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls tha... | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number *n* (1<=≤<=*n*<=≤<=9... | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card.
If no player received a card, then you do not need to... | [
"MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n"
] | [
"MC 25 70\nMC 42 82\nCSKA 13 90\n"
] | none | 500 | [
{
"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r",
"output": "MC 25 70\nMC 42 82\nCSKA 13 90"
},
{
"input": "REAL\nBARCA\n3\n27 h 7 y\n44 a 10 y\n87 h 3 r",
"output": "REAL 3 87"
},
{
"input": "MASFF\nSAFBDSRG\n5\n1 ... | 1,696,842,995 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 61 | 0 | # Wadea #
h = input()
a = input()
arr = []
player = []
out = []
for i in range(int(input())):
minute,ha,num,card = input().split()
arr.append([ha,num])
if card == "r":
if ha == "h":
out.append([h,num,minute])
elif ha == "a":
out.append([a,num,minute])
... | Title: Vasya and Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically re... | ```python
# Wadea #
h = input()
a = input()
arr = []
player = []
out = []
for i in range(int(input())):
minute,ha,num,card = input().split()
arr.append([ha,num])
if card == "r":
if ha == "h":
out.append([h,num,minute])
elif ha == "a":
out.append([a,num,... | 0 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,610,152,184 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 109 | 1,331,200 | n = int(input())
arr = input().split()
for i in range(2*n):
arr[i] = int(arr[i])
arr.sort()
b = [0] * (n*2)
ctr = 0
best = 1000000
for i in range(2*n):
for j in range(i+1, 2*n):
for k in range(2*n):
b[k] = arr[k]
b[i] = -1
b[j] = -1
b.sort()
... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
n = int(input())
arr = input().split()
for i in range(2*n):
arr[i] = int(arr[i])
arr.sort()
b = [0] * (n*2)
ctr = 0
best = 1000000
for i in range(2*n):
for j in range(i+1, 2*n):
for k in range(2*n):
b[k] = arr[k]
b[i] = -1
b[j] = -1
b.sort(... | 3 | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,532,463,502 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 124 | 0 | n = int(input())
ball = int(input())
n = n % 6
while n > 0:
if n % 2 == 1:
if ball == 0:
ball = 1
elif ball == 1:
ball = 0
elif n % 2 == 0:
if ball == 1:
ball = 2
elif ball == 2:
ball = 1
n -= 1
print(ball) | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
n = int(input())
ball = int(input())
n = n % 6
while n > 0:
if n % 2 == 1:
if ball == 0:
ball = 1
elif ball == 1:
ball = 0
elif n % 2 == 0:
if ball == 1:
ball = 2
elif ball == 2:
ball = 1
n -= 1
print(ball)
``` | 3 | |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,631,770,826 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 93 | 16,179,200 | n = int(input())
l = sorted(set(map(int, input().split())))
s = len(l)
print(['NO', 'YES'][s<3 or (s==3 and l[0]+l[2]==l[1]*2)])
| Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a... | ```python
n = int(input())
l = sorted(set(map(int, input().split())))
s = len(l)
print(['NO', 'YES'][s<3 or (s==3 and l[0]+l[2]==l[1]*2)])
``` | 3 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,689,709,990 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 46 | 0 |
def num(k,r):
if k == r:
return 1
elif k%10 == 5:
return 2
elif k%10 == 0:
return 1
else:
for i in range(1,10):
d = k * i
rem = d%10
if rem == r:
return i
if __name__ == '__ma... | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
def num(k,r):
if k == r:
return 1
elif k%10 == 5:
return 2
elif k%10 == 0:
return 1
else:
for i in range(1,10):
d = k * i
rem = d%10
if rem == r:
return i
if __name_... | 0 | |
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==... | The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). | Output a single integer — the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
... | 1,584,379,271 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 139 | 0 | p=[];a=[]
m,n=map(int,input().split())
for i in range(n):
x=int(input())
if x in p:
a.append(i)
p.append(x)
print(a[0] if len(a)!=0 else '-1') | Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere... | ```python
p=[];a=[]
m,n=map(int,input().split())
for i in range(n):
x=int(input())
if x in p:
a.append(i)
p.append(x)
print(a[0] if len(a)!=0 else '-1')
``` | 0 | |
976 | E | Well played! | PROGRAMMING | 2,100 | [
"greedy",
"sortings"
] | null | null | Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns *n* creatures, *i*-th of them can be described with two numbers — its health *hp**i* and its damage *dmg**i*. Max also ha... | The first line contains three integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*a*<=≤<=20, 0<=≤<=*b*<=≤<=2·105) — the number of creatures, spells of the first type and spells of the second type, respectively.
The *i*-th of the next *n* lines contain two number *hp**i* and *dmg**i* (1<=≤<=*hp**i*,<=*dmg**i*<=≤<=109) ... | Print single integer — maximum total damage creatures can deal. | [
"2 1 1\n10 15\n6 1\n",
"3 0 3\n10 8\n7 11\n5 2\n"
] | [
"27\n",
"26\n"
] | In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27.
In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on... | 0 | [
{
"input": "2 1 1\n10 15\n6 1",
"output": "27"
},
{
"input": "3 0 3\n10 8\n7 11\n5 2",
"output": "26"
},
{
"input": "1 0 0\n2 1",
"output": "1"
},
{
"input": "1 0 200000\n1 2",
"output": "2"
},
{
"input": "7 5 7\n29 25\n84 28\n34 34\n14 76\n85 9\n40 57\n99 88",
... | 1,540,221,604 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 25,600,000 | def main():
n, a, b = map(int, input().split())
arr = []
for i in range(n):
arr.append(list(map(int,input().split())))
arr.sort(key=lambda x:-x[0]+x[1])
total = 0
for i in range(len(arr)):
if i < b:
total += max(arr[i][0], arr[i][1])
else:
... | Title: Well played!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns *n* creatures, *i*-th o... | ```python
def main():
n, a, b = map(int, input().split())
arr = []
for i in range(n):
arr.append(list(map(int,input().split())))
arr.sort(key=lambda x:-x[0]+x[1])
total = 0
for i in range(len(arr)):
if i < b:
total += max(arr[i][0], arr[i][1])
else... | 0 | |
475 | B | Strongly Connected City | PROGRAMMING | 1,400 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes... | The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character... | If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". | [
"3 3\n><>\nv^v\n",
"4 6\n<><>\nv^v^v^\n"
] | [
"NO\n",
"YES\n"
] | The figure above shows street directions in the second sample test case. | 1,000 | [
{
"input": "3 3\n><>\nv^v",
"output": "NO"
},
{
"input": "4 6\n<><>\nv^v^v^",
"output": "YES"
},
{
"input": "2 2\n<>\nv^",
"output": "YES"
},
{
"input": "2 2\n>>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\n^^v",
"output": "YES"
},
{
"input": "3 4\n>>... | 1,690,198,046 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n, m = map(int, input().split())
hor = input()
vert = input()
if (vert[0]!=vert[n-1]) and (hor[0]!=hor[n-1]):
print("YES")
else:
print("NO")
| Title: Strongly Connected City
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one... | ```python
n, m = map(int, input().split())
hor = input()
vert = input()
if (vert[0]!=vert[n-1]) and (hor[0]!=hor[n-1]):
print("YES")
else:
print("NO")
``` | 0 | |
689 | B | Mike and Shortcuts | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"greedy",
"shortest paths"
] | null | null | Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Wal... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of ... | In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*. | [
"3\n2 2 3\n",
"5\n1 2 3 4 5\n",
"7\n4 4 4 4 7 7 7\n"
] | [
"0 1 2 \n",
"0 1 2 3 4 \n",
"0 1 2 1 2 3 3 \n"
] | In the first sample case desired sequences are:
1: 1; *m*<sub class="lower-index">1</sub> = 0;
2: 1, 2; *m*<sub class="lower-index">2</sub> = 1;
3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2.
In the second sample case the sequence for any intersection 1 < *i* is always 1, *i* and *m*<sub class="lowe... | 1,000 | [
{
"input": "3\n2 2 3",
"output": "0 1 2 "
},
{
"input": "5\n1 2 3 4 5",
"output": "0 1 2 3 4 "
},
{
"input": "7\n4 4 4 4 7 7 7",
"output": "0 1 2 1 2 3 3 "
},
{
"input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87... | 1,467,824,411 | 1,511 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
ll MOD = 1e9 + 7;
const ld E = 1e-10;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#ifndef LOCA... | Title: Mike and Shortcuts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walkin... | ```python
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
ll MOD = 1e9 + 7;
const ld E = 1e-10;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#i... | -1 | |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,405,270,623 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 140 | 5,120,000 | import sys
import string
from decimal import *
from itertools import *
from math import *
def solve():
s = input()
k = int(input())
w = list(map(int,input().split()))
mm = max(w)
ans = 0
for i in range(len(s)+k):
if (i < len(s)):
ans = ans + w[ord(s[i])-ord('a... | Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
import sys
import string
from decimal import *
from itertools import *
from math import *
def solve():
s = input()
k = int(input())
w = list(map(int,input().split()))
mm = max(w)
ans = 0
for i in range(len(s)+k):
if (i < len(s)):
ans = ans + w[ord(s[... | 3 | |
883 | G | Orientation of Edges | PROGRAMMING | 1,900 | [
"dfs and similar",
"graphs"
] | null | null | Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex *s* from the graph. Now Vasya wants to create two separate plans:
1. to orient each undirected edge in one of two possible directions to maximiz... | The first line contains three integers *n*, *m* and *s* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*m*<=≤<=3·105, 1<=≤<=*s*<=≤<=*n*) — number of vertices and edges in the graph, and the vertex Vasya has picked.
The following *m* lines contain information about the graph edges. Each line contains three integers *t**i*, *u**i* and *v*... | The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices.
A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan s... | [
"2 2 1\n1 1 2\n2 2 1\n",
"6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3\n"
] | [
"2\n-\n2\n+\n",
"6\n++-\n2\n+-+\n"
] | none | 0 | [
{
"input": "2 2 1\n1 1 2\n2 2 1",
"output": "2\n-\n2\n+"
},
{
"input": "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3",
"output": "6\n++-\n2\n+-+"
},
{
"input": "5 5 5\n2 5 3\n1 2 3\n1 4 5\n2 5 2\n1 2 1",
"output": "4\n++\n1\n--"
},
{
"input": "13 18 9\n2 3 10\n1 12 10\n1 1... | 1,609,965,477 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 12 | 530 | 20,480,000 | from collections import defaultdict
def dfs(u):
vis[u]=1
for j in adj[u]:
if d[j,u]==1:
d1[j,u]="+"
elif d[u,j]==1:
d1[u,j]="-"
if d3[u,j]:
if not vis[j]:
dfs(j)
def dfs2(u):
vis[u] = 1
for j in adj[u]:
... | Title: Orientation of Edges
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex *s* from the graph. Now Vasya wants to c... | ```python
from collections import defaultdict
def dfs(u):
vis[u]=1
for j in adj[u]:
if d[j,u]==1:
d1[j,u]="+"
elif d[u,j]==1:
d1[u,j]="-"
if d3[u,j]:
if not vis[j]:
dfs(j)
def dfs2(u):
vis[u] = 1
for j in ad... | -1 | |
407 | A | Triangle | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"implementation",
"math"
] | null | null | There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the... | The first line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=1000), separated by a single space. | In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute valu... | [
"1 1\n",
"5 5\n",
"5 10\n"
] | [
"NO\n",
"YES\n2 1\n5 5\n-2 4\n",
"YES\n-10 4\n-2 -2\n1 2\n"
] | none | 500 | [
{
"input": "1 1",
"output": "NO"
},
{
"input": "5 5",
"output": "YES\n2 1\n5 5\n-2 4"
},
{
"input": "5 10",
"output": "YES\n-10 4\n-2 -2\n1 2"
},
{
"input": "2 2",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 11",
"output": "... | 1,557,365,076 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | a, b = map(int, input().split())
s = [i*i for i in range(1, int(max(a, b)**0.5+1))]
for i in s:
if a-i in s:
for j in s:
if b-j in s: print('YES'); exit()
print('NO'); exit()
print('NO') | Title: Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the v... | ```python
a, b = map(int, input().split())
s = [i*i for i in range(1, int(max(a, b)**0.5+1))]
for i in s:
if a-i in s:
for j in s:
if b-j in s: print('YES'); exit()
print('NO'); exit()
print('NO')
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,650,192,875 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n, m =input().split()
e = (int(n)*int(m))/2
print(int(e)) | 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
n, m =input().split()
e = (int(n)*int(m))/2
print(int(e))
``` | -1 |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,688,419,907 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | x1,x2,x3 = map(int, input().split())
z1 = abs(x2-x1)+abs(x3-x2)
z2 = abs(x1-x2)+abs(x1-x3)
z3 = abs(x3-x1)+abs(x3-x2)
print(min(z1,z2,z3))
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
x1,x2,x3 = map(int, input().split())
z1 = abs(x2-x1)+abs(x3-x2)
z2 = abs(x1-x2)+abs(x1-x3)
z3 = abs(x3-x1)+abs(x3-x2)
print(min(z1,z2,z3))
``` | 3 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,579,113,971 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | #867A
n = int(input())
a = list(input())
cur = a[0]
count = 0
total = 0
for i in range(1,n):
if cur == 'S' and a[i] == 'F':
count+=1
if cur == a[i]:
total += 1
cur = a[i]
if count > (total-count):
print('YES')
else:
print('NO') | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
#867A
n = int(input())
a = list(input())
cur = a[0]
count = 0
total = 0
for i in range(1,n):
if cur == 'S' and a[i] == 'F':
count+=1
if cur == a[i]:
total += 1
cur = a[i]
if count > (total-count):
print('YES')
else:
print('NO')
``` | 0 | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,675,860,378 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
s = input()
# Count the number of 'U's and 'R's in the input string
u_count = s.count('U')
r_count = s.count('R')
# The minimum length of the sequence after replacements is the minimum of the number of 'U's and 'R's
print(min(u_count, r_count) * 2 + 1)
| Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
n = int(input())
s = input()
# Count the number of 'U's and 'R's in the input string
u_count = s.count('U')
r_count = s.count('R')
# The minimum length of the sequence after replacements is the minimum of the number of 'U's and 'R's
print(min(u_count, r_count) * 2 + 1)
``` | 0 | |
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,524,693,411 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 7,065,600 | n,k=[int(x) for x in input().split()]
m=[]
for i in range(n):
m.append(list(input()))
for i in range(n):
for j in range(n):
if m[i][j]=='.':
m[i][j]=1
else:
m[i][j]=-1
for i in range(n):
for j in range(n):
if m[i][j]>=1:
#down
... | 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
n,k=[int(x) for x in input().split()]
m=[]
for i in range(n):
m.append(list(input()))
for i in range(n):
for j in range(n):
if m[i][j]=='.':
m[i][j]=1
else:
m[i][j]=-1
for i in range(n):
for j in range(n):
if m[i][j]>=1:
#d... | -1 | |
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,414,225,048 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 30 | 62 | 0 | import sys
import math
n = int(sys.stdin.readline())
x = [int(x) for x in (sys.stdin.readline()).split()]
vmax = 0
vmin = 100
for k in x:
if(k > vmax):
vmax = k
if(k < vmin):
vmin = k
res = 0
while(vmin != 0):
res = vmin
t = vmax % vmin
vmax = vmin
... | 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
import sys
import math
n = int(sys.stdin.readline())
x = [int(x) for x in (sys.stdin.readline()).split()]
vmax = 0
vmin = 100
for k in x:
if(k > vmax):
vmax = k
if(k < vmin):
vmin = k
res = 0
while(vmin != 0):
res = vmin
t = vmax % vmin
vm... | 0 | |
527 | A | Playing with Paper | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle... | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | 500 | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"in... | 1,645,950,212 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 62 | 0 | # m, n = map(lambda v: int(v), input().split())
# n = int(input())
# mem=dict()
# mem.setdefault(1, 1)
# mem.setdefault(2, 1)
# def fib(a):
# if not mem.get(a): mem.setdefault(a, fib(a-1) + fib(a-2))
# return mem[a]
a,b = map(lambda v: int(v), input().split())
i=1
while a!=b and a*b>0:
if a... | Title: Playing with Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a squ... | ```python
# m, n = map(lambda v: int(v), input().split())
# n = int(input())
# mem=dict()
# mem.setdefault(1, 1)
# mem.setdefault(2, 1)
# def fib(a):
# if not mem.get(a): mem.setdefault(a, fib(a-1) + fib(a-2))
# return mem[a]
a,b = map(lambda v: int(v), input().split())
i=1
while a!=b and a*b>0:... | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,693,636,896 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 46 | 0 | n,m,a,b = map(int,input().split())
if (m*a >b):
rem = n%m * a
if rem>b:
print(n // m * b + b)
else:
print(n // m * b + rem)
else:
print(n*a)
| Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
n,m,a,b = map(int,input().split())
if (m*a >b):
rem = n%m * a
if rem>b:
print(n // m * b + b)
else:
print(n // m * b + rem)
else:
print(n*a)
``` | 3 | |
808 | B | Average Sleep Time | PROGRAMMING | 1,300 | [
"data structures",
"implementation",
"math"
] | null | null | It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp k... | The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | Output average sleeping time over all weeks.
The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point. | [
"3 2\n3 4 7\n",
"1 1\n10\n",
"8 2\n1 2 4 100000 123 456 789 1\n"
] | [
"9.0000000000\n",
"10.0000000000\n",
"28964.2857142857\n"
] | In the third example there are *n* - *k* + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. | 0 | [
{
"input": "3 2\n3 4 7",
"output": "9.0000000000"
},
{
"input": "1 1\n10",
"output": "10.0000000000"
},
{
"input": "8 2\n1 2 4 100000 123 456 789 1",
"output": "28964.2857142857"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n100000",
"ou... | 1,517,220,467 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 62 | 5,632,000 | n,k=(int(x) for x in input().split())
s=[int(x) for x in input().split()]
a=0
for i in range(k):
a+=s[i]
a/=k
x=a
if n==k:
print(a)
else:
for i in range(n-k):
x=(x*k+s[i+k]-s[i])/k
a+=x
a/=(n-k+1)
print(a*k) | Title: Average Sleep Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his s... | ```python
n,k=(int(x) for x in input().split())
s=[int(x) for x in input().split()]
a=0
for i in range(k):
a+=s[i]
a/=k
x=a
if n==k:
print(a)
else:
for i in range(n-k):
x=(x*k+s[i+k]-s[i])/k
a+=x
a/=(n-k+1)
print(a*k)
``` | 0 | |
814 | A | An abandoned sentiment from past | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly ... | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulti... | 500 | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 4... | 1,497,257,178 | 2,147,483,647 | Python 3 | OK | TESTS | 96 | 77 | 0 |
def solve(n,k,a,b):
if k==1:
for i in range(n):
if a[i]==0:
a[i] = b[0]
for i in range(n):
j = i+1
while(j<n):
if a[i]>a[j]:
return "Yes"
j = j+1
return "No"... | Title: An abandoned sentiment from past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of t... | ```python
def solve(n,k,a,b):
if k==1:
for i in range(n):
if a[i]==0:
a[i] = b[0]
for i in range(n):
j = i+1
while(j<n):
if a[i]>a[j]:
return "Yes"
j = j+1
r... | 3 | |
339 | B | Xenia and Ringroad | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). Note that Xenia can have multiple consecutive tasks in one house. | Print a single integer — the time Xenia needs to complete all tasks.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n3 2 3\n",
"4 3\n2 3 3\n"
] | [
"6\n",
"2\n"
] | In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units. | 1,000 | [
{
"input": "4 3\n3 2 3",
"output": "6"
},
{
"input": "4 3\n2 3 3",
"output": "2"
},
{
"input": "2 2\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "100 100\n56 46 1 47 5 86 45 35 81 1 ... | 1,694,861,860 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 156 | 13,824,000 | n, m = map(int, input().split())
tasks = list(map(int, input().split()))
current_house = 1
total_time = 0
for task in tasks:
if task >= current_house:
time_to_task = task - current_house
else:
time_to_task = n - current_house + task
total_time += time_to_task
curren... | Title: Xenia and Ringroad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recent... | ```python
n, m = map(int, input().split())
tasks = list(map(int, input().split()))
current_house = 1
total_time = 0
for task in tasks:
if task >= current_house:
time_to_task = task - current_house
else:
time_to_task = n - current_house + task
total_time += time_to_task
... | 3 | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,637,415,281 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 62 | 0 | def round(n):
if n-int(n)>=0.5:
return n+1
else:
return n
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
if round(sum(a)/n)>=k:
print(0)
else:
print(2*k*n-2*sum(a)-n) | Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
def round(n):
if n-int(n)>=0.5:
return n+1
else:
return n
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
if round(sum(a)/n)>=k:
print(0)
else:
print(2*k*n-2*sum(a)-n)
``` | 3 | |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 ... | 1,625,580,004 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 154 | 0 | a,b=input().split()
a,b=int(a),int(b)
c=a//b
rem=a%b
d=[c]*(b-rem)
d=d+[c+1]*rem
for i in d:
print(i,end=" ") | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ... | ```python
a,b=input().split()
a,b=int(a),int(b)
c=a//b
rem=a%b
d=[c]*(b-rem)
d=d+[c+1]*rem
for i in d:
print(i,end=" ")
``` | 3 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,683,179,496 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | x = list(input())
y = []
for i in range(len(x)):
if (int(x[i]) >= 5):
y.append(9-int(x[i]))
else:
y.append(int(x[i]))
stri = ""
for i in y:
stri = stri + str(i)
print(stri) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
x = list(input())
y = []
for i in range(len(x)):
if (int(x[i]) >= 5):
y.append(9-int(x[i]))
else:
y.append(int(x[i]))
stri = ""
for i in y:
stri = stri + str(i)
print(stri)
``` | 0 | |
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,601,514,354 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 218 | 307,200 | def determine(l,a,b):
if l < a+b:
return 'TRIANGLE'
elif l == a+b:
return 'SEGMENT'
else:
return 'IMPOSSIBLE'
if __name__ == '__main__':
lines = list(map(int, input().split()))
lines.sort(reverse=True)
result = set([determine(*lines[:-1]), determine(*lines[1:])])
if 'TRIANGLE' in result... | 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
def determine(l,a,b):
if l < a+b:
return 'TRIANGLE'
elif l == a+b:
return 'SEGMENT'
else:
return 'IMPOSSIBLE'
if __name__ == '__main__':
lines = list(map(int, input().split()))
lines.sort(reverse=True)
result = set([determine(*lines[:-1]), determine(*lines[1:])])
if 'TRIANGLE'... | 3.943211 |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,698,779,074 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | n, t = map(int, input().split())
s = input()
while t:
s = s.replace("BG", "GB")
t -= 1
print(s) | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
n, t = map(int, input().split())
s = input()
while t:
s = s.replace("BG", "GB")
t -= 1
print(s)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,635,723,252 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 61 | 4,300,800 | s = input()
l= input()
d=[]
b=int(len(s))
for i in range(0,b):
if s[i]==l[i]:
d.append("0")
else:
d.append("1")
print(''.join(d))
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
s = input()
l= input()
d=[]
b=int(len(s))
for i in range(0,b):
if s[i]==l[i]:
d.append("0")
else:
d.append("1")
print(''.join(d))
``` | 3.976739 |
660 | B | Seating On Bus | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*.
Consider that *m* (*m*<=≤<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to... | The only line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=4*n*) — the number of pairs of rows and the number of passengers. | Print *m* distinct integers from 1 to *m* — the order in which the passengers will get off the bus. | [
"2 7\n",
"9 36\n"
] | [
"5 1 6 2 7 3 4\n",
"19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18\n"
] | none | 0 | [
{
"input": "2 7",
"output": "5 1 6 2 7 3 4"
},
{
"input": "9 36",
"output": "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 4",
"output": "3 1 4 2"
},
{
"input... | 1,651,839,226 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 46 | 0 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
n = n*4
a = list(range(n//2+1, n+1))
b = list(range(1, n//2+1))
for i in range(n//2):
if a[i] <= m:
print(a[i], end=' ')
if b[i] <= m:
print(b[i], end=' ')
| Title: Seating On Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*.
Consider that *m* (*m*<... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
n = n*4
a = list(range(n//2+1, n+1))
b = list(range(1, n//2+1))
for i in range(n//2):
if a[i] <= m:
print(a[i], end=' ')
if b[i] <= m:
print(b[i], end=' ')
``` | 3 | |
748 | A | Santa Claus and a Place in a Class | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 500 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,482,662,686 | 5,986 | Python 3 | OK | TESTS | 46 | 77 | 4,608,000 | a=input().split()
if int(a[2])%2==0:
s='R'
else:
s='L'
k=0
if int(a[2])%(int(a[1])*2)>0:
k+=1
r=int(a[2])%(int(a[1])*2)//2+int(a[2])%(int(a[1])*2)%2
if r==0:
r=a[1]
print(int(a[2])//(int(a[1])*2)+k)
print(r)
print(s)
| Title: Santa Claus and a Place in a Class
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work... | ```python
a=input().split()
if int(a[2])%2==0:
s='R'
else:
s='L'
k=0
if int(a[2])%(int(a[1])*2)>0:
k+=1
r=int(a[2])%(int(a[1])*2)//2+int(a[2])%(int(a[1])*2)%2
if r==0:
r=a[1]
print(int(a[2])//(int(a[1])*2)+k)
print(r)
print(s)
``` | 3 | |
131 | B | Opposites Attract | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* (<=-<=10<=≤<=*t**i*<=≤<=10). Of course, one number can be assigned to an... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=10<=≤<=*t**i*<=≤<=10), *t**i* — is the parameter of the *i*-th customer that has been ... | Print the number of couples of customs with opposite *t*. The opposite number for *x* is number <=-<=*x* (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. ... | [
"5\n-3 3 0 0 3\n",
"3\n0 0 0\n"
] | [
"3\n",
"3\n"
] | In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite. | 1,000 | [
{
"input": "5\n-3 3 0 0 3",
"output": "3"
},
{
"input": "3\n0 0 0",
"output": "3"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "2\n-3 3",
"output": "1"
},
{
"inp... | 1,694,560,251 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 7,680,000 | size = int(input())
couples = input().split(" ")
couples = [int(x) for x in couples]
count = 0
for x in range(len(couples)):
for y in range(x + 1, len(couples)):
if couples[x] + couples[y] == 0:
count += 1
print(count)
| Title: Opposites Attract
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to t... | ```python
size = int(input())
couples = input().split(" ")
couples = [int(x) for x in couples]
count = 0
for x in range(len(couples)):
for y in range(x + 1, len(couples)):
if couples[x] + couples[y] == 0:
count += 1
print(count)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.