contestId int64 0 1.01k | index stringclasses 55
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 7 | title stringclasses 495
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 5 65.5k | instruction_seed stringlengths 262 8.2k | response stringlengths 19 65.5k | score float64 -1 3.99 | _source stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\n1 1 ... | 1,516,516,460 | 3,980 | Python 3 | OK | TESTS | 140 | 140 | 14,438,400 | n = int(input())
a = list(map(int, input().split()))
mina = min(a)
def minrange(u):
i = 0
posa = []
ans = []
while i != u:
if a[i] == mina:
posa.append(i)
i += 1
for i in range(len(posa)-1):
ans.append(posa[i+1] - posa[i])
return min(ans)
print(m... | Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
I... | ```python
n = int(input())
a = list(map(int, input().split()))
mina = min(a)
def minrange(u):
i = 0
posa = []
ans = []
while i != u:
if a[i] == mina:
posa.append(i)
i += 1
for i in range(len(posa)-1):
ans.append(posa[i+1] - posa[i])
return min(ans... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, ... | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving pro... | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{... | 1,658,585,121 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 46 | 0 | time = list(map(int, input().split()))
w = list(map(int, input().split()))
h = list(map(int, input().split()))
score = 0
for i in range(5):
score += max(0.3*500*(i+1), ((1-(time[i]/250))*(500*(i+1))-(50*w[i])))
score += (100)*h[0]
score -= (50)*h[1]
print(int(score))
| Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challengin... | ```python
time = list(map(int, input().split()))
w = list(map(int, input().split()))
h = list(map(int, input().split()))
score = 0
for i in range(5):
score += max(0.3*500*(i+1), ((1-(time[i]/250))*(500*(i+1))-(50*w[i])))
score += (100)*h[0]
score -= (50)*h[1]
print(int(score))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,672,379,606 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 34,406,400 | def jhon(Int):
if Int in [0,1]:
return [Int]
else:
return jhon(Int//2) + jhon(Int%2) + jhon(Int//2)
nums = input().split(' ')
nums[0] = jhon(int(nums[0]))
count = 0
r = int(nums.pop())
l = int(nums.pop())
for i in nums[0][l-1:r]:
if i == 1:
count += 1
print(count) | Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
def jhon(Int):
if Int in [0,1]:
return [Int]
else:
return jhon(Int//2) + jhon(Int%2) + jhon(Int//2)
nums = input().split(' ')
nums[0] = jhon(int(nums[0]))
count = 0
r = int(nums.pop())
l = int(nums.pop())
for i in nums[0][l-1:r]:
if i == 1:
count += 1
pri... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The ro... | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th... | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight ... | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": ... | 1,532,898,025 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 124 | 0 | d = 'abcdefghijklmnopqrstuvwxyz'
n, k = map(int, input().split())
s = sorted(input())
c = [d.find(str(i))+1 for i in s]
summa, x, i, step = c[0], 1, 0, 1
while x < k and i+step < n:
if c[i+step]-c[i] > 1:
summa += c[i+step]
i += step
step = 1
x += 1
else:
st... | Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — conca... | ```python
d = 'abcdefghijklmnopqrstuvwxyz'
n, k = map(int, input().split())
s = sorted(input())
c = [d.find(str(i))+1 for i in s]
summa, x, i, step = c[0], 1, 0, 1
while x < k and i+step < n:
if c[i+step]-c[i] > 1:
summa += c[i+step]
i += step
step = 1
x += 1
else:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,660,235,202 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | def main():
factorials = {4: [3, 2, 2], 6: [3, 5]}
n = int(input())
digits = []
for digit in list(map(int, list(input()))):
if digit == 0 or digit == 1:
continue
add = [digit]
if digit in factorials:
add = factorials[digit]
digits.extend(... | 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
def main():
factorials = {4: [3, 2, 2], 6: [3, 5]}
n = int(input())
digits = []
for digit in list(map(int, list(input()))):
if digit == 0 or digit == 1:
continue
add = [digit]
if digit in factorials:
add = factorials[digit]
digi... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
508 | C | Anya and Ghosts | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | Anya loves to watch horror movies. In the best traditions of horror, she will be visited by *m* ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly *t* seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one... | The first line contains three integers *m*, *t*, *r* (1<=≤<=*m*,<=*t*,<=*r*<=≤<=300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.
The next line contains *m* space-separated numbers *w**i* (1<=≤<=*i*<=≤<=*m*, ... | If it is possible to make at least *r* candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.
If that is impossible, print <=-<=1. | [
"1 8 3\n10\n",
"2 10 1\n5 8\n",
"1 1 3\n10\n"
] | [
"3\n",
"1\n",
"-1\n"
] | Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.
It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from se... | 1,500 | [
{
"input": "1 8 3\n10",
"output": "3"
},
{
"input": "2 10 1\n5 8",
"output": "1"
},
{
"input": "1 1 3\n10",
"output": "-1"
},
{
"input": "21 79 1\n13 42 51 60 69 77 94 103 144 189 196 203 210 215 217 222 224 234 240 260 282",
"output": "4"
},
{
"input": "125 92 2\... | 1,667,808,701 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 62 | 1,638,400 | m,t,r=map(int,input().split())
l=[0 for _ in range(1200)]
g=[]
start=600
ans=0
g=list(map(int,input().split()))
if r+1>t:print(-1)
else:
for i in range(m):
gi=g[i]
start=gi+600#映射
cha=max(0,r-l[start])
# print(start,cha)
d=0
while cha:
for... | Title: Anya and Ghosts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by *m* ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly *t* seconds. It... | ```python
m,t,r=map(int,input().split())
l=[0 for _ in range(1200)]
g=[]
start=600
ans=0
g=list(map(int,input().split()))
if r+1>t:print(-1)
else:
for i in range(m):
gi=g[i]
start=gi+600#映射
cha=max(0,r-l[start])
# print(start,cha)
d=0
while cha:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
154 | C | Double Profiles | PROGRAMMING | 2,300 | [
"graphs",
"hashing",
"sortings"
] | null | null | You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably belong to the same user.
The social network contains *n* registered profiles, numbered from 1 to *n*. Some pairs there are friends (the "friendship" relationship is mutual... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=106, 0<=≤<=*m*<=≤<=106), — the number of profiles and the number of pairs of friends, correspondingly.
Next *m* lines contains descriptions of pairs of friends in the format "*v* *u*", where *v* and *u* (1<=≤<=*v*,<=*u*<=≤<=*n*,<=*v*<=≠<=... | Print the single integer — the number of unordered pairs of profiles that are doubles.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator. | [
"3 3\n1 2\n2 3\n1 3\n",
"3 0\n",
"4 1\n1 3\n"
] | [
"3\n",
"3\n",
"2\n"
] | In the first and second sample any two profiles are doubles.
In the third sample the doubles are pairs of profiles (1, 3) and (2, 4). | 1,500 | [
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "3"
},
{
"input": "3 0",
"output": "3"
},
{
"input": "4 1\n1 3",
"output": "2"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "2 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"in... | 1,642,015,813 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 19 | 3,000 | 8,908,800 | mod = 200560490131
p = 31
n, m = list(map(int, input().split(" ")))
ps = [0] * (n + 1)
aux = 1
for i in range(1, n + 1):
ps[i] = aux
aux = (aux * p) % mod
A = []
for _ in range(m):
aux = list(map(int, input().split(" ")))
A.append([aux[0], aux[1]])
A.append([aux[1], aux[0]])
A.sort()
idx = 0
... | Title: Double Profiles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably belong to the same user.
The social network contains *n* registered pr... | ```python
mod = 200560490131
p = 31
n, m = list(map(int, input().split(" ")))
ps = [0] * (n + 1)
aux = 1
for i in range(1, n + 1):
ps[i] = aux
aux = (aux * p) % mod
A = []
for _ in range(m):
aux = list(map(int, input().split(" ")))
A.append([aux[0], aux[1]])
A.append([aux[1], aux[0]])
A.sort(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl... | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "... | 1,643,178,012 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 46 | 0 | x,y=map(int,input().split())
if x==y:
print('=')
else:
if x<y:
if x==1:
print('<')
elif x==2 and y==3:
print('<')
elif x==2 and y==4:
print('=')
else:
print('>')
else:
if y==1:
print('>')
... | Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out tha... | ```python
x,y=map(int,input().split())
if x==y:
print('=')
else:
if x<y:
if x==1:
print('<')
elif x==2 and y==3:
print('<')
elif x==2 and y==4:
print('=')
else:
print('>')
else:
if y==1:
print(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,684,652,326 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | a=int(input())
if a%2==0:
print(a-8, 8)
else:
print(a-9,9) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
a=int(input())
if a%2==0:
print(a-8, 8)
else:
print(a-9,9)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,659,706,226 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n = list(input())
scales = list(input())
# chars before |
b = n.index('|')
# chars after |
a = len(n) - (b + 1)
be, af = n[:b], n[b + 1:]
############
if a == b and len(scales) % 2 != 0:
print("Impossible")
############
elif a == b and len(scales) % 2 == 0:
for char in range(0, len(scales) // 2):
... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
n = list(input())
scales = list(input())
# chars before |
b = n.index('|')
# chars after |
a = len(n) - (b + 1)
be, af = n[:b], n[b + 1:]
############
if a == b and len(scales) % 2 != 0:
print("Impossible")
############
elif a == b and len(scales) % 2 == 0:
for char in range(0, len(scales)... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for... | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhe... | 1,599,116,090 | 350 | PyPy 3 | OK | TESTS | 41 | 140 | 0 | a1=[0]*(26)
d=0
s = input()
k = int(input())
for i in s:
tmp=ord(i)-ord('a')
if a1[tmp]==0:
a1[tmp]=1
else:
d+=1
if sum(a1)>=k:
print(0)
elif sum(a1)+d<k:
print("impossible")
else:
print(k-sum(a1))
| Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it... | ```python
a1=[0]*(26)
d=0
s = input()
k = int(input())
for i in s:
tmp=ord(i)-ord('a')
if a1[tmp]==0:
a1[tmp]=1
else:
d+=1
if sum(a1)>=k:
print(0)
elif sum(a1)+d<k:
print("impossible")
else:
print(k-sum(a1))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,696,177,713 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 61 | 0 | n = input().split()
a = input().split()
count = 0
for i in range(len(n)):
n[i] = int(n[i])
for i in range(len(a)):
a[i] = int(a[i])
for i in a:
if i > n[1]:
count = count + 2
elif 1 <= n[1]:
count = count +1
print(count)
| 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 = input().split()
a = input().split()
count = 0
for i in range(len(n)):
n[i] = int(n[i])
for i in range(len(a)):
a[i] = int(a[i])
for i in a:
if i > n[1]:
count = count + 2
elif 1 <= n[1]:
count = count +1
print(count)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,696,948,611 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | i1 = int(input())
ihi = "I hate it "
ihiili = "I hate it i love it "
ihiiliihi = "I hate that I love that I hate it "
while i1 == 1:
print(ihi)
break
while i1 == 2:
print(ihiili)
break
while i1 == 3:
print(ihiiliihi)
break
while i1%2 == 0 and i1 != 2:
print(ihiili*i1)
brea... | 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
i1 = int(input())
ihi = "I hate it "
ihiili = "I hate it i love it "
ihiiliihi = "I hate that I love that I hate it "
while i1 == 1:
print(ihi)
break
while i1 == 2:
print(ihiili)
break
while i1 == 3:
print(ihiiliihi)
break
while i1%2 == 0 and i1 != 2:
print(ihiili*i1)... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,647,042,620 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n , x = [int(i) for i in input().split()]
p = x
c = 0
for i in range(n):
q = input()
if q[0] == '+':
p += int(q[2:])
if q[0] == '-':
if int(q[2:]) <= p:
p -= int(q[2:])
else:
c += 1
print(p , c) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
n , x = [int(i) for i in input().split()]
p = x
c = 0
for i in range(n):
q = input()
if q[0] == '+':
p += int(q[2:])
if q[0] == '-':
if int(q[2:]) <= p:
p -= int(q[2:])
else:
c += 1
print(p , c)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,601,898,445 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 248 | 512,000 | n,m=map(int,input().split())
a=list(map(int, input().split()))
b=[j for j in a]
maxi=0
mini=0
for i in range(n):
a.sort(reverse=True)
b.sort()
if a[-1]==0:
a=a[:-1]
if b[0]==0:
b=b[1:]
maxi+=a[0]
a[0]-=1
mini+=b[0]
b[0]-=1
print(maxi,mini)
| Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
n,m=map(int,input().split())
a=list(map(int, input().split()))
b=[j for j in a]
maxi=0
mini=0
for i in range(n):
a.sort(reverse=True)
b.sort()
if a[-1]==0:
a=a[:-1]
if b[0]==0:
b=b[1:]
maxi+=a[0]
a[0]-=1
mini+=b[0]
b[0]-=1
print(maxi,mini)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,692,911,710 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | lines = int(input())
uniforms = []
count = 0
for i in range(lines):
uniforms.append(list(map(int, input().split())))
for each1, each2 in uniforms:
for each, eache in uniforms:
if each1 == eache:
count += 1
print(count) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
lines = int(input())
uniforms = []
count = 0
for i in range(lines):
uniforms.append(list(map(int, input().split())))
for each1, each2 in uniforms:
for each, eache in uniforms:
if each1 == eache:
count += 1
print(count)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
... | The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k... | [
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] | [
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] | none | 0 | [
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "... | 1,483,696,413 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 4,608,000 | s = input()
t = input()
sol = []
for i in range(len(s)):
if s[i] != t[i]:
x = [s[i], t[i]]
x.sort()
if x not in sol:
sol += [x]
print(len(sol))
print('\n'.join([' '.join(i) for i in sol]))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, ... | ```python
s = input()
t = input()
sol = []
for i in range(len(s)):
if s[i] != t[i]:
x = [s[i], t[i]]
x.sort()
if x not in sol:
sol += [x]
print(len(sol))
print('\n'.join([' '.join(i) for i in sol]))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,694,944,980 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 8 | 154 | 2,764,800 | import math
maxn = 30
par = [0] * maxn
for i in range(2, maxn):
if par[i] == 0:
for j in range(i, maxn, i):
par[j] = i
n, ans = int(input()), 0
for i in range(2, n + 1):
counter = 0
for j in range(2, i + 1):
if i % j == 0 and par[j] == j:
counter += 1... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
import math
maxn = 30
par = [0] * maxn
for i in range(2, maxn):
if par[i] == 0:
for j in range(i, maxn, i):
par[j] = i
n, ans = int(input()), 0
for i in range(2, n + 1):
counter = 0
for j in range(2, i + 1):
if i % j == 0 and par[j] == j:
co... | -1 | MatrixStudio/Codeforces-Python-Submissions |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,699,543,520 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | p = int(input())
w = list(map(int, input().split()))
total= sum(w)
maxw= max(w)
mi = maxw* p - total
print(mi) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
p = int(input())
w = list(map(int, input().split()))
total= sum(w)
maxw= max(w)
mi = maxw* p - total
print(mi)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
91 | B | Queue | PROGRAMMING | 1,500 | [
"binary search",
"data structures"
] | B. Queue | 2 | 256 | There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*.
The *i*-th walrus becomes displeased if there's a younger... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of walruses in the queue. The second line contains integers *a**i* (1<=≤<=*a**i*<=≤<=109).
Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly youn... | Print *n* numbers: if the *i*-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the *i*-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | [
"6\n10 8 5 3 50 45\n",
"7\n10 4 6 3 2 8 15\n",
"5\n10 3 1 10 11\n"
] | [
"2 1 0 -1 0 -1 ",
"4 2 1 0 -1 -1 -1 ",
"1 0 -1 -1 -1 "
] | none | 1,000 | [
{
"input": "6\n10 8 5 3 50 45",
"output": "2 1 0 -1 0 -1 "
},
{
"input": "7\n10 4 6 3 2 8 15",
"output": "4 2 1 0 -1 -1 -1 "
},
{
"input": "5\n10 3 1 10 11",
"output": "1 0 -1 -1 -1 "
},
{
"input": "13\n18 9 8 9 23 20 18 18 33 25 31 37 36",
"output": "2 0 -1 -1 2 1 -1 -1 ... | 1,623,179,154 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 | from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = []
min_ = float("inf")
for i in range(n-1, -1, -1):
if a[i] < min_:
min_ = a[i]
b.append((a[i], i))
b.reverse()
ans = []
for i in range(n):
l = 0
r = len(b)
best_i... | Title: Queue
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus ... | ```python
from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = []
min_ = float("inf")
for i in range(n-1, -1, -1):
if a[i] < min_:
min_ = a[i]
b.append((a[i], i))
b.reverse()
ans = []
for i in range(n):
l = 0
r = len(b)
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
292 | B | Network Topology | PROGRAMMING | 1,200 | [
"graphs",
"implementation"
] | null | null | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them... | The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*... | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo... | [
"4 3\n1 2\n2 3\n3 4\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n"
] | [
"bus topology\n",
"ring topology\n",
"star topology\n",
"unknown topology\n"
] | none | 1,000 | [
{
"input": "4 3\n1 2\n2 3\n3 4",
"output": "bus topology"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "ring topology"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "star topology"
},
{
"input": "4 4\n1 2\n2 3\n3 1\n1 4",
"output": "unknown topology"
},
{
"i... | 1,588,279,712 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 1,746 | 7,884,800 | n, m = map(int, input().split())
A = [0]*n
for _ in range(m):
a, b = map(int, input().split())
A[a-1] += 1
A[b-1] += 1
x = set(A)
if x == {2}:
print("ring topology")
elif x == {1, 2}:
print("bus topology")
elif x == {1, m}:
print("star topology")
else:
print("unknown topology")... | Title: Network Topology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in... | ```python
n, m = map(int, input().split())
A = [0]*n
for _ in range(m):
a, b = map(int, input().split())
A[a-1] += 1
A[b-1] += 1
x = set(A)
if x == {2}:
print("ring topology")
elif x == {1, 2}:
print("bus topology")
elif x == {1, m}:
print("star topology")
else:
print("unknown ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh... | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"... | 1,503,596,139 | 3,639 | Python 3 | OK | TESTS | 55 | 77 | 0 | n,m = map(int,input().split())
row=[]
for i in range(n):
row.append(list(map(int,input().split())))
result =0
for r in range(n):
result+=((2**sum(row[r]))-1) + ((2**(m-sum(row[r])))-1)
for s in range(m):
summ=0
for g in range(n):
summ +=row[g][s]
result+=((2**summ)-1)+((2**(n-summ... | Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or ... | ```python
n,m = map(int,input().split())
row=[]
for i in range(n):
row.append(list(map(int,input().split())))
result =0
for r in range(n):
result+=((2**sum(row[r]))-1) + ((2**(m-sum(row[r])))-1)
for s in range(m):
summ=0
for g in range(n):
summ +=row[g][s]
result+=((2**summ)-1)+((... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl... | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "... | 1,607,460,553 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 156 | 0 | import math
x,y=map(int,input().split())
lx=math.log(x)
ly=math.log(y)
if lx*y>ly*x:
print(">")
elif lx*y<ly*x:
print("<")
else:
print("=") | Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out tha... | ```python
import math
x,y=map(int,input().split())
lx=math.log(x)
ly=math.log(y)
if lx*y>ly*x:
print(">")
elif lx*y<ly*x:
print("<")
else:
print("=")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,656,259,081 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 31 | 4,300,800 | n,m=list(map(int,input().split()))
if n>5 and n*m//5!=n*m/5:
summ=n*m//5
if summ%5>=3:
print(summ)
else:
print(summ+1)
else:
summ=(n*m)/5
print("%.0f"%summ)
| Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
n,m=list(map(int,input().split()))
if n>5 and n*m//5!=n*m/5:
summ=n*m//5
if summ%5>=3:
print(summ)
else:
print(summ+1)
else:
summ=(n*m)/5
print("%.0f"%summ)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,660,209,145 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res1 = 0
res2 = 0
for j in range(n):
res1 |= a[j]
res2 |= b[j]
print(res1 + res2)
| Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res1 = 0
res2 = 0
for j in range(n):
res1 |= a[j]
res2 |= b[j]
print(res1 + res2)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
4 | C | Registration System | PROGRAMMING | 1,300 | [
"data structures",
"hashing",
"implementation"
] | C. Registration system | 5 | 64 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | [
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] | [
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] | none | 0 | [
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
... | 1,688,022,882 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 5,000 | 7,475,200 | n = int(input()) # Read the number of requests
registered_names = {} # Dictionary to store registered names
# Process each request
for _ in range(n):
name = input() # Read the name from the request
if name in registered_names:
# Generate a new name if the requested name is already taken
... | Title: Registration System
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to imple... | ```python
n = int(input()) # Read the number of requests
registered_names = {} # Dictionary to store registered names
# Process each request
for _ in range(n):
name = input() # Read the name from the request
if name in registered_names:
# Generate a new name if the requested name is alrea... | 0 | MatrixStudio/Codeforces-Python-Submissions |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,510,507,866 | 5,166 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 2,000 | 11,571,200 | n=int(input())
s=input().split()
pam=[]
a=set()
for i in s:
if i not in a:
pam.append(i)
a.add(i)
else:
k=pam.index(i)
if k>=0:
pam.pop(k)
pam.append(i)
print(pam[0])
| Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
n=int(input())
s=input().split()
pam=[]
a=set()
for i in s:
if i not in a:
pam.append(i)
a.add(i)
else:
k=pam.index(i)
if k>=0:
pam.pop(k)
pam.append(i)
print(pam[0])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
205 | B | Little Elephant and Sorting | PROGRAMMING | 1,400 | [
"brute force",
"greedy"
] | null | null | The Little Elephant loves sortings.
He has an array *a* consisting of *n* integers. Let's number the array elements from 1 to *n*, then the *i*-th element will be denoted as *a**i*. The Little Elephant can make one move to choose an arbitrary pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) and increase *a**i*... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* integers, separated by single spaces — array *a* (1<=≤<=*a**i*<=≤<=109). The array elements are listed in the line in the order of their index's increasing. | In a single line print a single integer — the answer to the problem.
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. | [
"3\n1 2 3\n",
"3\n3 2 1\n",
"4\n7 4 1 47\n"
] | [
"0\n",
"2\n",
"6\n"
] | In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.
In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).
In ... | 1,000 | [
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "4\n7 4 1 47",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 1000000000",
"output": "0"
},
{
"input": "10\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 100000000... | 1,581,623,177 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | n=int(input())
a=list(map(int,input().split()))
c=a.index(max(a))
d=[0]
if(c==n-1):
for i in range(n-2):
if(a[i]>a[i+1]):
d.append(a[i]-a[i+1])
a[i+1]=a[i]
else:
for i in range(n-1):
if(a[i]>a[i+1]):
d.append(a[i]-a[i+1])
a[i+1]=a[i]
... | Title: Little Elephant and Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves sortings.
He has an array *a* consisting of *n* integers. Let's number the array elements from 1 to *n*, then the *i*-th element will be denoted as *a**i*. The Little Elephant can ... | ```python
n=int(input())
a=list(map(int,input().split()))
c=a.index(max(a))
d=[0]
if(c==n-1):
for i in range(n-2):
if(a[i]>a[i+1]):
d.append(a[i]-a[i+1])
a[i+1]=a[i]
else:
for i in range(n-1):
if(a[i]>a[i+1]):
d.append(a[i]-a[i+1])
a[i... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,613,278,988 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | s=str(input())
t='hello'
j=0
flag=0
for i in range(len(s)):
if t[j]==s[i]:
j+=1
if j==len(t):
flag=1
break
if flag==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
s=str(input())
t='hello'
j=0
flag=0
for i in range(len(s)):
if t[j]==s[i]:
j+=1
if j==len(t):
flag=1
break
if flag==1:
print('YES')
else:
print("NO")
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,695,737,899 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | aa=input()+input()
cc=input()
if len(aa)!=len(cc):
print("NO")
else:
for i in aa:
if i in cc:
ind=cc.index(i)
cc=cc[:ind]+cc[ind+1:]
else:
break
if len(cc)==0:
print("YES")
else:
print("NO") | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
aa=input()+input()
cc=input()
if len(aa)!=len(cc):
print("NO")
else:
for i in aa:
if i in cc:
ind=cc.index(i)
cc=cc[:ind]+cc[ind+1:]
else:
break
if len(cc)==0:
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
916 | B | Jamie and Binary Sequence (changed after round) | PROGRAMMING | 2,000 | [
"bitmasks",
"greedy",
"math"
] | null | null | Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. ... | The first line consists of two integers *n* and *k* (1<=≤<=*n*<=≤<=1018,<=1<=≤<=*k*<=≤<=105) — the required sum and the length of the sequence. | Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and *k* numbers separated by space in the second line — the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [<=-<=1018,<=1018]. | [
"23 5\n",
"13 2\n",
"1 2\n"
] | [
"Yes\n3 3 2 1 0 \n",
"No\n",
"Yes\n-1 -1 \n"
] | Sample 1:
2<sup class="upper-index">3</sup> + 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">2</sup> + 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">0</sup> = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1... | 1,000 | [
{
"input": "23 5",
"output": "Yes\n3 3 2 1 0 "
},
{
"input": "13 2",
"output": "No"
},
{
"input": "1 2",
"output": "Yes\n-1 -1 "
},
{
"input": "1 1",
"output": "Yes\n0 "
},
{
"input": "1000000000000000000 100000",
"output": "Yes\n44 44 44 44 44 44 44 44 44 44 ... | 1,516,396,617 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 31,948,800 | from collections import Counter
n, m = [int(x) for x in input().split()]
BITS = 62
def binary(x):
return [bit for bit in range(BITS + 1) if (x & (1 << bit)) > 0]
def panic():
print('No')
exit()
def update(a, m):
counter = Counter(a)
for i in reversed(range(-10 ** 5, BITS + 1)):
if cou... | Title: Jamie and Binary Sequence (changed after round)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find *k* integers such tha... | ```python
from collections import Counter
n, m = [int(x) for x in input().split()]
BITS = 62
def binary(x):
return [bit for bit in range(BITS + 1) if (x & (1 << bit)) > 0]
def panic():
print('No')
exit()
def update(a, m):
counter = Counter(a)
for i in reversed(range(-10 ** 5, BITS + 1)):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,587,388,426 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 307,200 | s = input()
n = len(s)
m = int(input())
arr = list(map(int,input().split()))
arr.sort()
d = {}
d[arr[0]] = 1
for i in range(1,m):
if(arr[i] not in d):
d[arr[i]] = i+1
else:
d[arr[i]]+=1
print(d)
s =list(s)
for k,v in d.items():
if(v%2==1):
s[k-1],s[n-k] = s[n-k],s[k-1]
print(''.join(... | Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
s = input()
n = len(s)
m = int(input())
arr = list(map(int,input().split()))
arr.sort()
d = {}
d[arr[0]] = 1
for i in range(1,m):
if(arr[i] not in d):
d[arr[i]] = i+1
else:
d[arr[i]]+=1
print(d)
s =list(s)
for k,v in d.items():
if(v%2==1):
s[k-1],s[n-k] = s[n-k],s[k-1]
prin... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
803 | C | Maximal GCD | PROGRAMMING | 1,900 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010). | If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them. | [
"6 3\n",
"8 2\n",
"5 3\n"
] | [
"1 2 3\n",
"2 6\n",
"-1\n"
] | none | 0 | [
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 10000000... | 1,676,402,637 | 4,317 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | import sys
n, k = map(int, input().split())
min_sum = (1 + k) * k // 2
if min_sum > n:
print(-1)
sys.exit()
answer = 1
gcd = 1
while gcd * gcd <= n:
if n % gcd == 0:
sequence_sum = n / gcd
if min_sum <= sequence_sum:
answer = max(answer, gcd)
gcd, seque... | Title: Maximal GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Grea... | ```python
import sys
n, k = map(int, input().split())
min_sum = (1 + k) * k // 2
if min_sum > n:
print(-1)
sys.exit()
answer = 1
gcd = 1
while gcd * gcd <= n:
if n % gcd == 0:
sequence_sum = n / gcd
if min_sum <= sequence_sum:
answer = max(answer, gcd)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
298 | A | Snow Footprints | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000).
The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's gu... | Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. | [
"9\n..RRLL...\n",
"11\n.RRRLLLLL..\n"
] | [
"3 4\n",
"7 5\n"
] | The first test sample is the one in the picture. | 500 | [
{
"input": "11\n.RRRLLLLL..",
"output": "7 5"
},
{
"input": "4\n.RL.",
"output": "3 2"
},
{
"input": "3\n.L.",
"output": "2 1"
},
{
"input": "3\n.R.",
"output": "2 3"
}
] | 1,648,556,931 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | def solve() :
l=x.count('L')
r=x.count('R')
if l==0:
return f"{x.find('R')+1} {n-x[::-1].find('R')}"
elif r==0:
return f"{x.find('L')+1} {n-x[::-1].find('L')}"
return f"{x.find('R')+1} {x.find('L')}"
from sys import stdin
input = stdin.readline
... | Title: Snow Footprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *... | ```python
def solve() :
l=x.count('L')
r=x.count('R')
if l==0:
return f"{x.find('R')+1} {n-x[::-1].find('R')}"
elif r==0:
return f"{x.find('L')+1} {n-x[::-1].find('L')}"
return f"{x.find('R')+1} {x.find('L')}"
from sys import stdin
input = stdin.readline ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,599,039,511 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 218 | 307,200 | n = int(input())
a = list(map(int, input().split()))
chest = sum(a[0::3])
biceps = sum(a[1::3])
back = sum(a[2::3])
if chest == max(chest, biceps, back):
i = 0
elif biceps == max(chest, biceps, back):
i = 1
else:
i = 2
print(['chest','biceps','back'][i]) | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
a = list(map(int, input().split()))
chest = sum(a[0::3])
biceps = sum(a[1::3])
back = sum(a[2::3])
if chest == max(chest, biceps, back):
i = 0
elif biceps == max(chest, biceps, back):
i = 1
else:
i = 2
print(['chest','biceps','back'][i])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,690,482,649 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | x=''
c=1
l=[]
n=int(input())
if(n==2):
print(2)
else:
for i in range(n):
s=str(input())
if(i==0):
x+=s
else:
if(x[-2:]==s):
c+=1
x+=s
else:
l.append(c)
c=1
... | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
x=''
c=1
l=[]
n=int(input())
if(n==2):
print(2)
else:
for i in range(n):
s=str(input())
if(i==0):
x+=s
else:
if(x[-2:]==s):
c+=1
x+=s
else:
l.append(c)
c=1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,462,196,375 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | n, m = map(int, input().split())
res = []
for i in range(4*n):
v = 2*n*((i+1+(i+1)*(i==(m-1)))%2) + 1 + i//2
if(v <= m):
res.append(v)
print(' '.join(map(str, res)))
| 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
n, m = map(int, input().split())
res = []
for i in range(4*n):
v = 2*n*((i+1+(i+1)*(i==(m-1)))%2) + 1 + i//2
if(v <= m):
res.append(v)
print(' '.join(map(str, res)))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,063,837 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | string = str(input())
new_string = string.split("WUB")
ans = ""
for i in new_string:
if i == '':
continue
else:
ans += (i+" ")
print(ans) | 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
string = str(input())
new_string = string.split("WUB")
ans = ""
for i in new_string:
if i == '':
continue
else:
ans += (i+" ")
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,678,979,093 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <map>
using namespace std;
typedef unsigned long long ll;
typedef double num;
vector<vector<int>> tree;
vector<int> d;
/*int dfs(int v, in... | Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000.... | ```python
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <map>
using namespace std;
typedef unsigned long long ll;
typedef double num;
vector<vector<int>> tree;
vector<int> d;
/*int dfs... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ... | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "... | 1,517,532,663 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 5,632,000 | n = input()
n = list(n)
i = 0
while i < len(n):
while n[i] in ['/']:
i += 1
if i == len(n) or (i < len(n) and n[i] not in ['/']):
print("/", end="")
if i == len(n):
break
if i == len(n):
break
print(n[i], end="")
i += 1
| Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n... | ```python
n = input()
n = list(n)
i = 0
while i < len(n):
while n[i] in ['/']:
i += 1
if i == len(n) or (i < len(n) and n[i] not in ['/']):
print("/", end="")
if i == len(n):
break
if i == len(n):
break
print(n[i], end="")
i +=... | 0 | MatrixStudio/Codeforces-Python-Submissions |
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid show... | The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov... | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
... | 1,690,453,023 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 23 | 46 | 0 |
mas=[]
n,m=map(int,input().split())
if(n*m)%2==0 and (n*m)!=2 and (n*m)!=1750:
mas.append('Malvika')
else:
mas.append('Akshat')
print(*mas) | Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid... | ```python
mas=[]
n,m=map(int,input().split())
if(n*m)%2==0 and (n*m)!=2 and (n*m)!=1750:
mas.append('Malvika')
else:
mas.append('Akshat')
print(*mas)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,524,825,571 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 109 | 21,708,800 | n, k, m, d = map(int, input().split())
maxr = 0
for i in range(1, d+1):
peeps = k*(i-1) + 1
t = n//peeps
if t <= m:
maxr = max(maxr, t*i)
continue
sec = k*i
t2 = n//sec
if(t2 > m):
continue
r = n//m
# cyc = (r%k == 0 ? r//k : r//k + 1)
if(r%k == 0):
cyc = r//k
else:
cyc = r//k + 1
... | Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
n, k, m, d = map(int, input().split())
maxr = 0
for i in range(1, d+1):
peeps = k*(i-1) + 1
t = n//peeps
if t <= m:
maxr = max(maxr, t*i)
continue
sec = k*i
t2 = n//sec
if(t2 > m):
continue
r = n//m
# cyc = (r%k == 0 ? r//k : r//k + 1)
if(r%k == 0):
cyc = r//k
else:
cyc = ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
63 | B | Settlers' Training | PROGRAMMING | 1,200 | [
"implementation"
] | B. Settlers' Training | 2 | 256 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either i... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains *n* numbers in the non-decreasing order. The *i*-th of them, *a**i*, represents the rank of the *i*-th soldier in the defense buil... | Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank. | [
"4 4\n1 2 2 3\n",
"4 3\n1 1 1 1\n"
] | [
"4",
"5"
] | In the first example the ranks will be raised in the following manner:
1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins. | 1,000 | [
{
"input": "4 4\n1 2 2 3",
"output": "4"
},
{
"input": "4 3\n1 1 1 1",
"output": "5"
},
{
"input": "3 3\n1 2 3",
"output": "2"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 5\n1",
"output": "4"
},
{
"input": "1 5\n4",
"output": "1"
},
... | 1,597,775,538 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 280 | 1,433,600 | n,k=map(int,input().split())
L=list(map(int,input().split()))
L.reverse()
coins=0
var=-1
change=0
while(True):
for i in range(n):
if(L[i]<k and L[i]!=var):
change+=1
var=L[i]
L[i]+=1
if(change>0):
coins+=1
var=-1
change=0
el... | Title: Settlers' Training
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers... | ```python
n,k=map(int,input().split())
L=list(map(int,input().split()))
L.reverse()
coins=0
var=-1
change=0
while(True):
for i in range(n):
if(L[i]<k and L[i]!=var):
change+=1
var=L[i]
L[i]+=1
if(change>0):
coins+=1
var=-1
change... | 3.92733 | MatrixStudio/Codeforces-Python-Submissions |
36 | A | Extra-terrestrial Intelligence | PROGRAMMING | 1,300 | [
"implementation"
] | A. Extra-terrestrial Intelligence | 2 | 64 | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | [
"8\n00111000\n",
"7\n1001011\n",
"7\n1010100\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "8\n00111000",
"output": "YES"
},
{
"input": "7\n1001011",
"output": "NO"
},
{
"input": "7\n1010100",
"output": "YES"
},
{
"input": "5\n10101",
"output": "YES"
},
{
"input": "3\n111",
"output": "YES"
},
{
"input": "10\n0011111011",
"outp... | 1,685,692,296 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 122 | 2,867,200 |
n=int(input())
s=input()
e,m=-1,-1
k=True
for i in range(n):
if e==-1 and s[i]=='1':
e=i
elif m==-1 and s[i]=='1':
m=i
elif s[i]=='1' and m-e!=i-m:
k=False
if k:
print("YES")
else:
print("NO")
| Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* da... | ```python
n=int(input())
s=input()
e,m=-1,-1
k=True
for i in range(n):
if e==-1 and s[i]=='1':
e=i
elif m==-1 and s[i]=='1':
m=i
elif s[i]=='1' and m-e!=i-m:
k=False
if k:
print("YES")
else:
print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
0 | none | none | none | 0 | [
"none"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 0 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,505,661,249 | 7,749 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 3 | 1,000 | 4,505,600 | import sys
def krounding(n,k):
c = 1
while True:
val = (c*(pow(10,k))) % n
if val == 0:
return c*(pow(10,k))
c+=1
def main():
(n,k) = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
print(krounding(n,k))
if __name__ == '__main__':
main()
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000... | ```python
import sys
def krounding(n,k):
c = 1
while True:
val = (c*(pow(10,k))) % n
if val == 0:
return c*(pow(10,k))
c+=1
def main():
(n,k) = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
print(krounding(n,k))
if __name__ == '__main__':
main()
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,690,280,716 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 62 | 0 | def distinct_characters(s):
return len(set(s.replace("{", "").replace("}", "").replace(",", "").replace(" ", "")))
s = input()
result = distinct_characters(s)
print(result)
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
def distinct_characters(s):
return len(set(s.replace("{", "").replace("}", "").replace(",", "").replace(" ", "")))
s = input()
result = distinct_characters(s)
print(result)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Arkady decides to observe a river for *n* consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of days.
The second line contains *n* space-separated integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=<<=*i*) — the number of marks strictly above the water on each day. | Output one single integer — the minimum possible sum of the number of marks strictly below the water level among all days. | [
"6\n0 1 0 3 0 2\n",
"5\n0 1 2 1 2\n",
"5\n0 1 1 2 2\n"
] | [
"6\n",
"1\n",
"0\n"
] | In the first example, the following figure shows an optimal case.
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case. | 0 | [
{
"input": "6\n0 1 0 3 0 2",
"output": "6"
},
{
"input": "5\n0 1 2 1 2",
"output": "1"
},
{
"input": "5\n0 1 1 2 2",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "100\n0 1 2 2 3 0 1 5 6 6 0 0 8 7 1 9 9 4 10 11 12 2 12 12 12 12 9 13 14 8 15 15 15... | 1,521,911,311 | 5,611 | Python 3 | OK | TESTS | 42 | 264 | 14,438,400 | N = int(input())
above = list(map(int, input().split()))
if N == 1:
print(0)
quit()
required_mark = [0] * N
required_mark[N-2] = above[N-1]
for i in reversed(range(N-2)):
required_mark[i] = max(above[i+1], required_mark[i+1] - 1)
d = 0
mark = 1
for i in range(1, N):
if mark == above[i]... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady decides to observe a river for *n* consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the w... | ```python
N = int(input())
above = list(map(int, input().split()))
if N == 1:
print(0)
quit()
required_mark = [0] * N
required_mark[N-2] = above[N-1]
for i in reversed(range(N-2)):
required_mark[i] = max(above[i+1], required_mark[i+1] - 1)
d = 0
mark = 1
for i in range(1, N):
if mark =... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,676,115,284 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 404 | 7,372,800 | # filename = "input.txt"
# f = open(filename, "r")
# input_lines = f.read().split("\n")
# amount, time = list(map(int, input_lines[0].strip().split(" ")))
# books = list(map(int, input_lines[1].strip().split(" ")))
amount, time = list(map(int, input().strip().split(" ")))
books = list(map(int, input().strip().s... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
# filename = "input.txt"
# f = open(filename, "r")
# input_lines = f.read().split("\n")
# amount, time = list(map(int, input_lines[0].strip().split(" ")))
# books = list(map(int, input_lines[1].strip().split(" ")))
amount, time = list(map(int, input().strip().split(" ")))
books = list(map(int, input()... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,648,980,054 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 102,400 | n = int(input())
s = input()
d = {}
for i in range(n):
if s[i] not in d:
d[s[i]] = 1
else:
d[s[i]] += 1
c = 0
for i,j in d.items():
if j == 1:
pass
else:
c += (j - 1)
print(c) | Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
n = int(input())
s = input()
d = {}
for i in range(n):
if s[i] not in d:
d[s[i]] = 1
else:
d[s[i]] += 1
c = 0
for i,j in d.items():
if j == 1:
pass
else:
c += (j - 1)
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,627,301,361 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 61 | 6,758,400 | d1,d2,d3 = list( map(int,input().split()) )
print(min([(d1*2)+(d2*2),(d1*2)+(d3*2),(d2*2)+(d3*2),(d1+d2+d3)])) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3 = list( map(int,input().split()) )
print(min([(d1*2)+(d2*2),(d1*2)+(d3*2),(d2*2)+(d3*2),(d1+d2+d3)]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,510,227 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 77 | 0 | #yousef
n,m,a,b=map(int, input().split())
c=(n//m)*b
d=n*a
w=n%m
print(min(d,c)+min((w*a,b))) | 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
#yousef
n,m,a,b=map(int, input().split())
c=(n//m)*b
d=n*a
w=n%m
print(min(d,c)+min((w*a,b)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
650 | B | Image Preview | PROGRAMMING | 1,900 | [
"binary search",
"brute force",
"dp",
"two pointers"
] | null | null | Vasya's telephone contains *n* photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo *n*. Similarly, by swiping right from the last photo you reach photo 1. It takes *... | The first line of the input contains 4 integers *n*,<=*a*,<=*b*,<=*T* (1<=≤<=*n*<=≤<=5·105, 1<=≤<=*a*,<=*b*<=≤<=1000, 1<=≤<=*T*<=≤<=109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo.
Second line of the input contains a ... | Output the only integer, the maximum number of photos Vasya is able to watch during those *T* seconds. | [
"4 2 3 10\nwwhw\n",
"5 2 4 13\nhhwhh\n",
"5 2 4 1000\nhhwhh\n",
"3 1 100 10\nwhw\n"
] | [
"2\n",
"4\n",
"5\n",
"0\n"
] | In the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds.
Note that in the last sample test the time is not enough even to watch the first phot... | 1,000 | [
{
"input": "4 2 3 10\nwwhw",
"output": "2"
},
{
"input": "5 2 4 13\nhhwhh",
"output": "4"
},
{
"input": "5 2 4 1000\nhhwhh",
"output": "5"
},
{
"input": "3 1 100 10\nwhw",
"output": "0"
},
{
"input": "10 2 3 32\nhhwwhwhwwh",
"output": "7"
},
{
"input":... | 1,458,411,056 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 5,120,000 | A = list(map(int,input().split()))
n = A[0]
a = A[1]
b = A[2]
T = A[3]
task = input()
time = 0
count_a = 0 #просмотренные фотографии
count_b = 0
# время потраченное на первый просмотр
for ch in task:
if ch == 'w':
time += b
if time > T:
flag = False
break
count_... | Title: Image Preview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's telephone contains *n* photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo,... | ```python
A = list(map(int,input().split()))
n = A[0]
a = A[1]
b = A[2]
T = A[3]
task = input()
time = 0
count_a = 0 #просмотренные фотографии
count_b = 0
# время потраченное на первый просмотр
for ch in task:
if ch == 'w':
time += b
if time > T:
flag = False
break
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,654,452,513 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | s = list(input())
x = max(s)
print(x*s.count(x)) | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
s = list(input())
x = max(s)
print(x*s.count(x))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,698,977,950 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 154 | 0 | a = str(input())
b = a.split("WUB")
arr = []
for x in b:
if x == "":
continue
else:
arr.append(x)
c = ' '.join(arr)
print(c) | 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
a = str(input())
b = a.split("WUB")
arr = []
for x in b:
if x == "":
continue
else:
arr.append(x)
c = ' '.join(arr)
print(c)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | There are *n* animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number *i* in the queue will have to visit... | The first line of input data contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=1014). In the second line are given space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommen... | If the doctor will overall carry out less than *k* examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing o... | [
"3 3\n1 2 1\n",
"4 10\n3 3 2 1\n",
"7 10\n1 3 3 1 2 3 1\n"
] | [
"2 ",
"-1\n",
"6 2 3 "
] | In the first sample test:
- Before examination: {1, 2, 3} - After the first examination: {2, 3} - After the second examination: {3, 2} - After the third examination: {2}
In the second sample test:
- Before examination: {1, 2, 3, 4, 5, 6, 7} - After the first examination: {2, 3, 4, 5, 6, 7} - After the second ... | 0 | [
{
"input": "3 3\n1 2 1",
"output": "2 "
},
{
"input": "4 10\n3 3 2 1",
"output": "-1"
},
{
"input": "7 10\n1 3 3 1 2 3 1",
"output": "6 2 3 "
},
{
"input": "1 0\n1",
"output": "1 "
},
{
"input": "6 101\n9 78 54 62 2 91",
"output": "4 6 2 3 "
},
{
"inpu... | 1,518,317,191 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 5,632,000 | n,k=map(int,input().strip().split(' '))
L=list(map(int,input().split(' ')))
s=sum(L)
if k>s:
print(-1)
else:
i=0
j=0
while i<k:
if L[j]!=0:
i=i+1
L[j]-=1
j=(j+1)%n
for i in range(n):
if L[(i+j)%n]!=0:
print((i+j+1)%n,end=' ')
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly w... | ```python
n,k=map(int,input().strip().split(' '))
L=list(map(int,input().split(' ')))
s=sum(L)
if k>s:
print(-1)
else:
i=0
j=0
while i<k:
if L[j]!=0:
i=i+1
L[j]-=1
j=(j+1)%n
for i in range(n):
if L[(i+j)%n]!=0:
print((i+j+1)%n,end=' ')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,604,469,665 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | str=list(input())
secstr=input()
for i in range(len(str)//2):
temp=str[i]
str[i]=str[len(str)-1-i]
str[len(str)-1-i]=temp
istr="".join(str)
if istr==secstr:
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
str=list(input())
secstr=input()
for i in range(len(str)//2):
temp=str[i]
str[i]=str[len(str)-1-i]
str[len(str)-1-i]=temp
istr="".join(str)
if istr==secstr:
print("YES")
else:
print("NO")
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
605 | A | Sorting Railway Cars | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and telepor... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train.
The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. | Print a single integer — the minimum number of actions needed to sort the railway cars. | [
"5\n4 1 2 5 3\n",
"4\n4 1 3 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train. | 500 | [
{
"input": "5\n4 1 2 5 3",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "6\n5 3 6 1 4 2",
"output": "4"
},
... | 1,477,426,280 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | n = input()
arr = list(map(int, input().split()))
def min(a, b):
if a < b:
return a
else: return b
count = 0
for i in range(1, len(arr)):
if arr[i] < arr[i - 1]:
count += 1
print(count) | Title: Sorting Railway Cars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the... | ```python
n = input()
arr = list(map(int, input().split()))
def min(a, b):
if a < b:
return a
else: return b
count = 0
for i in range(1, len(arr)):
if arr[i] < arr[i - 1]:
count += 1
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
33 | A | What is for dinner? | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | A. What is for dinner? | 2 | 256 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where bel... | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | [
"4 3 18\n2 3\n1 2\n3 6\n2 3\n",
"2 2 13\n1 13\n2 12\n"
] | [
"11\n",
"13\n"
] | none | 500 | [
{
"input": "4 3 18\n2 3\n1 2\n3 6\n2 3",
"output": "11"
},
{
"input": "2 2 13\n1 13\n2 12",
"output": "13"
},
{
"input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3",
"output": "8"
},
{
"input": "1 1 0\n1 3",
"output": "0"
},
{
"input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 1... | 1,620,830,731 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 6,656,000 | n,k=map(int,input().split())
a = list(map(int,input().split()))
i=0
answer=23454
def no(a):
a.sort()
return a[-1]-a[0]
while(i<k-1):
ans=no(a[i:i+n+1])
answer = min(ans,answer)
i+=1
print(answer)
| Title: What is for dinner?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that... | ```python
n,k=map(int,input().split())
a = list(map(int,input().split()))
i=0
answer=23454
def no(a):
a.sort()
return a[-1]-a[0]
while(i<k-1):
ans=no(a[i:i+n+1])
answer = min(ans,answer)
i+=1
print(answer)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
679 | A | Bear and Prime 100 | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two d... | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu... | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hi... | 750 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
... | 1,588,781,213 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 20,172,800 | from sys import stdout
f = False
c = False
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
for p in prime:
print(p)
stdout.flush()
if input() == 'yes':
if not f:
f = True
elif f:
c = True
break
print('composite' if c else ... | Title: Bear and Prime 100
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say i... | ```python
from sys import stdout
f = False
c = False
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
for p in prime:
print(p)
stdout.flush()
if input() == 'yes':
if not f:
f = True
elif f:
c = True
break
print('composite' ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 0 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,517,222,479 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 62 | 5,632,000 | #http://codeforces.com/contest/876/problem/C
def calc(x):
res = x
while (x):
res += x % 10
x = int(x / 10)
return res
if __name__ == '__main__':
n = int(input())
ans = []
if (n >= 81):
for i in range(n-81, n):
if (calc(i) == n):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova th... | ```python
#http://codeforces.com/contest/876/problem/C
def calc(x):
res = x
while (x):
res += x % 10
x = int(x / 10)
return res
if __name__ == '__main__':
n = int(input())
ans = []
if (n >= 81):
for i in range(n-81, n):
if (calc(i) == n):
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,677,248,614 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | N,X=list(map(int,input().split()))
TRISTES=0
for K in range(N):
Cad=input()
Num=int(Cad[2:len(Cad)])
if(Cad[0]=="+"):
X=X+Num
else:
if(Num<=X):
X=X-Num
else:
TRISTES+=1
print(X,TRISTES)
| Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
N,X=list(map(int,input().split()))
TRISTES=0
for K in range(N):
Cad=input()
Num=int(Cad[2:len(Cad)])
if(Cad[0]=="+"):
X=X+Num
else:
if(Num<=X):
X=X-Num
else:
TRISTES+=1
print(X,TRISTES)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
946 | D | Timetable | PROGRAMMING | 1,800 | [
"dp"
] | null | null | Ivan is a student at Berland State University (BSU). There are *n* days in Berland week, and each of these days Ivan might have some classes at the university.
There are *m* working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during *i*... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=≤<=500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then *n* lines follow, *i*-th line containing a binary string of *m* charact... | Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than *k* lessons. | [
"2 5 1\n01001\n10110\n",
"2 5 0\n01001\n10110\n"
] | [
"5\n",
"8\n"
] | In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | 0 | [
{
"input": "2 5 1\n01001\n10110",
"output": "5"
},
{
"input": "2 5 0\n01001\n10110",
"output": "8"
},
{
"input": "3 4 0\n0000\n0000\n0000",
"output": "0"
},
{
"input": "3 4 12\n1111\n1111\n1111",
"output": "0"
},
{
"input": "3 4 6\n1111\n1111\n1111",
"output":... | 1,545,082,892 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | def into(a, b):
return a + b | Title: Timetable
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan is a student at Berland State University (BSU). There are *n* days in Berland week, and each of these days Ivan might have some classes at the university.
There are *m* working hours during each Berland day, and each le... | ```python
def into(a, b):
return a + b
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,681,543,493 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 57 | 140 | 13,107,200 | import sys
input = sys.stdin.readline
def solve():
n = int(input())
a = [int(input()) for _ in range(n)]
first, second = [], []
for x in a:
if x > 0:
first.append(x)
else:
second.append(-x)
f, s = sum(first), sum(second)
r... | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
import sys
input = sys.stdin.readline
def solve():
n = int(input())
a = [int(input()) for _ in range(n)]
first, second = [], []
for x in a:
if x > 0:
first.append(x)
else:
second.append(-x)
f, s = sum(first), sum(second)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,678,028,973 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n = map(int,input().split())
t = m*n
print(t//2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n = map(int,input().split())
t = m*n
print(t//2)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,690,561,131 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 156 | 0 | import sys
sys.setrecursionlimit(100000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x))
# from random import randint
# from copy import deepcopy
# from collections import deque
# from heapq import heapify,heappush,heappop
# from bisect import bisect_left,bisect,insort
# ... | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
import sys
sys.setrecursionlimit(100000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x))
# from random import randint
# from copy import deepcopy
# from collections import deque
# from heapq import heapify,heappush,heappop
# from bisect import bisect_left,bisect,... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
84 | A | Toy Army | PROGRAMMING | 900 | [
"math",
"number theory"
] | A. Toy Army | 2 | 256 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe... | The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. | Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. | [
"2\n",
"4\n"
] | [
"3\n",
"6\n"
] | The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | 500 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "6"
},
{
"input": "6",
"output": "9"
},
{
"input": "8",
"output": "12"
},
{
"input": "10",
"output": "15"
},
{
"input": "140",
"output": "210"
},
{
"input": "500",
"output": "75... | 1,658,683,959 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 92 | 0 | """
OOOO
OOOO
"""
n = int(input())
shot_n = 0
shot_n += n // 2 * 2
n -= n // 2
shot_n += n
print(shot_n)
| Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on t... | ```python
"""
OOOO
OOOO
"""
n = int(input())
shot_n = 0
shot_n += n // 2 * 2
n -= n // 2
shot_n += n
print(shot_n)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
23 | A | You're Given a String... | PROGRAMMING | 1,200 | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number — length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | 0 | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggg... | 1,698,317,931 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 154 | 3,891,200 | def II():
return(int(input()))
def LMI():
return(list(map(int,input().split())))
def I():
return(input())
def MII():
return(map(int,input().split()))
# import sys
# input=sys.stdin.readline
# import io,os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# from collections import... | Title: You're Given a String...
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input Sp... | ```python
def II():
return(int(input()))
def LMI():
return(list(map(int,input().split())))
def I():
return(input())
def MII():
return(map(int,input().split()))
# import sys
# input=sys.stdin.readline
# import io,os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# from collecti... | 3.954252 | MatrixStudio/Codeforces-Python-Submissions |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,537,980,073 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 218 | 0 | lectura=input()
lista=list(lectura)
test3= ""
test1=[]
test2=""
for i in range(0,len(lista)):
test2+=lista[i]
#print(test2)
x = lectura.rfind(test2)
#print(x)
if(x!=0):
test3=x
conclusion=""
for i in range(test3, len(lista)):
conclusion+=lista[i]
if(lectura.find(conclusion... | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
lectura=input()
lista=list(lectura)
test3= ""
test1=[]
test2=""
for i in range(0,len(lista)):
test2+=lista[i]
#print(test2)
x = lectura.rfind(test2)
#print(x)
if(x!=0):
test3=x
conclusion=""
for i in range(test3, len(lista)):
conclusion+=lista[i]
if(lectura.find(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,645,873,243 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 1,126,400 | s=input()
t=input()
n=0
if len(s)>len(t):
S=s[len(s)-len(t):]
l=len(s)-len(t)
for i in range(len(S)):
if S[i]!=t[i]:
n=n+2
else:
T=t[len(t)-len(s):]
l=len(t)-len(s)
for j in range(len(T)):
if T[j]!=s[j]:
n=n+2
print(n+l) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s=input()
t=input()
n=0
if len(s)>len(t):
S=s[len(s)-len(t):]
l=len(s)-len(t)
for i in range(len(S)):
if S[i]!=t[i]:
n=n+2
else:
T=t[len(t)-len(s):]
l=len(t)-len(s)
for j in range(len(T)):
if T[j]!=s[j]:
n=n+2
print(n+l)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,646,580,038 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 716,800 | def func(ans):
if (len(ans) % 2) == 1:
return ans
return min(func(ans[:len(ans) // 2]) + func(ans[len(ans) // 2:]), func(ans[len(ans) // 2:]) + func(ans[:len(ans) // 2]))
if func(input()) == func(input()):
print("YES")
else:
print("NO") | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def func(ans):
if (len(ans) % 2) == 1:
return ans
return min(func(ans[:len(ans) // 2]) + func(ans[len(ans) // 2:]), func(ans[len(ans) // 2:]) + func(ans[:len(ans) // 2]))
if func(input()) == func(input()):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
23 | A | You're Given a String... | PROGRAMMING | 1,200 | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number — length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | 0 | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggg... | 1,628,444,195 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 6,758,400 | stroka = str(input())
kol = 0
bol = 0
for p in stroka:
if kol >= bol:
bol = kol
kol = 0
for j in stroka:
if p == j:
kol += 1
if bol > 1:
print(bol)
else:
print(0) | Title: You're Given a String...
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input Sp... | ```python
stroka = str(input())
kol = 0
bol = 0
for p in stroka:
if kol >= bol:
bol = kol
kol = 0
for j in stroka:
if p == j:
kol += 1
if bol > 1:
print(bol)
else:
print(0)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,638,618,910 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 |
n, d=map(int, input().split())
ar=list(map(int, input().split()))
s=sum(ar)
t=s+(10*(n-1))
if t>d:
print(-1)
else:
x=(n-1)*2
if t==d:
print(x)
else:
print(((d-t)//5)+x) | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
n, d=map(int, input().split())
ar=list(map(int, input().split()))
s=sum(ar)
t=s+(10*(n-1))
if t>d:
print(-1)
else:
x=(n-1)*2
if t==d:
print(x)
else:
print(((d-t)//5)+x)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,595,879,695 | 2,147,483,647 | PyPy 3 | OK | TESTS | 70 | 310 | 22,016,000 | from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
g = {}
for _ in range(m):
a, b = map(int, stdin.readline().split())
if a in g:
g[a].append(b)
else:
g[a] = [b]
if b in g:
g[b].append(a)
else:
g[b] = [a]
r = 0
wh... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
g = {}
for _ in range(m):
a, b = map(int, stdin.readline().split())
if a in g:
g[a].append(b)
else:
g[a] = [b]
if b in g:
g[b].append(a)
else:
g[b] = [a]
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
242 | C | King's Path | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contai... | If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one. | [
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n"
] | [
"4\n",
"6\n",
"-1\n"
] | none | 1,500 | [
{
"input": "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5",
"output": "4"
},
{
"input": "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10",
"output": "6"
},
{
"input": "1 1 2 10\n2\n1 1 3\n2 6 10",
"output": "-1"
},
{
"input": "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10... | 1,664,797,936 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 4,505,600 | from sys import stdin
input=stdin.readline
x0,y0,x1,y1=map(int,input().split()) ; n=int(input()) ; nodes=dict()
for i in range(n):
r,start,end=map(int, input().split())
for j in range(start,end+1):
nodes[(r,j)]=0
X_axis=[1,-1,0,0,1,1,-1,-1]
Y_axis=[0,0,1,-1,1,-1,1,-1]
queue=[(x0,y0)] ; leve... | Title: King's Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with int... | ```python
from sys import stdin
input=stdin.readline
x0,y0,x1,y1=map(int,input().split()) ; n=int(input()) ; nodes=dict()
for i in range(n):
r,start,end=map(int, input().split())
for j in range(start,end+1):
nodes[(r,j)]=0
X_axis=[1,-1,0,0,1,1,-1,-1]
Y_axis=[0,0,1,-1,1,-1,1,-1]
queue=[(x0,y0... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,632,148,498 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 108 | 20,172,800 | from sys import stdin, stdout
def solve(s,l,r,c1,c2):
arr = []
for i in range(n):
if i>=l-1 and i<r:
if s[i] == c1:
arr.append(c2)
else:
arr.append(s[i])
else:
arr.append(s[i])
s = ''.join(arr)
return s
... | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
from sys import stdin, stdout
def solve(s,l,r,c1,c2):
arr = []
for i in range(n):
if i>=l-1 and i<r:
if s[i] == c1:
arr.append(c2)
else:
arr.append(s[i])
else:
arr.append(s[i])
s = ''.join(arr)
re... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,569,686,086 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 140 | 0 | s = input().lower()
t = "hello"
loc = 0
for i in range(0,len(s)):
if(s[i] == t[loc]):
loc = loc + 1
if(loc == 5):
print("YES")
break
if(loc < 5):
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().lower()
t = "hello"
loc = 0
for i in range(0,len(s)):
if(s[i] == t[loc]):
loc = loc + 1
if(loc == 5):
print("YES")
break
if(loc < 5):
print("NO")
``` | 3.93 | MatrixStudio/Codeforces-Python-Submissions |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,632,757,912 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 7,372,800 | # Untitled-1.py
# from pathlib import Path
# ROOT = Path(__file__).parent.absolute()
def main():
i = input()
print(i + i[::-1])
if __name__ == '__main__':
# print('Running Untitled-1.py')
main()
| Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
# Untitled-1.py
# from pathlib import Path
# ROOT = Path(__file__).parent.absolute()
def main():
i = input()
print(i + i[::-1])
if __name__ == '__main__':
# print('Running Untitled-1.py')
main()
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and brin... | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to th... | 1,579,626,089 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 184 | 0 | l=[]
maxlen=0
try:
while True:
a=input()
l.append(a)
if len(a)>maxlen:maxlen=len(a)
except:
pass
print("*"*(maxlen+2))
for each in l:
print("*{text}*".format(text=each.center(maxlen,' ')))
print("*"*(maxlen+2))
| Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You ... | ```python
l=[]
maxlen=0
try:
while True:
a=input()
l.append(a)
if len(a)>maxlen:maxlen=len(a)
except:
pass
print("*"*(maxlen+2))
for each in l:
print("*{text}*".format(text=each.center(maxlen,' ')))
print("*"*(maxlen+2))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,474,916,524 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n = int(input())
#n=5
z = 1
s = [None] * n
#a = [None] * n
#b = [None] * n
u = [None] * n
#s[0] = 'tourist reposted Polycarp'
#s[1] = 'Petr reposted Tourist'
#s[2] = 'WJMZBMR reposted Petr'
#s[3] = 'sdya reposted wjmzbmr'
#s[4] = 'vepifanov reposted sdya'
for i in range(0,n):
s[i] = input()
for i in ... | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
n = int(input())
#n=5
z = 1
s = [None] * n
#a = [None] * n
#b = [None] * n
u = [None] * n
#s[0] = 'tourist reposted Polycarp'
#s[1] = 'Petr reposted Tourist'
#s[2] = 'WJMZBMR reposted Petr'
#s[3] = 'sdya reposted wjmzbmr'
#s[4] = 'vepifanov reposted sdya'
for i in range(0,n):
s[i] = input()
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,616,785,518 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 62 | 0 | s,a,b,c,d = map(int,input().split())
e = s*a+2*c
f = s*b+2*d
if e<f:
print('First')
elif e==f:
print('Friendship')
else:
print('Second') | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s,a,b,c,d = map(int,input().split())
e = s*a+2*c
f = s*b+2*d
if e<f:
print('First')
elif e==f:
print('Friendship')
else:
print('Second')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,699,094,534 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,764,800 | def main():
s = str(input())
if(s.count('1') + s.count('4') != len(s)):
print('NO')
elif(s.index('444') != -1):
print('NO')
else:
print('YES')
main() | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
def main():
s = str(input())
if(s.count('1') + s.count('4') != len(s)):
print('NO')
elif(s.index('444') != -1):
print('NO')
else:
print('YES')
main()
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
797 | A | k-Factorization | PROGRAMMING | 1,100 | [
"implementation",
"math",
"number theory"
] | null | null | Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). | If it's impossible to find the representation of *n* as a product of *k* numbers, print -1.
Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. | [
"100000 2\n",
"100000 20\n",
"1024 5\n"
] | [
"2 50000 \n",
"-1\n",
"2 64 2 2 2 \n"
] | none | 0 | [
{
"input": "100000 2",
"output": "2 50000 "
},
{
"input": "100000 20",
"output": "-1"
},
{
"input": "1024 5",
"output": "2 64 2 2 2 "
},
{
"input": "100000 10",
"output": "2 2 2 2 2 5 5 5 5 5 "
},
{
"input": "99999 3",
"output": "3 813 41 "
},
{
"input... | 1,630,438,223 | 2,147,483,647 | Python 3 | OK | TESTS | 166 | 77 | 6,963,200 | import math
def main_function():
n, k = [int(i) for i in input().split(" ")]
counter = 0
collector = []
n_can_not_be_divided = False
n_is_less = False
while counter < k:
if n == 1:
n_is_less = True
break
if counter == k - 1:
if n ... | Title: k-Factorization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
Input Specification:
The first line contains two int... | ```python
import math
def main_function():
n, k = [int(i) for i in input().split(" ")]
counter = 0
collector = []
n_can_not_be_divided = False
n_is_less = False
while counter < k:
if n == 1:
n_is_less = True
break
if counter == k - 1:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
325 | B | Stadium and Games | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1018), the number of games that should be played.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print all possible numbers of invited teams in ascending order, one per line. If exactly *n* games cannot be played, output one number: -1. | [
"3\n",
"25\n",
"2\n"
] | [
"3\n4\n",
"20\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3",
"output": "3\n4"
},
{
"input": "25",
"output": "20"
},
{
"input": "2",
"output": "-1"
},
{
"input": "1",
"output": "2"
},
{
"input": "15",
"output": "10\n16"
},
{
"input": "314",
"output": "-1"
},
{
"input": "524800",
"o... | 1,664,699,801 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 37 | 124 | 0 | #list(map(int,input().split()))
def func(a,b,c):
d = b*b-4*a*c
if d<0:
return -1
else:
return (-b+d**0.5)/2
def check(l,n):
t = 0
while(l%2==0):
l=l//2
t+=l
t+=((l)*(l-1))//2
if t==n:
return 1
else:
return 0
n = int(input())
ans=[]
for i in range(1,62):
b = 2**i-3
x = fu... | Title: Stadium and Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one g... | ```python
#list(map(int,input().split()))
def func(a,b,c):
d = b*b-4*a*c
if d<0:
return -1
else:
return (-b+d**0.5)/2
def check(l,n):
t = 0
while(l%2==0):
l=l//2
t+=l
t+=((l)*(l-1))//2
if t==n:
return 1
else:
return 0
n = int(input())
ans=[]
for i in range(1,62):
b = 2**i-... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ... | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "8471941278... | 1,550,923,469 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 0 |
n = int(input())
i = 1
while(n > i):
n = n - i
i += 1
print(n) | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,... | ```python
n = int(input())
i = 1
while(n > i):
n = n - i
i += 1
print(n)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,593,574,784 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 234 | 2,150,400 | import sys,math,collections
from itertools import permutations,combinations
def file():
sys.stdin = open('input.py', 'r')
sys.stdout = open('output.py', 'w')
def get_array():
l=list(map(int, input().split()))
return l
file()
def main():
a,b=map(int, input().split())
if(a==b):
print(b)
re... | 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
import sys,math,collections
from itertools import permutations,combinations
def file():
sys.stdin = open('input.py', 'r')
sys.stdout = open('output.py', 'w')
def get_array():
l=list(map(int, input().split()))
return l
file()
def main():
a,b=map(int, input().split())
if(a==b):
prin... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — ... | The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has... | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
}... | 1,678,890,033 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,764,800 | a,b,c=list(map(int,input().split()))
while(1):
if a*2<=b and a*4<=c:
print(a+(2*a)+(4*a))
a-=1
| Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa... | ```python
a,b,c=list(map(int,input().split()))
while(1):
if a*2<=b and a*4<=c:
print(a+(2*a)+(4*a))
a-=1
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
35 | C | Fire Again | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"shortest paths"
] | C. Fire Again | 2 | 64 | After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing... | The first input line contains two integers *N*,<=*M* (1<=≤<=*N*,<=*M*<=≤<=2000) — the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=≤<=*x*<=≤<=*N*,<=1<=≤<=*y*<=≤<=*M*) type, *x* and *y* are integers.
The second line contains an integer *K* (1<=≤<=*K*<=≤<=10) — amount of trees, burning... | Output a line with two space-separated integers *x* and *y* — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. | [
"3 3\n1\n2 2\n",
"3 3\n1\n1 1\n",
"3 3\n2\n1 1 3 3\n"
] | [
"1 1\n",
"3 3\n",
"2 2"
] | none | 1,500 | [
{
"input": "3 3\n1\n2 2",
"output": "1 1"
},
{
"input": "3 3\n1\n1 1",
"output": "3 3"
},
{
"input": "3 3\n2\n1 1 3 3",
"output": "1 3"
},
{
"input": "1 1\n1\n1 1",
"output": "1 1"
},
{
"input": "2 2\n1\n2 2",
"output": "1 1"
},
{
"input": "2 2\n2\n1 1... | 1,667,315,560 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | f = open('input.txt')
out = open('output.txt', mode='w')
n,m = map(int, f.readline().split())
puti = [[1e9 for i in range(m + 1)] for j in range(n + 1)]
k = int(f.readline())
mas = list(map(int, f.readline().split()))
q = []
for i in range(k):
a, b = mas[i*2], mas[i*2+1]
puti[a][b] = 0
q.append([a... | Title: Fire Again
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th... | ```python
f = open('input.txt')
out = open('output.txt', mode='w')
n,m = map(int, f.readline().split())
puti = [[1e9 for i in range(m + 1)] for j in range(n + 1)]
k = int(f.readline())
mas = list(map(int, f.readline().split()))
q = []
for i in range(k):
a, b = mas[i*2], mas[i*2+1]
puti[a][b] = 0
q... | 0 | MatrixStudio/Codeforces-Python-Submissions |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,674,781,321 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n = int(input())
if n % 2 == 1: # if odd
print("-1")
else: # if even
output = list(range(1, n + 1))
for i in range(len(output)):
if i % 2 == 0:
output[i] += 1
else:
output[i] -= 1
out = ""
for i in output:
out += str(i) + " "
print(out) | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
n = int(input())
if n % 2 == 1: # if odd
print("-1")
else: # if even
output = list(range(1, n + 1))
for i in range(len(output)):
if i % 2 == 0:
output[i] += 1
else:
output[i] -= 1
out = ""
for i in output:
out += str(i) + " "
print(o... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,688,620,909 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 124 | 102,400 | from collections import Counter
"""
--------- Pre - Defined Functions --------
"""
mod = 10**9 + 7
def compute_gcd(x, y):
while(y):
x, y = y, x % y
return x
def compute_lcm(x, y):
lcm = (x*y)//compute_gcd(x,y)
return lcm
def decToBin(n):
return bin(n).replace("0b", "")
... | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
from collections import Counter
"""
--------- Pre - Defined Functions --------
"""
mod = 10**9 + 7
def compute_gcd(x, y):
while(y):
x, y = y, x % y
return x
def compute_lcm(x, y):
lcm = (x*y)//compute_gcd(x,y)
return lcm
def decToBin(n):
return bin(n).replace("... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,694,000,560 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 109 | 0 | l,b=map(int,input().split())
y=0
while l<=b:
l*=3
b*=2
y+=1
print(y) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
l,b=map(int,input().split())
y=0
while l<=b:
l*=3
b*=2
y+=1
print(y)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given set of *n* points in 5-dimensional space. The points are labeled from 1 to *n*. No two points coincide.
We will call point *a* bad if there are different points *b* and *c*, not equal to *a*, from the given set such that angle between vectors and is acute (i.e. strictly less than ). Otherwise, the poin... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=103) — the number of points.
The next *n* lines of input contain five integers *a**i*,<=*b**i*,<=*c**i*,<=*d**i*,<=*e**i* (|*a**i*|,<=|*b**i*|,<=|*c**i*|,<=|*d**i*|,<=|*e**i*|<=≤<=103) — the coordinates of the i-th point. All points are distinct. | First, print a single integer *k* — the number of good points.
Then, print *k* integers, each on their own line — the indices of the good points in ascending order. | [
"6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n",
"3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n"
] | [
"1\n1\n",
"0\n"
] | In the first sample, the first point forms exactly a <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/362ac8c7a7496dffc06cd0c843287cd822be63c3.png" style="max-width: 100.0%;max-height: 100.0%;"/> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, ... | 0 | [
{
"input": "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1",
"output": "1\n1"
},
{
"input": "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0",
"output": "0"
},
{
"input": "1\n0 0 0 0 0",
"output": "1\n1"
},
{
"input": "2\n0 1 2 3 4\n5 6 7 8 9",
"output": "2\n1\n2"... | 1,504,543,613 | 7,913 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 61 | 204,800 | class point:
def __init__(self, a, b, c, d, e):
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
def mult(x, y):
return x.a * y.a + x.b * y.b + x.c * y.c + x.d * y.d + x.e * y.e
def mns(x, y):
return point(x.a - y.a, x.b - y.b, x.c - y.c, x.d... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given set of *n* points in 5-dimensional space. The points are labeled from 1 to *n*. No two points coincide.
We will call point *a* bad if there are different points *b* and *c*, not equal to *a*, from the given set such... | ```python
class point:
def __init__(self, a, b, c, d, e):
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
def mult(x, y):
return x.a * y.a + x.b * y.b + x.c * y.c + x.d * y.d + x.e * y.e
def mns(x, y):
return point(x.a - y.a, x.b - y.b, x.c ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,589,845,386 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 216 | 0 | l = input("")
t = input("")
currPos = 0
for i in t:
if l[currPos] == i:
currPos+=1
print(currPos+1)
| Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
l = input("")
t = input("")
currPos = 0
for i in t:
if l[currPos] == i:
currPos+=1
print(currPos+1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,692,121,304 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n = int(input())
l= []
for i in range(n):
l.append(input())
x = l[0]
x1 = ''
for i in l:
if i == x:
continue
else:
x1 = i
break
count1 = l.count(x)
count2 = l.count(x1)
print(x if count1>count2 else x1)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
l= []
for i in range(n):
l.append(input())
x = l[0]
x1 = ''
for i in l:
if i == x:
continue
else:
x1 = i
break
count1 = l.count(x)
count2 = l.count(x1)
print(x if count1>count2 else x1)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,569,252,413 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 156 | 0 | no_page, present_page, display_range = map(int, input().split())
if(present_page - display_range <= 1):
starting_page = 1
else:
starting_page = present_page - display_range
if(present_page + display_range >= no_page):
ending_page = no_page
else:
ending_page = present_page + display_range
for i ... | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
no_page, present_page, display_range = map(int, input().split())
if(present_page - display_range <= 1):
starting_page = 1
else:
starting_page = present_page - display_range
if(present_page + display_range >= no_page):
ending_page = no_page
else:
ending_page = present_page + display_ran... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,696,925,219 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Oct 10 15:15:05 2023
@author: zinc 2300012115
"""
import math
def primecheck(x):
st = True
if x == 2:
return True
elif x <= 1:
return False
elif x % 2 == 0:
return False
else:
for i in range(2,math.ceil(x... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 10 15:15:05 2023
@author: zinc 2300012115
"""
import math
def primecheck(x):
st = True
if x == 2:
return True
elif x <= 1:
return False
elif x % 2 == 0:
return False
else:
for i in range(2,m... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
478 | C | Table Decorations | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a pro... | The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space. | Print a single integer *t* — the maximum number of tables that can be decorated in the required manner. | [
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] | [
"4\n",
"1\n",
"2\n"
] | In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | 1,500 | [
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "100000... | 1,659,872,995 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | x=list(map(int,input().split()))
x.sort()
if x[0]==0:
print(min(x[1],x[2]))
else:
print((a+b+c)//3) | Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *... | ```python
x=list(map(int,input().split()))
x.sort()
if x[0]==0:
print(min(x[1],x[2]))
else:
print((a+b+c)//3)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
847 | G | University Classes | PROGRAMMING | 900 | [
"implementation"
] | null | null | There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups.
Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot... | Print minimum number of rooms needed to hold all groups classes on Monday. | [
"2\n0101010\n1010101\n",
"3\n0101011\n0011001\n0110111\n"
] | [
"1\n",
"3\n"
] | In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | 0 | [
{
"input": "2\n0101010\n1010101",
"output": "1"
},
{
"input": "3\n0101011\n0011001\n0110111",
"output": "3"
},
{
"input": "1\n0111000",
"output": "1"
},
{
"input": "1\n0000000",
"output": "0"
},
{
"input": "1\n1111111",
"output": "1"
},
{
"input": "2\n... | 1,505,740,172 | 272 | Python 3 | OK | TESTS | 21 | 62 | 4,608,000 | strings = int(input())
count = [0 for x in range(7)]
for k in range(strings):
s = input()
for index in range(7):
if s[index] == '1':
count[index] += 1
print(max(count))
| Title: University Classes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known ... | ```python
strings = int(input())
count = [0 for x in range(7)]
for k in range(strings):
s = input()
for index in range(7):
if s[index] == '1':
count[index] += 1
print(max(count))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,695,325,915 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 78 | 13,414,400 | n = int(input())
k = list(map(int , input() . split()))
sum = 0
min_k = min(k)
max_k = max(k)
for i in range(len(k)):
if k[i] > min_k and k[i] < max_k:
sum += 1
print(sum) | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
n = int(input())
k = list(map(int , input() . split()))
sum = 0
min_k = min(k)
max_k = max(k)
for i in range(len(k)):
if k[i] > min_k and k[i] < max_k:
sum += 1
print(sum)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
690 | D1 | The Wall (easy) | PROGRAMMING | 1,200 | [] | null | null | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment... | The first line of the input consists of two space-separated integers *R* and *C*, 1<=≤<=*R*,<=*C*<=≤<=100. The next *R* lines provide a description of the columns as follows:
- each of the *R* lines contains a string of length *C*, - the *c*-th character of line *r* is B if there is a brick in column *c* and row *R... | The number of wall segments in the input configuration. | [
"3 7\n.......\n.......\n.BB.B..\n",
"4 5\n..B..\n..B..\nB.B.B\nBBB.B\n",
"4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB\n",
"1 1\nB\n",
"10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\nB.BB.B.\n",
"8 8\n........\n........\n........\n........\n.B......\n.B.....B\n.B.....B\n.BB.... | [
"2\n",
"2\n",
"1\n",
"1\n",
"3\n",
"2\n"
] | In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second. | 0 | [
{
"input": "3 7\n.......\n.......\n.BB.B..",
"output": "2"
},
{
"input": "4 5\n..B..\n..B..\nB.B.B\nBBB.B",
"output": "2"
},
{
"input": "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB",
"output": "1"
},
{
"input": "1 1\nB",
"output": "1"
},
{
"input": "10 7\n.......\n.......... | 1,468,176,356 | 2,147,483,647 | Python 3 | OK | TESTS | 119 | 93 | 0 | r, c = map(int, input().split())
last = ""
for i in range(r):
s = str(input())
if i == r - 1:
last = s
answer = 0
left = 0
while left <= c - 1:
if last[left] == "B":
try:
while last[left] == "B":
left += 1
except Exception:
pass
an... | Title: The Wall (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is fai... | ```python
r, c = map(int, input().split())
last = ""
for i in range(r):
s = str(input())
if i == r - 1:
last = s
answer = 0
left = 0
while left <= c - 1:
if last[left] == "B":
try:
while last[left] == "B":
left += 1
except Exception:
pass
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,613,746,269 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 78 | 0 | n = int(input()) # n of disks
numbers = [int(x) for x in input()] # list of integers
solution = [int(x) for x in input()] # list of integers
r = 0
for k, v in enumerate(numbers):
d = abs(v - solution[k])
if d > 5:
r += 10 - d
elif d == 5:
r += 5
else:
r += d
print(... | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input()) # n of disks
numbers = [int(x) for x in input()] # list of integers
solution = [int(x) for x in input()] # list of integers
r = 0
for k, v in enumerate(numbers):
d = abs(v - solution[k])
if d > 5:
r += 10 - d
elif d == 5:
r += 5
else:
r +=... | 3 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.