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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,588,084,397 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 310 | 0 | n = int(input())
pi = 3.1415926536
r =sorted([int(i) for i in input().split()])[::-1]
t = 0
# print(r)
for i ,_ in enumerate(r):
if i % 2 == 0 :
if not i == len(r)-1:
t += r[i]*r[i] - r[i+1]*r[i+1]
else :
t += r[i] * r[i]
print(pi * t)
| Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
n = int(input())
pi = 3.1415926536
r =sorted([int(i) for i in input().split()])[::-1]
t = 0
# print(r)
for i ,_ in enumerate(r):
if i % 2 == 0 :
if not i == len(r)-1:
t += r[i]*r[i] - r[i+1]*r[i+1]
else :
t += r[i] * r[i]
print(pi * t)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
376 | B | I.O.U. | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 0<=≤<=*m*<=≤<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*c**i*<=≤<=100), which mean that person *a**i* owes person *b**i* *c**i... | Print a single integer — the minimum sum of debts in the optimal rearrangement. | [
"5 3\n1 2 10\n2 3 1\n2 4 1\n",
"3 0\n",
"4 3\n1 2 1\n2 3 1\n3 1 1\n"
] | [
"10\n",
"0\n",
"0\n"
] | In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.
In the second sample, there are no debts.
In the third sample, you can annul all the debts. | 1,000 | [
{
"input": "5 3\n1 2 10\n2 3 1\n2 4 1",
"output": "10"
},
{
"input": "3 0",
"output": "0"
},
{
"input": "4 3\n1 2 1\n2 3 1\n3 1 1",
"output": "0"
},
{
"input": "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\... | 1,600,130,580 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 139 | 409,600 | from collections import defaultdict
debts = defaultdict()
n, m = map(int, input().split())
for i in range(n):
debts[i + 1] = 0
for _ in range(m):
a, b, c = map(int, input().split())
debts[a] -= c
debts[b] += c
sum = 0
for each in debts.values():
if each > 0:
sum += each
... | Title: I.O.U.
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearran... | ```python
from collections import defaultdict
debts = defaultdict()
n, m = map(int, input().split())
for i in range(n):
debts[i + 1] = 0
for _ in range(m):
a, b, c = map(int, input().split())
debts[a] -= c
debts[b] += c
sum = 0
for each in debts.values():
if each > 0:
sum... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
799 | E | Aquarium decoration | PROGRAMMING | 2,500 | [
"data structures",
"greedy",
"two pointers"
] | null | null | Arkady and Masha want to choose decorations for thier aquarium in Fishdom game. They have *n* decorations to choose from, each of them has some cost. To complete a task Arkady and Masha need to choose exactly *m* decorations from given, and they want to spend as little money as possible.
There is one difficulty: Masha... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=200000, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=*n*) — the number of decorations, how many decorations the friends should choose, how many decorations each of them should like among the chosen.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c*... | Print single integer: the minimum sum of money the friends should spend to fulfill all constraints. If it is not possible, print -1. | [
"4 3 2\n3 2 2 1\n2\n1 2\n2\n1 3\n",
"4 3 2\n3 2 2 1\n2\n1 2\n3\n4 1 3\n",
"4 2 2\n3 2 2 1\n2\n1 2\n3\n4 1 3\n"
] | [
"7\n",
"6\n",
"-1\n"
] | In the first example the only possible variant to choose 3 decorations having all conditions satisfied is to choose decorations 1, 2, 3.
In the second example friends can choose decoration 4 instead of decoration 3, because this one is one coin cheaper.
In the third example it's not possible to choose 2 decorations i... | 2,500 | [
{
"input": "4 3 2\n3 2 2 1\n2\n1 2\n2\n1 3",
"output": "7"
},
{
"input": "4 3 2\n3 2 2 1\n2\n1 2\n3\n4 1 3",
"output": "6"
},
{
"input": "4 2 2\n3 2 2 1\n2\n1 2\n3\n4 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1\n1\n1\n1\n1",
"output": "1"
},
{
"input": "2 1 1\n1 ... | 1,696,354,375 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 46 | 0 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * (n + 1) + v
def update(i, x, tree):
i += l1
tree[i] = x
i >>= 1
while i:
tree[i] = tree[2 * i] + tree[2 * i + 1]
i >>= 1
return
n, m, k = map(int, input().spl... | Title: Aquarium decoration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady and Masha want to choose decorations for thier aquarium in Fishdom game. They have *n* decorations to choose from, each of them has some cost. To complete a task Arkady and Masha need to choose exactly *m* de... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * (n + 1) + v
def update(i, x, tree):
i += l1
tree[i] = x
i >>= 1
while i:
tree[i] = tree[2 * i] + tree[2 * i + 1]
i >>= 1
return
n, m, k = map(int, i... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
48 | A | Rock-paper-scissors | PROGRAMMING | 900 | [
"implementation",
"schedules"
] | A. Rock-paper-scissors | 2 | 256 | Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio... | The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. | Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". | [
"rock\nrock\nrock\n",
"paper\nrock\nrock\n",
"scissors\nrock\nrock\n",
"scissors\npaper\nrock\n"
] | [
"?\n",
"F\n",
"?\n",
"?\n"
] | none | 0 | [
{
"input": "rock\nrock\nrock",
"output": "?"
},
{
"input": "paper\nrock\nrock",
"output": "F"
},
{
"input": "scissors\nrock\nrock",
"output": "?"
},
{
"input": "scissors\npaper\nrock",
"output": "?"
},
{
"input": "paper\npaper\nrock",
"output": "?"
},
{
... | 1,673,911,803 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 122 | 0 | p = [input() for i in range(3)]
if p[0]=='paper' and p[1]=='rock' and p[2]=='rock':
print("F")
elif p[1]=='paper' and p[0]=='rock' and p[2]=='rock':
print("M")
elif p[2]=='paper' and p[1]=='rock' and p[0]=='rock':
print("S")
elif p[0]=='scissors' and p[1]=='paper' and p[2]=='paper':
print("F... | Title: Rock-paper-scissors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ... | ```python
p = [input() for i in range(3)]
if p[0]=='paper' and p[1]=='rock' and p[2]=='rock':
print("F")
elif p[1]=='paper' and p[0]=='rock' and p[2]=='rock':
print("M")
elif p[2]=='paper' and p[1]=='rock' and p[0]=='rock':
print("S")
elif p[0]=='scissors' and p[1]=='paper' and p[2]=='paper':
... | 3.9695 | MatrixStudio/Codeforces-Python-Submissions |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,688,970,039 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 3,584,000 | n, t = map(int, input().split())
t -= 1
a = list(map(int, input().split()))
k = 0
while k < t:
k += a[k]
print(["NO", "YES"][k == t])
| Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n, t = map(int, input().split())
t -= 1
a = list(map(int, input().split()))
k = 0
while k < t:
k += a[k]
print(["NO", "YES"][k == t])
``` | 3 | 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,827,512 | 6,612 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | def count2(a):
a = int(a)
st2 = 0
while a%2 == 0:
a=a//2
st2+=1
return st2
def count5(a):
a=int(a)
st5 = 0
while a%5 == 0:
a=a//5
st5+=1
return st5
def umn(n,k):
st2 = count2(n)
st5 = count5(n)
m = min(st2, st5)
ot... | 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
def count2(a):
a = int(a)
st2 = 0
while a%2 == 0:
a=a//2
st2+=1
return st2
def count5(a):
a=int(a)
st5 = 0
while a%5 == 0:
a=a//5
st5+=1
return st5
def umn(n,k):
st2 = count2(n)
st5 = count5(n)
m = min(st2, st... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
817 | B | Makes And The Product | PROGRAMMING | 1,500 | [
"combinatorics",
"implementation",
"math",
"sortings"
] | null | null | After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (*i*,<= *j*,<= *k*) (*i*<=<<=*j*<=<<=*k*), such that *a**i*·*a**j*·*a... | The first line of input contains a positive integer number *n* (3<=≤<=*n*<=≤<=105) — the number of elements in array *a*. The second line contains *n* positive integer numbers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of a given array. | Print one number — the quantity of triples (*i*,<= *j*,<= *k*) such that *i*,<= *j* and *k* are pairwise distinct and *a**i*·*a**j*·*a**k* is minimum possible. | [
"4\n1 1 1 1\n",
"5\n1 3 2 3 4\n",
"6\n1 3 3 1 3 2\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) ... | 0 | [
{
"input": "4\n1 1 1 1",
"output": "4"
},
{
"input": "5\n1 3 2 3 4",
"output": "2"
},
{
"input": "6\n1 3 3 1 3 2",
"output": "1"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": ... | 1,569,348,884 | 4,484 | Python 3 | OK | TESTS | 80 | 202 | 9,113,600 | n=int(input())
a=list(map(int,input().split()))
a1=sorted(a)
k1,k2,k3=a1[0],a1[1],a1[2]
pre=[0,0,0]
ans=0
for i in range(n):
if a[i]==k1:
pre[0]+=1
if a[i]==k2:
pre[1]+=1
if a[i] == k3:
pre[2] += 1
if k1!=k2 and k1!=k3 and k3!=k2:
ans = pre[0] * pre[1] * pre[2]
... | Title: Makes And The Product
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular questi... | ```python
n=int(input())
a=list(map(int,input().split()))
a1=sorted(a)
k1,k2,k3=a1[0],a1[1],a1[2]
pre=[0,0,0]
ans=0
for i in range(n):
if a[i]==k1:
pre[0]+=1
if a[i]==k2:
pre[1]+=1
if a[i] == k3:
pre[2] += 1
if k1!=k2 and k1!=k3 and k3!=k2:
ans = pre[0] * pre[1]... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,585,753,987 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 124 | 307,200 | n=int(input())
la=[]
lb=[]
for _ in range(n):
a,b=map(int, input().split())
la.append(a)
lb.append(b)
if la!=lb:
print("rated")
else:
la1 = la[:]
lb1 = lb[:]
la1.sort()
lb1.sort()
la1.reverse()
lb1.reverse()
if (la1 == la) and (lb1==lb):
print("maybe")
else:
... | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
n=int(input())
la=[]
lb=[]
for _ in range(n):
a,b=map(int, input().split())
la.append(a)
lb.append(b)
if la!=lb:
print("rated")
else:
la1 = la[:]
lb1 = lb[:]
la1.sort()
lb1.sort()
la1.reverse()
lb1.reverse()
if (la1 == la) and (lb1==lb):
print("maybe")
e... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
376 | A | Lever | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1.
The decoding of the lever d... | The first line contains the lever description as a non-empty string *s* (3<=≤<=|*s*|<=≤<=106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.
To solve the p... | Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance. | [
"=^==\n",
"9===^==1\n",
"2==^7==\n",
"41^52==\n"
] | [
"balance\n",
"left\n",
"right\n",
"balance\n"
] | As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.
The pictures to the examples: | 500 | [
{
"input": "=^==",
"output": "balance"
},
{
"input": "9===^==1",
"output": "left"
},
{
"input": "2==^7==",
"output": "right"
},
{
"input": "41^52==",
"output": "balance"
},
{
"input": "=^2=4=1===1=",
"output": "right"
},
{
"input": "9=6===5==3=9=1=1^7=... | 1,504,918,944 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 732 | 3,174,400 | a = input()
i = 0
r = 0
l = 0
while(a[i] != "^"):
i = i+1
k = i
for j in range(i):
if(a[j]!= "="):
l = l +k*int(a[j])
k = k-1
k = 1
i +=1
while(i<len(a)):
if(a[i]!= "="):
r = r+k*int(a[i])
i = i+1
k = k+1
if(r==l):
print("balance")
elif(l>r):
print(... | Title: Lever
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar i... | ```python
a = input()
i = 0
r = 0
l = 0
while(a[i] != "^"):
i = i+1
k = i
for j in range(i):
if(a[j]!= "="):
l = l +k*int(a[j])
k = k-1
k = 1
i +=1
while(i<len(a)):
if(a[i]!= "="):
r = r+k*int(a[i])
i = i+1
k = k+1
if(r==l):
print("balance")
elif(l>r):
... | 3 | 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,689,775,776 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | s1 = input().strip()
s2 = input().strip()
if len(s1) != len(s2):
print("NO")
else:
is_reverse = True
for i in range(len(s1)):
if s1[i] != s2[len(s2) - i - 1]:
is_reverse = False
break
if is_reverse:
print("YES")
else:
print... | 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
s1 = input().strip()
s2 = input().strip()
if len(s1) != len(s2):
print("NO")
else:
is_reverse = True
for i in range(len(s1)):
if s1[i] != s2[len(s2) - i - 1]:
is_reverse = False
break
if is_reverse:
print("YES")
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
48 | A | Rock-paper-scissors | PROGRAMMING | 900 | [
"implementation",
"schedules"
] | A. Rock-paper-scissors | 2 | 256 | Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio... | The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. | Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". | [
"rock\nrock\nrock\n",
"paper\nrock\nrock\n",
"scissors\nrock\nrock\n",
"scissors\npaper\nrock\n"
] | [
"?\n",
"F\n",
"?\n",
"?\n"
] | none | 0 | [
{
"input": "rock\nrock\nrock",
"output": "?"
},
{
"input": "paper\nrock\nrock",
"output": "F"
},
{
"input": "scissors\nrock\nrock",
"output": "?"
},
{
"input": "scissors\npaper\nrock",
"output": "?"
},
{
"input": "paper\npaper\nrock",
"output": "?"
},
{
... | 1,563,128,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 216 | 0 | a=input() #F
b=input() #M
c=input() #S
d={'rock':1,'paper':2,'scissors':3}
if a==b and b==c:
print('?')
elif a!=b and b!=c:
print('?')
else:
if a==b and b!=c:
if ((d[a]==1 and d[c]==2) or (d[a]==2 and d[c]==3)or
(d[a]==3 and d[c]==1)):
print('S')
else:
print('?')
if b==c:
if ((d[a]==... | Title: Rock-paper-scissors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ... | ```python
a=input() #F
b=input() #M
c=input() #S
d={'rock':1,'paper':2,'scissors':3}
if a==b and b==c:
print('?')
elif a!=b and b!=c:
print('?')
else:
if a==b and b!=c:
if ((d[a]==1 and d[c]==2) or (d[a]==2 and d[c]==3)or
(d[a]==3 and d[c]==1)):
print('S')
else:
print('?')
if b==c:
i... | 0 | MatrixStudio/Codeforces-Python-Submissions |
166 | C | Median | PROGRAMMING | 1,500 | [
"greedy",
"math",
"sortings"
] | null | null | A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,<=2,<=3) is the number 2, and a median of array (0,<=96,<=17,<=23) — the number 17.
We defi... | The first input line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=500, 1<=≤<=*x*<=≤<=105) — the initial array's length and the required median's value. The second line contains *n* space-separated numbers — the initial array. The elements of the array are integers from 1 to 105. The array elements a... | Print the only integer — the minimum number of elements Petya needs to add to the array so that its median equals *x*. | [
"3 10\n10 20 30\n",
"3 4\n1 2 3\n"
] | [
"1\n",
"4\n"
] | In the first sample we can add number 9 to array (10, 20, 30). The resulting array (9, 10, 20, 30) will have a median in position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7dd92241318a531b780c7783dfa446a3e413115e.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 10.
In t... | 1,000 | [
{
"input": "3 10\n10 20 30",
"output": "1"
},
{
"input": "3 4\n1 2 3",
"output": "4"
},
{
"input": "2 2\n3 2",
"output": "0"
},
{
"input": "5 1\n1 1 2 1 2",
"output": "0"
},
{
"input": "5 4\n5 5 4 3 5",
"output": "1"
},
{
"input": "10 2\n2 2 1 3 2 1 2 ... | 1,638,619,414 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | '''input
3 4
1 2 3
'''
import sys
input = sys.stdin.readline
def getstr(): return input().rstrip('\r\n')
def getint(): return int(input().strip())
def getints(): return list(map(int, input().strip().split()))
def impossible(): print(-1),exit(0)
n,k = getints()
arr = getints()
ans = 0
while arr[(len(arr... | Title: Median
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,... | ```python
'''input
3 4
1 2 3
'''
import sys
input = sys.stdin.readline
def getstr(): return input().rstrip('\r\n')
def getint(): return int(input().strip())
def getints(): return list(map(int, input().strip().split()))
def impossible(): print(-1),exit(0)
n,k = getints()
arr = getints()
ans = 0
while ar... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,544,390,608 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 310 | 8,499,200 | c = input()
list = []
for i in range(1000):
z = ((i)*(i+1))//2
list.append(z)
# print(list)
hash = []
for i in list:
for j in list:
hash.append(i+j)
if c in hash:
print('YES')
else:
print('NO')
| Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
c = input()
list = []
for i in range(1000):
z = ((i)*(i+1))//2
list.append(z)
# print(list)
hash = []
for i in list:
for j in list:
hash.append(i+j)
if c in hash:
print('YES')
else:
print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
397 | A | On Segment's Own Points | PROGRAMMING | 0 | [
"implementation"
] | null | null | Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.
The dorm has exactly one straight dryer — a 100 ce... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. | On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. | [
"3\n0 5\n2 8\n1 6\n",
"3\n0 10\n1 5\n7 15\n"
] | [
"1\n",
"3\n"
] | Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.
In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and... | 500 | [
{
"input": "3\n0 5\n2 8\n1 6",
"output": "1"
},
{
"input": "3\n0 10\n1 5\n7 15",
"output": "3"
},
{
"input": "1\n0 100",
"output": "100"
},
{
"input": "2\n1 9\n1 9",
"output": "0"
},
{
"input": "2\n1 9\n5 10",
"output": "4"
},
{
"input": "2\n1 9\n3 5",... | 1,558,159,751 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 109 | 0 | n = int(input())
a,b = [int(i) for i in input().split()]
l = []
for i in range(n-1):
x,y = [int(i) for i in input().split()]
l.append([x,y])
l.sort()
i = 0
while(i<len(l)-1):
if(l[i][1]<a or l[i][0]>b):
l.pop(i)
elif(l[i][1]>=l[i+1][0]):
l[i][1] = l[i+1][1]
l.pop(i+1)
else:
... | Title: On Segment's Own Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some... | ```python
n = int(input())
a,b = [int(i) for i in input().split()]
l = []
for i in range(n-1):
x,y = [int(i) for i in input().split()]
l.append([x,y])
l.sort()
i = 0
while(i<len(l)-1):
if(l[i][1]<a or l[i][0]>b):
l.pop(i)
elif(l[i][1]>=l[i+1][0]):
l[i][1] = l[i+1][1]
l.pop(i+1)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
518 | D | Ilya and Escalator | PROGRAMMING | 1,700 | [
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.
Let's assume that *n* people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue en... | The first line of the input contains three numbers *n*,<=*p*,<=*t* (1<=≤<=*n*,<=*t*<=≤<=2000, 0<=≤<=*p*<=≤<=1). Numbers *n* and *t* are integers, number *p* is real, given with exactly two digits after the decimal point. | Print a single real number — the expected number of people who will be standing on the escalator after *t* seconds. The absolute or relative error mustn't exceed 10<=-<=6. | [
"1 0.50 1\n",
"1 0.50 4\n",
"4 0.20 2\n"
] | [
"0.5\n",
"0.9375\n",
"0.4\n"
] | none | 2,000 | [
{
"input": "1 0.50 1",
"output": "0.500000000000000"
},
{
"input": "1 0.50 4",
"output": "0.937500000000000"
},
{
"input": "4 0.20 2",
"output": "0.400000000000000"
},
{
"input": "2000 0.61 2000",
"output": "1219.999999999999545"
},
{
"input": "100 1.00 200",
... | 1,602,874,105 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 55,296,000 | matriz = [[0 for i in range(2010)]for j in range(2010)]
n, p, t = map(float, input().split())
n = int(n)
t = int(t)
matriz[0][0] = 1
if(n > 2000):
n = 2000
for i in range(1, t+1):
for j in range(n+1):
if j == 0:
matriz[i][j] = matriz[i-1][j]*(1-p)
elif j == n:
matriz[i][j... | Title: Ilya and Escalator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.
Let's assume that *n* people stand in the queue for the escalator. At... | ```python
matriz = [[0 for i in range(2010)]for j in range(2010)]
n, p, t = map(float, input().split())
n = int(n)
t = int(t)
matriz[0][0] = 1
if(n > 2000):
n = 2000
for i in range(1, t+1):
for j in range(n+1):
if j == 0:
matriz[i][j] = matriz[i-1][j]*(1-p)
elif j == n:
m... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,592,895,628 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 31,948,800 | def mo(x,y):
if x<y:
x=y
return x
def myfunc(l1):
i=0
t=[]
temp=0
ans=0
while i<len(l1):
if l1[i] not in t:
temp+=1
t.append(l1[i])
else:
temp-=1
ans=mo(ans,temp)
i+=1
return ans
def answer():... | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
def mo(x,y):
if x<y:
x=y
return x
def myfunc(l1):
i=0
t=[]
temp=0
ans=0
while i<len(l1):
if l1[i] not in t:
temp+=1
t.append(l1[i])
else:
temp-=1
ans=mo(ans,temp)
i+=1
return ans
def... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,650,325,834 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | import math
import sys
#!pip install numpy
#import numpy as np
res=int(input())
#count1 = str1.count(substr)
#print(*(res.replace("WUB"," ").split()))
g=49
#rt="qwertyuiopasdfghjkl;zxcvbnm,./"
#print(res2[1:].count("10"))
a=[]
#b=[]
tar=0
ts=0
for i in range(res):
v=input()
#v=v[i+1:]
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
import math
import sys
#!pip install numpy
#import numpy as np
res=int(input())
#count1 = str1.count(substr)
#print(*(res.replace("WUB"," ").split()))
g=49
#rt="qwertyuiopasdfghjkl;zxcvbnm,./"
#print(res2[1:].count("10"))
a=[]
#b=[]
tar=0
ts=0
for i in range(res):
v=input()
#v=v[i... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T... | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<... | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "5287... | 1,627,119,665 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 6,963,200 | n, p1, p2, p3, t1, t2 = list(map(int, input().split(" ")))
l = []
for _ in range(n):
l += list(map(int, input().split(" ")))
p = 0
for i in range(len(l) // 2 - 1):
x = l[2 * i + 2] - l[2 * i + 1]
p += p1 * min(t1, x) + p2 * min(t2, max(0, x - t1)) + p3 * max(0, x - t1 - t2)
for i in range(len(... | Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f... | ```python
n, p1, p2, p3, t1, t2 = list(map(int, input().split(" ")))
l = []
for _ in range(n):
l += list(map(int, input().split(" ")))
p = 0
for i in range(len(l) // 2 - 1):
x = l[2 * i + 2] - l[2 * i + 1]
p += p1 * min(t1, x) + p2 * min(t2, max(0, x - t1)) + p3 * max(0, x - t1 - t2)
for i in ... | 3.91003 | MatrixStudio/Codeforces-Python-Submissions |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,697,193,926 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | k,n,w=map(int,input().split())
c=0
for i in range(w):
c = c + k*(i + 1)
c = c - n
if c < 0:
print(0)
else:
print(c) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k,n,w=map(int,input().split())
c=0
for i in range(w):
c = c + k*(i + 1)
c = c - n
if c < 0:
print(0)
else:
print(c)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
... | 1,543,665,740 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 310 | 8,089,600 | n = int(input())
a = list(map(int,input().split()))
rs = min(a)
for i in a:
if i%rs!=0:
print(-1)
exit()
print(rs) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that ... | ```python
n = int(input())
a = list(map(int,input().split()))
rs = min(a)
for i in a:
if i%rs!=0:
print(-1)
exit()
print(rs)
``` | 3 | 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,650,182,667 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 0 | a = int(input())
s = list(map(int, input().split()))
t = 0
for i in range(a):
k = max(s)-s[i]
t+=k
print(t) | 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
a = int(input())
s = list(map(int, input().split()))
t = 0
for i in range(a):
k = max(s)-s[i]
t+=k
print(t)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,692,047,163 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n = int(input())
ans = 0
count = 0
while(n != 0):
val = n%10
if(val >= 5 and n != 9):
ans = (10**count)*(9-val) + ans
else:
ans = (10**count)*val + ans
count += 1
n = n//10
print(ans) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
n = int(input())
ans = 0
count = 0
while(n != 0):
val = n%10
if(val >= 5 and n != 9):
ans = (10**count)*(9-val) + ans
else:
ans = (10**count)*val + ans
count += 1
n = n//10
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
796 | D | Police Stations | PROGRAMMING | 2,100 | [
"constructive algorithms",
"dfs and similar",
"dp",
"graphs",
"shortest paths",
"trees"
] | null | null | Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos... | The first line contains three integers *n*, *k*, and *d* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=3·105, 0<=≤<=*d*<=≤<=*n*<=-<=1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.
The second line contains *k* integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≤<=*p**i*<=≤<... | In the first line, print one integer *s* that denotes the maximum number of roads that can be shut down.
In the second line, print *s* distinct integers, the indices of such roads, in any order.
If there are multiple answers, print any of them. | [
"6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n"
] | [
"1\n5\n",
"2\n4 5 "
] | In the first sample, if you shut down road 5, all cities can still reach a police station within *k* = 4 kilometers.
In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line. | 1,500 | [
{
"input": "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6",
"output": "1\n3 "
},
{
"input": "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6",
"output": "2\n4 5 "
},
{
"input": "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10",
"output": "0"
},
{
"input": "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n... | 1,650,751,851 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 96,460,800 | #https://codeforces.com/contest/796/problem/D
from collections import deque
n, k, d = list(map(int, input().split()))
police = list(map(int, input().split()))
g = [[] for _ in range(n+1)]
edges = {}
c = 1
for m in range(n-1):
i, j = list(map(int, input().split()))
g[i].append((j, m+1))
g[j].append... | Title: Police Stations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's p... | ```python
#https://codeforces.com/contest/796/problem/D
from collections import deque
n, k, d = list(map(int, input().split()))
police = list(map(int, input().split()))
g = [[] for _ in range(n+1)]
edges = {}
c = 1
for m in range(n-1):
i, j = list(map(int, input().split()))
g[i].append((j, m+1))
g... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,542,794,430 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | n = int(input())
d = 0
g = 0
h = 0
j = 0
for i in range(n):
a,b,c = map(int,input().split())
if a == 1:
if b > 0:
d += 1
elif a == 2:
j += 1
if c > 0:
g += 1
if d > 0 and g >= j:
print("LIVE")
print("LIVE")
elif d > h and g == j:
... | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
n = int(input())
d = 0
g = 0
h = 0
j = 0
for i in range(n):
a,b,c = map(int,input().split())
if a == 1:
if b > 0:
d += 1
elif a == 2:
j += 1
if c > 0:
g += 1
if d > 0 and g >= j:
print("LIVE")
print("LIVE")
elif d > h and... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,513,700,130 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 62 | 5,529,600 | l=int(input())
p=int(input())
q=int(input())
x=p*l/(p+q)
y=2*p*l*(q-p)/(p+q)**2
if(x-int(x)==0):
print(int(x))
else:
print(x)
#print(y)
#print(x-y)
| Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
l=int(input())
p=int(input())
q=int(input())
x=p*l/(p+q)
y=2*p*l*(q-p)/(p+q)**2
if(x-int(x)==0):
print(int(x))
else:
print(x)
#print(y)
#print(x-y)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,449,661,697 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 420 | 20,684,800 | n=int(input())
l=[int(i) for i in input().split()]
l.sort()
N=-l[n-1]
for i in range(n):
N=N+l[i]*(i+2)
print(N)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
N=-l[n-1]
for i in range(n):
N=N+l[i]*(i+2)
print(N)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,694,504,397 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 31 | 0 | n = int(input())
l1 = set(map(int, input().split()))
l2 = set(map(int, input().split()))
l1.update(l2)
if len(l1) == n:
print("I become the guy.")
else:
print("Oh, my keyboard!")
| Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
l1 = set(map(int, input().split()))
l2 = set(map(int, input().split()))
l1.update(l2)
if len(l1) == n:
print("I become the guy.")
else:
print("Oh, my keyboard!")
``` | 0 | 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,643,306,674 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 280 | 0 | n,a=list(map(int,input().split()))
p=list(map(int,input().split()))
k=list(p)
ma=0
mi=0
for i in range(0,n):
ma=ma+max(p)
j=p.index(max(p))
p[j]=p[j]-1
c=0
while(True):
if min(k)!=0:
mi=mi+min(k)
j=k.index(min(k))
k[j]=k[j]-1
c=c+1
else:
k.rem... | 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,a=list(map(int,input().split()))
p=list(map(int,input().split()))
k=list(p)
ma=0
mi=0
for i in range(0,n):
ma=ma+max(p)
j=p.index(max(p))
p[j]=p[j]-1
c=0
while(True):
if min(k)!=0:
mi=mi+min(k)
j=k.index(min(k))
k[j]=k[j]-1
c=c+1
else:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,697,532,992 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 124 | 0 | s = input()
d = ''
if ord('a') <= ord(s[0]) <= ord('z'):
d+= chr(ord(s[0])-32)
else:
d+= s[0]
print(d + s[1:]) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
s = input()
d = ''
if ord('a') <= ord(s[0]) <= ord('z'):
d+= chr(ord(s[0])-32)
else:
d+= s[0]
print(d + s[1:])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,617,938,369 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 592 | 11,264,000 | def costToBalance(s):
stack=[]
for i in s:
if(i=="("):
stack.append(i)
elif(i==")" and stack and stack[-1]=="("):
stack.pop(-1)
else:
stack.append(i)
return len(stack)
s =input().strip()
print(len(s)-costToBalance(s))
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
def costToBalance(s):
stack=[]
for i in s:
if(i=="("):
stack.append(i)
elif(i==")" and stack and stack[-1]=="("):
stack.pop(-1)
else:
stack.append(i)
return len(stack)
s =input().strip()
print(len(s)-costToBalance(s))
``` | 3.919819 | 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,534,184,958 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 216 | 0 | # #input
s = str(input())
l = list(map(str,s))
for i in range(len(l)+1):
if len(l) == 1:
break
if i == len(l)-1:
break
if '/' in l[i] and '/' in l[i+1]:
l[i] = "0"
elif '/' in l[i] and '/' not in l[i+1]:
continue
elif '/' in l[i-1] and '/' in l[i]:
l[i] = "0"
if '/' in l[-1] and len(l) != 1:
l[-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
# #input
s = str(input())
l = list(map(str,s))
for i in range(len(l)+1):
if len(l) == 1:
break
if i == len(l)-1:
break
if '/' in l[i] and '/' in l[i+1]:
l[i] = "0"
elif '/' in l[i] and '/' not in l[i+1]:
continue
elif '/' in l[i-1] and '/' in l[i]:
l[i] = "0"
if '/' in l[-1] and len(l) != 1:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,699,280,918 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | n = int(input())
a = sorted([int(i) for i in input().split()],reverse=True)
res = 0
for i in range(len(a)):
if res > (len(a)-res):
break
res += 1
print(res)
| Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n = int(input())
a = sorted([int(i) for i in input().split()],reverse=True)
res = 0
for i in range(len(a)):
if res > (len(a)-res):
break
res += 1
print(res)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
460 | C | Present | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"greedy"
] | null | null | Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted *n* flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver no... | The first line contains space-separated integers *n*, *m* and *w* (1<=≤<=*w*<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105). The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the maximum final height of the smallest flower. | [
"6 2 3\n2 2 2 2 1 1\n",
"2 5 1\n5 8\n"
] | [
"2\n",
"9\n"
] | In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test. | 1,500 | [
{
"input": "6 2 3\n2 2 2 2 1 1",
"output": "2"
},
{
"input": "2 5 1\n5 8",
"output": "9"
},
{
"input": "1 1 1\n1",
"output": "2"
},
{
"input": "3 2 3\n999999998 999999998 999999998",
"output": "1000000000"
},
{
"input": "10 8 3\n499 498 497 497 497 497 497 497 498... | 1,686,103,916 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | import sys
input = lambda: sys.stdin.readline().strip()
from collections import deque
n, m, w = list(map(int, input().split()))
a = list(map(int, input().split()))
l, r = 1, 100010001 # [)
while l < r - 1:
mid = (l + r) // 2
q = deque()
diff = 0
cnt = 0
if a[0] < mid:
diff = m... | Title: Present
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted *n* flowers in a row o... | ```python
import sys
input = lambda: sys.stdin.readline().strip()
from collections import deque
n, m, w = list(map(int, input().split()))
a = list(map(int, input().split()))
l, r = 1, 100010001 # [)
while l < r - 1:
mid = (l + r) // 2
q = deque()
diff = 0
cnt = 0
if a[0] < mid:
... | 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,682,086,530 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 108 | 614,400 | from collections import *
import sys
from functools import reduce
from itertools import *
def _input(): return sys.stdin.readline().rstrip("\r\n")
def I(): return int(_input())
def II(): return _input()
def III(): return map(int, _input().split())
def IV(): return list(map(int, _input().split()))
def V(): return sort... | 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
from collections import *
import sys
from functools import reduce
from itertools import *
def _input(): return sys.stdin.readline().rstrip("\r\n")
def I(): return int(_input())
def II(): return _input()
def III(): return map(int, _input().split())
def IV(): return list(map(int, _input().split()))
def V(): r... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
495 | B | Modular Equations | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and... | In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. | If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . | [
"21 5\n",
"9435152 272\n",
"10 10\n"
] | [
"2\n",
"282\n",
"infinity\n"
] | In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "21 5",
"output": "2"
},
{
"input": "9435152 272",
"output": "282"
},
{
"input": "10 10",
"output": "infinity"
},
{
"input": "0 1000000000",
"output": "0"
},
{
"input": "11 2",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
... | 1,671,151,010 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 93 | 1,228,800 |
if __name__ == '__main__':
a, b = [int(x) for x in input().split()]
if b == a:
print('infinity')
elif b > a:
print(0)
else:
c = 0
diff = a - b
x = 1
while x*x <= diff:
if diff % x == 0:
if x > b:
c += 1
... | Title: Modular Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed'... | ```python
if __name__ == '__main__':
a, b = [int(x) for x in input().split()]
if b == a:
print('infinity')
elif b > a:
print(0)
else:
c = 0
diff = a - b
x = 1
while x*x <= diff:
if diff % x == 0:
if x > b:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
958 | D1 | Hyperspace Jump (easy) | PROGRAMMING | 1,400 | [
"expression parsing",
"math"
] | null | null | The Rebel fleet is on the run. It consists of *m* ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independe... | The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) – the number of ships. The next *m* lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer *a* of up to two dec... | Print a single line consisting of *m* space-separated integers. The *i*-th integer should be equal to the number of ships whose coordinate is equal to that of the *i*-th ship (including the *i*-th ship itself). | [
"4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7\n"
] | [
"1 2 2 1 "
] | In the sample testcase, the second and the third ship will both end up at the coordinate 3.
Note that this problem has only two versions – easy and hard. | 0 | [
{
"input": "4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7",
"output": "1 2 2 1 "
},
{
"input": "10\n(44+98)/19\n(36+58)/47\n(62+74)/68\n(69+95)/82\n(26+32)/29\n(32+46)/39\n(32+24)/28\n(47+61)/54\n(39+13)/26\n(98+98)/98",
"output": "1 9 9 9 9 9 9 9 9 9 "
},
{
"input": "30\n(89+76)/87\n(81... | 1,523,694,247 | 4,747 | Python 3 | OK | TESTS | 16 | 1,996 | 42,598,400 | import re
m=int(input())
lis=list()
for i in range(m):
s=input()
lis+=[re.split('\W+', s)]
d=dict()
for i in range(m):
ans=int(lis[i][1])+int(lis[i][2])
ans=ans/int(lis[i][3])
lis[i][0]=ans
if ans in d:
d[ans]+=1
else: d[ans]=1
for i in range(m):
print(d[... | Title: Hyperspace Jump (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Rebel fleet is on the run. It consists of *m* ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebe... | ```python
import re
m=int(input())
lis=list()
for i in range(m):
s=input()
lis+=[re.split('\W+', s)]
d=dict()
for i in range(m):
ans=int(lis[i][1])+int(lis[i][2])
ans=ans/int(lis[i][3])
lis[i][0]=ans
if ans in d:
d[ans]+=1
else: d[ans]=1
for i in range(m):
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,695,707,419 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 26 13:15:31 2023
@author: huangxiaoyuan
"""
s=input()
s=s.lower()#先把字符串变小写
list1=[]
str1='aeyoui'
for i in s:
if i not in str1:
list1+=i
str2=''
for j in list1:
str2+='.'
str2+=j
if len(s)<=100:
print(str2)
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 26 13:15:31 2023
@author: huangxiaoyuan
"""
s=input()
s=s.lower()#先把字符串变小写
list1=[]
str1='aeyoui'
for i in s:
if i not in str1:
list1+=i
str2=''
for j in list1:
str2+='.'
str2+=j
if len(s)<=100:
print(str2)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,689,941,654 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | e=int(input())
a=list(map(int,input().split()))
c=int(input())
b=list(map(int,input().split()))
for i in range(1,len(a)):
a[i]+=a[i-1]
print(a)
for i in range(c):
for j in range(1,e):
if a[j] > b[i] and a[j-1] < b[i]:
print(j+1)
... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
e=int(input())
a=list(map(int,input().split()))
c=int(input())
b=list(map(int,input().split()))
for i in range(1,len(a)):
a[i]+=a[i-1]
print(a)
for i in range(c):
for j in range(1,e):
if a[j] > b[i] and a[j-1] < b[i]:
pri... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,615,202,393 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | n,k=map(int,input().split())
t=2
s="1"
while n>1:
s=s+str(t)+s
t+=1
n=n-1
print(s[k-1])
| Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
n,k=map(int,input().split())
t=2
s="1"
while n>1:
s=s+str(t)+s
t+=1
n=n-1
print(s[k-1])
``` | 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,696,489,554 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | t = input()
s = input()
def translation_function(t):
t = t[::-1]
return t
if translation_function(t) == s:
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
t = input()
s = input()
def translation_function(t):
t = t[::-1]
return t
if translation_function(t) == s:
print("YES")
else:
print("NO")
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,694,155,786 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 124 | 0 | p=input()
a=len(p)
for i in range(len(p)):
if p[i]=='H' or p[i]=='Q' or p[i]=='9':
print("YES")
break
else:
a=a-1
if a==0:
print("NO")
| Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
p=input()
a=len(p)
for i in range(len(p)):
if p[i]=='H' or p[i]=='Q' or p[i]=='9':
print("YES")
break
else:
a=a-1
if a==0:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
846 | A | Curriculum Vitae | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. | Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | 0 | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,504,627,877 | 3,977 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | def proceed(str, idx, counts):
counts.append(len(str[:idx].replace('1', '') + str[idx:]))
return str[:idx] + str[idx + 1:]
n = int(input())
games = input().replace(' ', '')
bad_idxs = [n for n in range(len(games)) if games.find('10', n) == n]
if len(bad_idxs) == 0:
print(len(games))
else:
cou... | Title: Curriculum Vitae
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* g... | ```python
def proceed(str, idx, counts):
counts.append(len(str[:idx].replace('1', '') + str[idx:]))
return str[:idx] + str[idx + 1:]
n = int(input())
games = input().replace(' ', '')
bad_idxs = [n for n in range(len(games)) if games.find('10', n) == n]
if len(bad_idxs) == 0:
print(len(games))
else... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,677,948,265 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 93 | 3,686,400 | from sys import stdin
r=0
for _ in range(int(stdin.readline())):
a=stdin.readline()[0:1]
r+=20 if a=='I' else 6 if a=='C' else 4 if a=='T' else 12 if a=='D' else 8
print(r)
| Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
from sys import stdin
r=0
for _ in range(int(stdin.readline())):
a=stdin.readline()[0:1]
r+=20 if a=='I' else 6 if a=='C' else 4 if a=='T' else 12 if a=='D' else 8
print(r)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
316 | E1 | Summer Homework | PROGRAMMING | 1,500 | [
"brute force",
"data structures"
] | null | null | By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to perform on it *m* consecutive operations of the following type:
1. For given numbers *x**i* and *v**i* assign valu... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105). Then follow *m* lines, each describes an operation. Each line star... | For each query print the calculated sum modulo 1000000000 (109). | [
"5 5\n1 3 1 2 4\n2 1 4\n2 1 5\n2 2 4\n1 3 10\n2 1 5\n",
"5 4\n1 3 1 2 4\n3 1 4 1\n2 2 4\n1 2 10\n2 1 5\n"
] | [
"12\n32\n8\n50\n",
"12\n45\n"
] | none | 30 | [
{
"input": "5 5\n1 3 1 2 4\n2 1 4\n2 1 5\n2 2 4\n1 3 10\n2 1 5",
"output": "12\n32\n8\n50"
},
{
"input": "1 3\n2\n2 1 1\n1 1 3\n2 1 1",
"output": "2\n3"
},
{
"input": "11 11\n6 1 9 0 2 9 1 6 2 8 0\n2 9 9\n1 9 0\n1 1 8\n2 2 5\n2 7 11\n2 2 8\n1 3 2\n1 10 0\n2 1 8\n2 9 11\n1 9 7",
"outp... | 1,371,134,475 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS1 | 0 | 0 | 0 | #include <iostream>
using namespace std;
int main()
{
int n=0,m=0,a=0,b=0,c=0;
cin >> n >> m;
int* mas=new int[n];
int* fib=new int[n];
long long int ans=0;
fib[0]=fib[1]=1;
for(int i=2; i<=n; i++)
fib[i]=fib[i-1]+fib[i-2];
for(int i=1; i<=n; i++)
cin >> mas[i];
for(int i=0; i<m; i++)
{... | Title: Summer Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to perform on it *... | ```python
#include <iostream>
using namespace std;
int main()
{
int n=0,m=0,a=0,b=0,c=0;
cin >> n >> m;
int* mas=new int[n];
int* fib=new int[n];
long long int ans=0;
fib[0]=fib[1]=1;
for(int i=2; i<=n; i++)
fib[i]=fib[i-1]+fib[i-2];
for(int i=1; i<=n; i++)
cin >> mas[i];
for(int i=0; i<m... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,626,425,896 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 20,172,800 |
def main():
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(set(a))
mx = max(a)
n = len(a)
valid = False
for i in range(n):
num = mx - a[i]
statuses = []
for j in range(n):
if a[j] + a[i] == num or a[j] - a[i] == num or... | Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a... | ```python
def main():
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(set(a))
mx = max(a)
n = len(a)
valid = False
for i in range(n):
num = mx - a[i]
statuses = []
for j in range(n):
if a[j] + a[i] == num or a[j] - a[i]... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,677,778,399 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 77 | 0 | n, m = map(int, input().split())
tabuleiro = []
for i in range(n):
row = input()
tabuleiro.append(row)
resposta = [['-' for j in range(m)] for i in range(n)]
for i in range(n):
for j in range(m):
if tabuleiro[i][j] == '.' and resposta[i][j] == '-':
if (i + j) % 2 == 0:
... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
n, m = map(int, input().split())
tabuleiro = []
for i in range(n):
row = input()
tabuleiro.append(row)
resposta = [['-' for j in range(m)] for i in range(n)]
for i in range(n):
for j in range(m):
if tabuleiro[i][j] == '.' and resposta[i][j] == '-':
if (i + j) % 2 == 0:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
253 | B | Physics Practical | PROGRAMMING | 1,400 | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer — the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one... | 1,000 | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 ... | 1,685,560,646 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 372 | 13,107,200 | import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n = int(input())
res = [int(t) for t in input().split()]
res.sort()
min_erase = n
i, j = 0, 0
while i != n - 1:
if res[j] <= 2 * res[i]:
ans = True
if n - (j - i + 1) < min_erase:
min_erase = n... | Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he... | ```python
import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n = int(input())
res = [int(t) for t in input().split()]
res.sort()
min_erase = n
i, j = 0, 0
while i != n - 1:
if res[j] <= 2 * res[i]:
ans = True
if n - (j - i + 1) < min_erase:
min... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
607 | B | Zuma | PROGRAMMING | 1,900 | [
"dp"
] | null | null | Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to choose exactly one continuous substring of colored gemstones ... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=500) — the number of gemstones.
The second line contains *n* space-separated integers, the *i*-th of which is *c**i* (1<=≤<=*c**i*<=≤<=*n*) — the color of the *i*-th gemstone in a line. | Print a single integer — the minimum number of seconds needed to destroy the entire line. | [
"3\n1 2 1\n",
"3\n1 2 3\n",
"7\n1 4 4 2 3 2 1\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample, Genos can destroy the entire line in one second.
In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds.
In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 ... | 1,250 | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "7\n1 4 4 2 3 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
... | 1,696,306,331 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 2,662,400 | n = int(input())
arr = list(map(int, input().split()))
dp = [[n for _ in range(n)] for _ in range(n)]
for i in range(n - 1, -1, -1):
for j in range(i, n):
if i == j:
dp[i][j] = 1
elif i + 1 == j:
if arr[i] == arr[j]:
dp[i][j] = 1
else:
... | Title: Zuma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In ... | ```python
n = int(input())
arr = list(map(int, input().split()))
dp = [[n for _ in range(n)] for _ in range(n)]
for i in range(n - 1, -1, -1):
for j in range(i, n):
if i == j:
dp[i][j] = 1
elif i + 1 == j:
if arr[i] == arr[j]:
dp[i][j] = 1
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,591,957,944 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | n,k=map(int,input().split())
c=d=i=0
while(n>=k):
if i%2==0 :
c+=1
else:
d+=1
i+=1
n-=k
if c>d:
print("YES")
else:
print("NO")
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
n,k=map(int,input().split())
c=d=i=0
while(n>=k):
if i%2==0 :
c+=1
else:
d+=1
i+=1
n-=k
if c>d:
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,585,726,911 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 124 | 307,200 | #Codeforce 987A
dict1={"purple":"Power","green":"Time","blue":"Space","orange":"Soul","red":"Reality","yellow":"Mind"}
list1=["purple","green","blue","orange","red","yellow"]
list2=[]
x=int(input())
for i in range(x):
gem=input().strip("\n\r")
list1.remove(gem)
print(len(list1))
for j in range(len(lis... | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
#Codeforce 987A
dict1={"purple":"Power","green":"Time","blue":"Space","orange":"Soul","red":"Reality","yellow":"Mind"}
list1=["purple","green","blue","orange","red","yellow"]
list2=[]
x=int(input())
for i in range(x):
gem=input().strip("\n\r")
list1.remove(gem)
print(len(list1))
for j in ran... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
230 | A | Dragons | PROGRAMMING | 1,000 | [
"greedy",
"sortings"
] | null | null | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit... | The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | [
"2 2\n1 99\n100 0\n",
"10 1\n100 100\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | 500 | [
{
"input": "2 2\n1 99\n100 0",
"output": "YES"
},
{
"input": "10 1\n100 100",
"output": "NO"
},
{
"input": "123 2\n78 10\n130 0",
"output": "YES"
},
{
"input": "999 2\n1010 10\n67 89",
"output": "YES"
},
{
"input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1",
"output": "YE... | 1,697,619,287 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | s,n=map(int,input().split())
d=[]
m=[]
for x in range(n):
b,c=map(int,input().split())
d.append(b)
m.append(c)
d.sort()
for y in range(len(d)):
if s>d[y]:
s+=m[y]
else:
print('NO')
exit()
print('YES') | Title: Dragons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the du... | ```python
s,n=map(int,input().split())
d=[]
m=[]
for x in range(n):
b,c=map(int,input().split())
d.append(b)
m.append(c)
d.sort()
for y in range(len(d)):
if s>d[y]:
s+=m[y]
else:
print('NO')
exit()
print('YES')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to he... | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x... | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
... | 1,685,127,606 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | a, b = map(int, input().split())
v = []
ok = 1
while b > a:
v.append(b)
if b & 1 == 0:
b //= 2
elif b % 10 == 1:
b //= 10
else:
ok = 0
break
if b != a:
ok = 0
else:
v.append(a)
if not ok:
print("NO")
else:
print("YES")
print(len(v))
print(*v[::-1])... | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app... | ```python
a, b = map(int, input().split())
v = []
ok = 1
while b > a:
v.append(b)
if b & 1 == 0:
b //= 2
elif b % 10 == 1:
b //= 10
else:
ok = 0
break
if b != a:
ok = 0
else:
v.append(a)
if not ok:
print("NO")
else:
print("YES")
print(len(v))
print... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
39 | J | Spelling Check | PROGRAMMING | 1,500 | [
"hashing",
"implementation",
"strings"
] | J. Spelling Check | 2 | 256 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d... | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible... | [
"abdrakadabra\nabrakadabra\n",
"aa\na\n",
"competition\ncodeforces\n"
] | [
"1\n3\n",
"2\n1 2\n",
"0\n"
] | none | 0 | [
{
"input": "abdrakadabra\nabrakadabra",
"output": "1\n3 "
},
{
"input": "aa\na",
"output": "2\n1 2 "
},
{
"input": "competition\ncodeforces",
"output": "0"
},
{
"input": "ab\na",
"output": "1\n2 "
},
{
"input": "bb\nb",
"output": "2\n1 2 "
},
{
"input"... | 1,680,365,117 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | """
https://vjudge.net/problem/CodeForces-39J
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds
extra letters to the words. Of course, the spell-checking system underlines the words for him
and he has to click every word and choose the right variant. Petya got fed up w... | Title: Spelling Check
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and ... | ```python
"""
https://vjudge.net/problem/CodeForces-39J
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds
extra letters to the words. Of course, the spell-checking system underlines the words for him
and he has to click every word and choose the right variant. Petya go... | 0 | MatrixStudio/Codeforces-Python-Submissions |
248 | B | Chilly Willy | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.
Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous... | A single input line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist. | [
"1\n",
"5\n"
] | [
"-1\n",
"10080"
] | none | 1,000 | [
{
"input": "1",
"output": "-1"
},
{
"input": "5",
"output": "10080"
},
{
"input": "6",
"output": "100170"
},
{
"input": "4",
"output": "1050"
},
{
"input": "15",
"output": "100000000000110"
},
{
"input": "16",
"output": "1000000000000050"
},
{
... | 1,627,402,572 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,758,400 | n = int(input())
z = 10**(n-1)
print(z+(210-z%210))
| Title: Chilly Willy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected wit... | ```python
n = int(input())
z = 10**(n-1)
print(z+(210-z%210))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
171 | B | Star | PROGRAMMING | 1,300 | [
"*special",
"combinatorics"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257). | Print a single integer *output* (1<=≤<=*output*<=≤<=2·109). | [
"2\n"
] | [
"13"
] | none | 0 | [
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"... | 1,617,245,677 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 154 | 0 | n = int(input())
print(1+6*(n**2-n)) | Title: Star
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Output Specification:
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
Demo Input:
['2\n']
Demo Output:
['13']
Note:
none | ```python
n = int(input())
print(1+6*(n**2-n))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | ||
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,529,126,606 | 3,086 | PyPy 3 | RUNTIME_ERROR | TESTS | 24 | 295 | 26,726,400 | def dfs(d,curr,parent):
d[curr].remove(parent)
for i in d[curr]:
dfs(d,i,curr)
def solve(d,curr,colors,count):
if d[curr]!=set():
for i in d[curr]:
if colors[curr-1]!=colors[i-1]:
count[0]+=1
solve(d,i,colors,count)
n=int(input... | Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
def dfs(d,curr,parent):
d[curr].remove(parent)
for i in d[curr]:
dfs(d,i,curr)
def solve(d,curr,colors,count):
if d[curr]!=set():
for i in d[curr]:
if colors[curr-1]!=colors[i-1]:
count[0]+=1
solve(d,i,colors,count)
n... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
560 | B | Gerald is into Art | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rec... | The first line contains two space-separated numbers *a*1 and *b*1 — the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 — the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000. | If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes). | [
"3 2\n1 3\n2 1\n",
"5 5\n3 3\n3 3\n",
"4 2\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | That's how we can place the pictures in the first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's how we can do it in the third one.
<img class="tex-graphics" src="https://espresso.codeforces... | 1,000 | [
{
"input": "3 2\n1 3\n2 1",
"output": "YES"
},
{
"input": "5 5\n3 3\n3 3",
"output": "NO"
},
{
"input": "4 2\n2 3\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 1",
"output": "YES"
},
{
"input": "1000 1000\n999 999\n1 1000",
"output": "YES"
},
{
"in... | 1,643,992,339 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def check():
s = input()
a1 = int(s.split()[0])
b1 = int(s.split()[1])
s = input()
a2 = int(s.split()[0])
b2 = int(s.split()[1])
s = input()
a3 = int(s.split()[0])
b3 = int(s.split()[1])
painting_sides = [a2, b2, a3, b3]
for i in painting_sides:
if i>a1 and i>b1:
... | Title: Gerald is into Art
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board ha... | ```python
def check():
s = input()
a1 = int(s.split()[0])
b1 = int(s.split()[1])
s = input()
a2 = int(s.split()[0])
b2 = int(s.split()[1])
s = input()
a3 = int(s.split()[0])
b3 = int(s.split()[1])
painting_sides = [a2, b2, a3, b3]
for i in painting_sides:
if i>a1 and... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,659,791,454 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | from curses.ascii import islower
from curses import *
i = input()
l = 0
u = 0
for j in i:
if j.islower() == TRUE:
l += 1
else :
u += 1
if l>u:
print(i.lower())
elif l==u :
print(i.lower())
else:
print(i.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
from curses.ascii import islower
from curses import *
i = input()
l = 0
u = 0
for j in i:
if j.islower() == TRUE:
l += 1
else :
u += 1
if l>u:
print(i.lower())
elif l==u :
print(i.lower())
else:
print(i.upper())
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
0 | none | none | none | 0 | [
"none"
] | null | null | В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии конец первого сообщения совмещается с началом второго. Конечно, совмещение мо... | В единственной строке выходных данных следует непустая строка *t*, состоящая из строчных букв латинского алфавита. Длина строки *t* не превосходит 100 символов. | Если сообщение *t* не может содержать ошибки, выведите «NO» (без кавычек) в единственную строку выходных данных.
В противном случае в первой строке выведите «YES» (без кавычек), а в следующей строке выведите строку *s* — возможное сообщение, которое могло привести к ошибке. Если возможных ответов несколько, разрешаетс... | [
"abrakadabrabrakadabra\n",
"acacacaca\n",
"abcabc\n",
"abababab\n",
"tatbt\n"
] | [
"YES\nabrakadabra\n",
"YES\nacaca\n",
"NO\n",
"YES\nababab\n",
"NO\n"
] | Во втором примере подходящим ответом также является строка acacaca. | 0 | [
{
"input": "abrakadabrabrakadabra",
"output": "YES\nabrakadabra"
},
{
"input": "acacacaca",
"output": "YES\nacaca"
},
{
"input": "abcabc",
"output": "NO"
},
{
"input": "abababab",
"output": "YES\nababab"
},
{
"input": "tatbt",
"output": "NO"
},
{
"inpu... | 1,458,732,136 | 163,336 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 61 | 4,608,000 | t=input()
l=len(t)-1
flag=False
while l > 1:
s=t[:l+1]
k=1
while k<(len(t)-l):
if s==t[k:k+l+1]:
flag=True
break
k+=1
if flag==True:
break
else:
l-=1
if flag==True:
print('YES')
print(s)
else:
print('NO'... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При т... | ```python
t=input()
l=len(t)-1
flag=False
while l > 1:
s=t[:l+1]
k=1
while k<(len(t)-l):
if s==t[k:k+l+1]:
flag=True
break
k+=1
if flag==True:
break
else:
l-=1
if flag==True:
print('YES')
print(s)
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | 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*. | 500 | [
{
"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,652,111,022 | 222 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 512,000 | n = int(input())
for i in range(1, n):
if len(str(i)) == 1:
if i*2 == n:
print(i)
if len(str(i)) == 2:
if int(str(i)[0])+int(str(i)[1])+i == n:
print(i)
if len(str(i)) == 3:
if int(str(i)[0])+int(str(i)[1])+int(str(i)[2])+i == n:
print(i)... | Title: Classroom Watch
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 answe... | ```python
n = int(input())
for i in range(1, n):
if len(str(i)) == 1:
if i*2 == n:
print(i)
if len(str(i)) == 2:
if int(str(i)[0])+int(str(i)[1])+i == n:
print(i)
if len(str(i)) == 3:
if int(str(i)[0])+int(str(i)[1])+int(str(i)[2])+i == n:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,687,115,754 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n = int(input())
for i in range(n):
line = input()
if(i == 0):
x = line[i]
otherLetter = line[i+1]
if(line[i] != x and line[n-1-i] != x):
print("NO")
exit()
for letter in line:
if(letter != x and letter != otherLetter):
print("NO... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
for i in range(n):
line = input()
if(i == 0):
x = line[i]
otherLetter = line[i+1]
if(line[i] != x and line[n-1-i] != x):
print("NO")
exit()
for letter in line:
if(letter != x and letter != otherLetter):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,681,029,614 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 186 | 12,800,000 | from sys import stdin
def input(): return stdin.readline()[:-1]
a=input()
b=input()
la=len(a)
lb=len(b)
if la!=lb:
print("NO")
exit()
c=0
for i in range(la):
if a[i]!=b[i]:
c+=1
if c==2 and sorted(a)==sorted(b):
print("YES")
else:
print("NO") | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
from sys import stdin
def input(): return stdin.readline()[:-1]
a=input()
b=input()
la=len(a)
lb=len(b)
if la!=lb:
print("NO")
exit()
c=0
for i in range(la):
if a[i]!=b[i]:
c+=1
if c==2 and sorted(a)==sorted(b):
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,695,401,156 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 108 | 1,945,600 | import math
from sys import stdin, stdout
# for i in range(0, int(input()), 1):
p = [int(x) for x in stdin.readline().split()]
a = input()
answer = 0
for element in range (0, len(a), 1):
answer += p[int(a[element]) - 1]
print(answer) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
import math
from sys import stdin, stdout
# for i in range(0, int(input()), 1):
p = [int(x) for x in stdin.readline().split()]
a = input()
answer = 0
for element in range (0, len(a), 1):
answer += p[int(a[element]) - 1]
print(answer)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,505,392,323 | 423 | Python 3 | OK | TESTS | 26 | 61 | 0 | n=int(input())
x=int(n/2)
if n%2!=0:
print(str(x)+" "+str(x+1))
else:
if n%4==0:
print(str(x-1)+" "+str(x+1))
else:
print(str(x-2)+" "+str(x+2)) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
n=int(input())
x=int(n/2)
if n%2!=0:
print(str(x)+" "+str(x+1))
else:
if n%4==0:
print(str(x-1)+" "+str(x+1))
else:
print(str(x-2)+" "+str(x+2))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "37546069... | 1,571,232,176 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 124 | 0 | n = int(input())+1
if n % 2 == 0:
n /= 2
print(int(n))
| Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthd... | ```python
n = int(input())+1
if n % 2 == 0:
n /= 2
print(int(n))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
743 | C | Vladik and fractions | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null | Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form .
Help Vladik with that, i.e for a given *n* find three distinct positive integers *x*, *y* and *z* such that . Because ... | The single line contains single integer *n* (1<=≤<=*n*<=≤<=104). | If the answer exists, print 3 distinct numbers *x*, *y* and *z* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=109, *x*<=≠<=*y*, *x*<=≠<=*z*, *y*<=≠<=*z*). Otherwise print -1.
If there are multiple answers, print any of them. | [
"3\n",
"7\n"
] | [
"2 7 42\n",
"7 8 56\n"
] | none | 1,250 | [
{
"input": "3",
"output": "2 7 42"
},
{
"input": "7",
"output": "7 8 56"
},
{
"input": "2",
"output": "2 3 6"
},
{
"input": "5",
"output": "5 6 30"
},
{
"input": "4",
"output": "4 5 20"
},
{
"input": "7",
"output": "7 8 56"
},
{
"input": "8... | 1,588,831,678 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 108 | 6,656,000 | def solve():
n = int(input())
current = n + 1
product = n * current
while 2 * (product // n) != product // n + product // current + 1:
current += 1
product = n * current
print("{} {} {}".format(n, current, product))
solve() | Title: Vladik and fractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form .
Help Vladik ... | ```python
def solve():
n = int(input())
current = n + 1
product = n * current
while 2 * (product // n) != product // n + product // current + 1:
current += 1
product = n * current
print("{} {} {}".format(n, current, product))
solve()
``` | 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,595,245,768 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 7,065,600 | from collections import OrderedDict
s=input()
def rd(s):
return ''.join(OrderedDict.fromkeys(s))
print(rd(s))
t=list(rd(s))
#print(''.join(t))
r='hello'
p= list(r)
q='helo'
w=list(q)
if q in rd(s):
print(t)
i=0
for i in range(0,len(t)-1):
if t[i]=='l':
t.insert(... | 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
from collections import OrderedDict
s=input()
def rd(s):
return ''.join(OrderedDict.fromkeys(s))
print(rd(s))
t=list(rd(s))
#print(''.join(t))
r='hello'
p= list(r)
q='helo'
w=list(q)
if q in rd(s):
print(t)
i=0
for i in range(0,len(t)-1):
if t[i]=='l':
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,565,551,661 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | o = int(input())
o2 = [int(y) for y in input().split()]
c=0
c+= o2.count(3)
c+= o2.count(2)
if c == 0:
print(1)
else:
print(c)
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
o = int(input())
o2 = [int(y) for y in input().split()]
c=0
c+= o2.count(3)
c+= o2.count(2)
if c == 0:
print(1)
else:
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,679,235,598 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n=int(input())
points = list(map(int,input().strip().split()))[:n]
ans=-1
e=0
o=0
for j in range(n):
if(points[j]%2==0):
e+=1
else:
o+=1
ev=max(e,o)
for j in range(n):
if(points[j]%2!=ev):
ans=j+1
break
print(ans)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
points = list(map(int,input().strip().split()))[:n]
ans=-1
e=0
o=0
for j in range(n):
if(points[j]%2==0):
e+=1
else:
o+=1
ev=max(e,o)
for j in range(n):
if(points[j]%2!=ev):
ans=j+1
break
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
252 | A | Little Xor | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that.
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230. | Print a single integer — the required maximal *xor* of a segment of consecutive elements. | [
"5\n1 2 1 1 2\n",
"3\n1 2 7\n",
"4\n4 2 4 8\n"
] | [
"3\n",
"7\n",
"14\n"
] | In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.
The second sample contains only one optimal segment, which contains exactly one array element (element with index three). | 500 | [
{
"input": "5\n1 2 1 1 2",
"output": "3"
},
{
"input": "3\n1 2 7",
"output": "7"
},
{
"input": "4\n4 2 4 8",
"output": "14"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "15"
},
{
"inpu... | 1,402,858,741 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 154 | 0 | n = int(input())
a = [int(i) for i in input().split()]
pref = [0] * (n + 1)
for i in range(n):
pref[i + 1] = pref[i] ^ a[i]
res = a[0]
for i in range(n):
for j in range(i, n):
res = max(res, pref[j + 1] ^ pref[i])
print(res) | Title: Little Xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, ... | ```python
n = int(input())
a = [int(i) for i in input().split()]
pref = [0] * (n + 1)
for i in range(n):
pref[i + 1] = pref[i] ^ a[i]
res = a[0]
for i in range(n):
for j in range(i, n):
res = max(res, pref[j + 1] ^ pref[i])
print(res)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,674,582,750 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | x,y = map(int,input().split())
b=0
for i in range(x):
if i % 2 == 0:
print('#'*y)
else:
if b == 0:
print('.'*(y-1)+'#')
b= 1
else:
b = 0
print('#'+'.'*(y-1))
| Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
x,y = map(int,input().split())
b=0
for i in range(x):
if i % 2 == 0:
print('#'*y)
else:
if b == 0:
print('.'*(y-1)+'#')
b= 1
else:
b = 0
print('#'+'.'*(y-1))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,686,321,184 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | z=[*map(int, input().split())]
for i in range(1,10):
if ((z[0]*i)-z[1])%10==0 or (z[0]*i)%10==0 : break
print (min(10,i)) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
z=[*map(int, input().split())]
for i in range(1,10):
if ((z[0]*i)-z[1])%10==0 or (z[0]*i)%10==0 : break
print (min(10,i))
``` | 3 | 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,656,703,646 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | (n, m) = map(int, input().split(' '))
s = input()
s_to_l = list(s)
for i in range(m):
l_r_c1_c2 = input().split(' ')
l = int(l_r_c1_c2[0])
r = int(l_r_c1_c2[1])
c1 = str(l_r_c1_c2[2])
c2 = str(l_r_c1_c2[3])
s = s[: l - 1] + s[l - 1: r].replace(c1, c2) + s[r:]
print(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
(n, m) = map(int, input().split(' '))
s = input()
s_to_l = list(s)
for i in range(m):
l_r_c1_c2 = input().split(' ')
l = int(l_r_c1_c2[0])
r = int(l_r_c1_c2[1])
c1 = str(l_r_c1_c2[2])
c2 = str(l_r_c1_c2[3])
s = s[: l - 1] + s[l - 1: r].replace(c1, c2) + s[r:]
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other ... | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3... | 1,634,522,433 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 155 | 14,233,600 | n_subs, hours = [int(x) for x in input().split()]
subjects = [int(x) for x in input().split()]
subjects.sort()
if hours >= len(subjects):
decreasing_time = list(range(hours, 0, -1))
subjects = [x * decreasing_time[i] for i,x in enumerate(subjects)]
result = sum(subjects)
else:
decreasing_time = list(ran... | Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co... | ```python
n_subs, hours = [int(x) for x in input().split()]
subjects = [int(x) for x in input().split()]
subjects.sort()
if hours >= len(subjects):
decreasing_time = list(range(hours, 0, -1))
subjects = [x * decreasing_time[i] for i,x in enumerate(subjects)]
result = sum(subjects)
else:
decreasing_time ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in *t* minutes. There is a straight road of length *s* from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point... | The first line contains four positive integers *n*, *k*, *s* and *t* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*k*<=≤<=2·105, 2<=≤<=*s*<=≤<=109, 1<=≤<=*t*<=≤<=2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the n... | Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in *t* minutes). If there is no appropriate car, print -1. | [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n"
] | [
"10\n",
"20\n"
] | In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. Aft... | 0 | [
{
"input": "3 1 8 10\n10 8\n5 7\n11 9\n3",
"output": "10"
},
{
"input": "2 2 10 18\n10 4\n20 6\n5 3",
"output": "20"
},
{
"input": "2 1 1000000000 2000000000\n111 1000000000\n101 1000000000\n5",
"output": "101"
},
{
"input": "2 1 1000000000 2000000000\n111 999999998\n101 9999... | 1,689,443,033 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689443033.8954937")# 1689443033.895514 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in *t* minutes. There is a straight road of length *s* from the service to the cinema. Let's introduce a coordina... | ```python
print("_RANDOM_GUESS_1689443033.8954937")# 1689443033.895514
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",... | 1,571,388,843 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x=int(input())
y=int(input())
n=x-y-1
if y=n+1,x=2(n)+y-1:
print("yes")
else:
print("no") | Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie... | ```python
x=int(input())
y=int(input())
n=x-y-1
if y=n+1,x=2(n)+y-1:
print("yes")
else:
print("no")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,629,702,005 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 218 | 20,172,800 | from collections import Counter
n,s=int(input()),Counter(input())
if len(set(s.values()))==1 and len(s)==n:
s1=''.join(s.keys())
print(s1*n)
else:print(-1) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
from collections import Counter
n,s=int(input()),Counter(input())
if len(set(s.values()))==1 and len(s)==n:
s1=''.join(s.keys())
print(s1*n)
else:print(-1)
``` | 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,503,598,421 | 5,921 | Python 3 | OK | TESTS | 41 | 62 | 0 | s = input()
k = int(input())
arr = []
for elem in s:
arr.append(elem)
arr = set(arr)
d = k - len(arr)
if k > len(s):
print('impossible')
else:
print(max(d, 0))
| 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
s = input()
k = int(input())
arr = []
for elem in s:
arr.append(elem)
arr = set(arr)
d = k - len(arr)
if k > len(s):
print('impossible')
else:
print(max(d, 0))
``` | 3 | 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,697,706,106 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a=set(input())
print(len(a)-3) | 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
a=set(input())
print(len(a)-3)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,627,554,326 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 20,172,800 | # author: violist
# created: 29.07.2021 12:17:59
import sys
input = sys.stdin.readline
s = input()[:-1]
samohlasky = ["A", "E", "I", "O", "U", "Y"]
pos = []
for i in range(len(s)):
if (s[i] in samohlasky):
pos.append(i)
diff = []
for i in range(len(pos) - 1):
diff.append(abs(pos[i] - pos[i + 1]))
p... | Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
# author: violist
# created: 29.07.2021 12:17:59
import sys
input = sys.stdin.readline
s = input()[:-1]
samohlasky = ["A", "E", "I", "O", "U", "Y"]
pos = []
for i in range(len(s)):
if (s[i] in samohlasky):
pos.append(i)
diff = []
for i in range(len(pos) - 1):
diff.append(abs(pos[i] - pos[... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,687,624,865 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | n=int(input())
count=0
for i in range(n):
a,b=[int(i) for i in input().split()]
if (b-a)>=2:
count+=1
print(count) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
n=int(input())
count=0
for i in range(n):
a,b=[int(i) for i in input().split()]
if (b-a)>=2:
count+=1
print(count)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,654,624,264 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n, a, b = map(int, raw_input().split())
a-=1
a+=b
a%=n
a+=1
print a
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
n, a, b = map(int, raw_input().split())
a-=1
a+=b
a%=n
a+=1
print a
``` | -1 | 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,694,311,341 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | l=list(map(str,input().split()))
s=set(l)
print(len(s))
| 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
l=list(map(str,input().split()))
s=set(l)
print(len(s))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 0 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,510,901,787 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 14,233,600 | n=int(input())
m=0
a=list(map(int,input().split()))
a.reverse()
for i in range(0,n):
if a.count(a[i])>1 and a.index(a[i])!=i :
a[i]=0
a.reverse()
for i in range(n-1,-1,-1):
if a[i]!=0:
m=a[i]
print(m)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First o... | ```python
n=int(input())
m=0
a=list(map(int,input().split()))
a.reverse()
for i in range(0,n):
if a.count(a[i])>1 and a.index(a[i])!=i :
a[i]=0
a.reverse()
for i in range(n-1,-1,-1):
if a[i]!=0:
m=a[i]
print(m)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,684,590,242 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 296 | 14,848,000 | n = int(input())
laptops = []
for _ in range(n):
ai, bi = map(int, input().split())
laptops.append((ai, bi))
laptops.sort()
for i in range(n-1):
if laptops[i][1] > laptops[i+1][1]:
print("Happy Alex")
exit()
print("Poor Alex")
| Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n = int(input())
laptops = []
for _ in range(n):
ai, bi = map(int, input().split())
laptops.append((ai, bi))
laptops.sort()
for i in range(n-1):
if laptops[i][1] > laptops[i+1][1]:
print("Happy Alex")
exit()
print("Poor Alex")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
637 | A | Voting for Photos | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms",
"implementation"
] | null | null | After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like. | Print the identifier of the photo which won the elections. | [
"5\n1 3 2 2 1\n",
"9\n100 200 300 200 100 300 300 100 200\n"
] | [
"2\n",
"300\n"
] | In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
- more likes than the photo with id 3; - as many likes as the photo with id 1, but t... | 500 | [
{
"input": "5\n1 3 2 2 1",
"output": "2"
},
{
"input": "9\n100 200 300 200 100 300 300 100 200",
"output": "300"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "5\n1 3 4 2 2",
"output": "2"
},
{
"input... | 1,535,713,347 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 124 | 0 | n = int(input())
a = list(map(int, input().split()))
p = {}
for i in range(n):
if a[i] in p:
p[a[i]] += 1
else:
p[a[i]] = 1
b = max(p[i] for i in p)
for i in p:
p[i] = 0
for i in a:
p[i] += 1
if p[i] == b:
print(i)
exit(0) | Title: Voting for Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rule... | ```python
n = int(input())
a = list(map(int, input().split()))
p = {}
for i in range(n):
if a[i] in p:
p[a[i]] += 1
else:
p[a[i]] = 1
b = max(p[i] for i in p)
for i in p:
p[i] = 0
for i in a:
p[i] += 1
if p[i] == b:
print(i)
exit(0)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
522 | B | Photo to Remember | PROGRAMMING | 1,100 | [
"*special",
"data structures",
"dp",
"implementation"
] | null | null | One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangl... | The first line contains integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of friends.
Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=10,<=1<=≤<=*h**i*<=≤<=1000) — the width and height in pixels of the correspo... | Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* — the total number of pixels on the minimum photo containing all friends expect for the *i*-th one. | [
"3\n1 10\n5 5\n10 1\n",
"3\n2 1\n1 2\n2 1\n"
] | [
"75 110 60 ",
"6 4 6 "
] | none | 1,000 | [
{
"input": "3\n1 10\n5 5\n10 1",
"output": "75 110 60 "
},
{
"input": "3\n2 1\n1 2\n2 1",
"output": "6 4 6 "
},
{
"input": "2\n1 5\n2 3",
"output": "6 5 "
},
{
"input": "2\n2 3\n1 1",
"output": "1 6 "
},
{
"input": "3\n1 10\n2 10\n3 10",
"output": "50 40 30 "
... | 1,687,663,672 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 102,400 | def heapify(arr, n, i):
largest = i
l = 2 * i + 1
r = 2 * i + 2
if l < n and arr[i] < arr[l]:
largest = l
if r < n and arr[largest] < arr[r]:
largest = r
if largest != i:
(arr[i], arr[largest]) = (arr[largest], arr[i])
heapify(arr, n, largest)
def heapSort(arr):
n = len(arr)... | Title: Photo to Remember
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the p... | ```python
def heapify(arr, n, i):
largest = i
l = 2 * i + 1
r = 2 * i + 2
if l < n and arr[i] < arr[l]:
largest = l
if r < n and arr[largest] < arr[r]:
largest = r
if largest != i:
(arr[i], arr[largest]) = (arr[largest], arr[i])
heapify(arr, n, largest)
def heapSort(arr):
n ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number t... | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the nu... | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
... | 1,659,026,711 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | n = int(input())
s = {}
for i in range(n):
x = int(input())
if(x not in s):
s.update({x:1})
else:
s[x] += 1
k = [*s.keys()]
if(len(k)==2 and s[k[0]]-s[k[1]]==0):
print("YES");print(*k)
else:
print("NO") | Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (di... | ```python
n = int(input())
s = {}
for i in range(n):
x = int(input())
if(x not in s):
s.update({x:1})
else:
s[x] += 1
k = [*s.keys()]
if(len(k)==2 and s[k[0]]-s[k[1]]==0):
print("YES");print(*k)
else:
print("NO")
``` | 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,604,735,526 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 0 | n=int(input(""))
s1=str(input(""))
s2=str(input(""))
b=0
for i in range (n):
a=abs(int(s1[i])-int(s2[i]))
if a>5: a=10-a
b=b+a
print(b)
exit()
| 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(""))
s1=str(input(""))
s2=str(input(""))
b=0
for i in range (n):
a=abs(int(s1[i])-int(s2[i]))
if a>5: a=10-a
b=b+a
print(b)
exit()
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,644,466,072 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 186 | 2,252,800 | n= int(input())
print(*[n]+list(range(1,n))) | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
n= int(input())
print(*[n]+list(range(1,n)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,648,484,528 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 154 | 102,400 | from collections import Counter
def solve():
K = int(input())
org = input()
data = Counter(org)
array = []
for key in data.keys():
if data[key] % K != 0:
return -1
else:
array.append(key*(data[key]//K))
array.sort()
output = ""
... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
from collections import Counter
def solve():
K = int(input())
org = input()
data = Counter(org)
array = []
for key in data.keys():
if data[key] % K != 0:
return -1
else:
array.append(key*(data[key]//K))
array.sort()
ou... | 3 | 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,667,053,639 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 31 | 0 | s = input()
a = []
for i in range(len(s)):
if s[i] == 'h' and 1 not in a:
a.append(1)
elif s[i] == 'e' and a[-1] == 1:
a.append(2)
elif s[i] == 'l' and a[-1] == 2:
a.append(3)
elif s[i] == 'l' and a[-1] == 3:
a.append(4)
elif s[i] == 'o' and a[-1] == 4:
... | 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()
a = []
for i in range(len(s)):
if s[i] == 'h' and 1 not in a:
a.append(1)
elif s[i] == 'e' and a[-1] == 1:
a.append(2)
elif s[i] == 'l' and a[-1] == 2:
a.append(3)
elif s[i] == 'l' and a[-1] == 3:
a.append(4)
elif s[i] == 'o' and a[-1]... | -1 | MatrixStudio/Codeforces-Python-Submissions |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,646,893,476 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 11,776,000 | n = int(input())
if n==1:
print("a")
else:
s = "ab"
i = 0
while len(s)<n:
if s[i]=="a":
s+="b"
else:
s+="a"
i+=1
print(s)
| Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n = int(input())
if n==1:
print("a")
else:
s = "ab"
i = 0
while len(s)<n:
if s[i]=="a":
s+="b"
else:
s+="a"
i+=1
print(s)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
900 | A | Find Extra One | PROGRAMMING | 800 | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. | Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | 500 | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1... | 1,622,446,788 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
c = 0
k =0
for i in range(n):
x,y = map(int,input().split())
if x>0:
c+=1
else:
k+=1
if c-k>1 or k-c>1:
print('YES')
else:
print('NO') | Title: Find Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
Input Specification:
The first li... | ```python
n = int(input())
c = 0
k =0
for i in range(n):
x,y = map(int,input().split())
if x>0:
c+=1
else:
k+=1
if c-k>1 or k-c>1:
print('YES')
else:
print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,583,489,283 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 0 | n = int(input())
aa = list(map(int, input().split()))
a, b = map(int, input().split())
x = b-a
ans = 0
for i in range(x):
ans += aa[i]
print (ans) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
n = int(input())
aa = list(map(int, input().split()))
a, b = map(int, input().split())
x = b-a
ans = 0
for i in range(x):
ans += aa[i]
print (ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
796 | B | Find The Bone | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*.
The problematic bone is initially at the position *x*<==<=1. Zane will co... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.
The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*... | Print one integer — the final position along the *x*-axis of the bone. | [
"7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"5 1 2\n2\n1 2\n2 4\n"
] | [
"1",
"2"
] | In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively.
In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground. | 750 | [
{
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1",
"output": "1"
},
{
"input": "5 1 2\n2\n1 2\n2 4",
"output": "2"
},
{
"input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11",
"output": "55"
},
{
"input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5... | 1,683,774,815 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n,m,k = map(int, input().split())
holes = list(map(int, input().split()))
pos = 1
cups = [0] * n
cups[0] = 1
for h in holes:
cups[h-1] = -1
for u,v in range(k):
u, v = map(int, input().split())
if cups[u-1] == 1:
if cups[v-1] == 0:
pos = v
cups[u-1], cups[v-1] = c... | Title: Find The Bone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t... | ```python
n,m,k = map(int, input().split())
holes = list(map(int, input().split()))
pos = 1
cups = [0] * n
cups[0] = 1
for h in holes:
cups[h-1] = -1
for u,v in range(k):
u, v = map(int, input().split())
if cups[u-1] == 1:
if cups[v-1] == 0:
pos = v
cups[u-1], cup... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
303 | A | Lucky Permutation Triple | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not.
A permutation triple of permutations of length *n* (*a*,<=... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | If no Lucky Permutation Triple of length *n* exists print -1.
Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*.
If there are multiple solutions, print any of them. | [
"5\n",
"2\n"
] | [
"1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n",
"-1\n"
] | In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img... | 500 | [
{
"input": "5",
"output": "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3"
},
{
"input": "2",
"output": "-1"
},
{
"input": "8",
"output": "-1"
},
{
"input": "9",
"output": "0 1 2 3 4 5 6 7 8 \n0 1 2 3 4 5 6 7 8 \n0 2 4 6 8 1 3 5 7 "
},
{
"input": "2",
"output": "-1"
},
{... | 1,592,756,950 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 966 | 307,200 | def prnt(j):
for i in range(j):
print(i,end=" ")
print()
return
def triplet(n):
if n%2!=0:
prnt(n)
prnt(n)
for i in range(n):
num=i+i
if num>=n:
num=num-n
print(num,end=" ")
else:
print("-1")
... | Title: Lucky Permutation Triple
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of lengt... | ```python
def prnt(j):
for i in range(j):
print(i,end=" ")
print()
return
def triplet(n):
if n%2!=0:
prnt(n)
prnt(n)
for i in range(n):
num=i+i
if num>=n:
num=num-n
print(num,end=" ")
else:
pri... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,642,020,614 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 31 | 186 | 4,915,200 | a=input()
b=input()
if len(a) != len(b):
print("NO")
else:
diff = []
for i in range(len(a)):
if a[i] != b[i]:
diff.append([a[i], b[i]])
alis = [p for p in a]
if len(diff) == 2:
if diff[0][0] == diff[1][-1] and diff[0][-1] == diff[1][0]:
print("YES")
elif len(diff) == 0 and len(set(alis... | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
a=input()
b=input()
if len(a) != len(b):
print("NO")
else:
diff = []
for i in range(len(a)):
if a[i] != b[i]:
diff.append([a[i], b[i]])
alis = [p for p in a]
if len(diff) == 2:
if diff[0][0] == diff[1][-1] and diff[0][-1] == diff[1][0]:
print("YES")
elif len(diff) == 0 and le... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
776 | C | Molly's Chemicals | PROGRAMMING | 1,800 | [
"binary search",
"brute force",
"data structures",
"implementation",
"math"
] | null | null | Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total ... | The first line of input contains two integers, *n* and *k*, the number of chemicals and the number, such that the total affection value is a non-negative power of this number *k*. (1<=≤<=*n*<=≤<=105, 1<=≤<=|*k*|<=≤<=10).
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — affecti... | Output a single integer — the number of valid segments. | [
"4 2\n2 2 2 2\n",
"4 -3\n3 -6 -3 12\n"
] | [
"8\n",
"3\n"
] | Do keep in mind that *k*<sup class="upper-index">0</sup> = 1.
In the first sample, Molly can get following different affection values:
- 2: segments [1, 1], [2, 2], [3, 3], [4, 4]; - 4: segments [1, 2], [2, 3], [3, 4]; - 6: segments [1, 3], [2, 4]; - 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of *k* = ... | 1,500 | [
{
"input": "4 2\n2 2 2 2",
"output": "8"
},
{
"input": "4 -3\n3 -6 -3 12",
"output": "3"
},
{
"input": "14 -9\n-2 -4 62 53 90 41 35 21 85 74 85 57 10 39",
"output": "0"
},
{
"input": "20 9\n90 21 -6 -61 14 -21 -17 -65 -84 -75 -48 56 67 -50 16 65 -79 -61 92 85",
"output": ... | 1,689,253,117 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689253117.558859")# 1689253117.558901 | Title: Molly's Chemicals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She in... | ```python
print("_RANDOM_GUESS_1689253117.558859")# 1689253117.558901
``` | 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,691,669,674 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | s="qwertyuiopasdfghjklzxcvbnm"
n=input()
c=0
for i in range(26):
if n.find(s[i])!=-1:
c+=1
print(c) | 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
s="qwertyuiopasdfghjklzxcvbnm"
n=input()
c=0
for i in range(26):
if n.find(s[i])!=-1:
c+=1
print(c)
``` | 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.