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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,625,849,125 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 186 | 0 | n = int(input())
a = 0
b = 0
for i in range(n):
c, d = map(int, input().split())
a += c
b += d
e = 0
if a<=n//2:
e += a
else :
e += n-a
if b<=n//2:
e += b
else :
e += n-b
print(e)
| Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n = int(input())
a = 0
b = 0
for i in range(n):
c, d = map(int, input().split())
a += c
b += d
e = 0
if a<=n//2:
e += a
else :
e += n-a
if b<=n//2:
e += b
else :
e += n-b
print(e)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,620,740,968 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 108 | 20,172,800 | n = int(input())
s = input()
if s.count('0') == n:
print(n)
elif s.count('0') == n - 1:
print(1)
else:
while "10" in s:
s = s.replace("10", '')
while "01" in s:
s = s.replace("01", '')
print(len(s)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n = int(input())
s = input()
if s.count('0') == n:
print(n)
elif s.count('0') == n - 1:
print(1)
else:
while "10" in s:
s = s.replace("10", '')
while "01" in s:
s = s.replace("01", '')
print(len(s))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,623,741,143 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 2,150,400 | a,b=map(int,input().split())
if a==b:
print("GB"*a)
elif a<b:
print("GB"*a+"G"*(b-a))
else:
print("BG"*b+"B"*(a-b)) | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
a,b=map(int,input().split())
if a==b:
print("GB"*a)
elif a<b:
print("GB"*a+"G"*(b-a))
else:
print("BG"*b+"B"*(a-b))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,423,845,301 | 601 | Python 3 | OK | TESTS | 20 | 62 | 102,400 | '''
Created on Feb 13, 2015
@author: mohamed265
'''
n = int(input())
temp = [int(x) for x in input().split()]
slon = 9999999999999999
for i in range(n):
temp2 = [int(x) for x in input().split()]
t = 0
for j in range(temp[i]):
t += temp2[j] * 5
t += 15
slon = min(slon , t)
... | Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
'''
Created on Feb 13, 2015
@author: mohamed265
'''
n = int(input())
temp = [int(x) for x in input().split()]
slon = 9999999999999999
for i in range(n):
temp2 = [int(x) for x in input().split()]
t = 0
for j in range(temp[i]):
t += temp2[j] * 5
t += 15
slon = min(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
108 | B | Datatypes | PROGRAMMING | 1,400 | [
"math",
"sortings"
] | B. Datatypes | 2 | 256 | Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of *n* integers (1<=≤<=*a**i*<=≤<=109) — sizes of datatypes in bits. Some datatypes may have equal sizes. | Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise. | [
"3\n64 16 32\n",
"4\n4 2 1 3\n"
] | [
"NO\n",
"YES\n"
] | In the second example, *x* = 7 (111<sub class="lower-index">2</sub>) fits in 3 bits, but *x*<sup class="upper-index">2</sup> = 49 (110001<sub class="lower-index">2</sub>) does not fit in 4 bits. | 1,000 | [
{
"input": "3\n64 16 32",
"output": "NO"
},
{
"input": "4\n4 2 1 3",
"output": "YES"
},
{
"input": "5\n1 5 3 3 2",
"output": "YES"
},
{
"input": "52\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 ... | 1,696,364,644 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | x=int(input())
a=list(map(int,input().split()))
for i in range(x):
for j in range(0, x-i-1):
if a[j] > a[j+1] :
s=a[j]
a[j]=a[j+1]
a[j+1]=s
test=True
i=0
while test and i<x-1:
if a[i+1]//2>=a[i]:
test=True
else :
test=False
i=i+1... | Title: Datatypes
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to wr... | ```python
x=int(input())
a=list(map(int,input().split()))
for i in range(x):
for j in range(0, x-i-1):
if a[j] > a[j+1] :
s=a[j]
a[j]=a[j+1]
a[j+1]=s
test=True
i=0
while test and i<x-1:
if a[i+1]//2>=a[i]:
test=True
else :
test=False
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,674,316,833 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | a=int(input())
m_1=[]
m_2=[]
m_3=[]
b=input().split()
for i in range(len(b)):
if b[i]=='1':
m_1.append(i+1)
elif b[i]=='2':
m_2.append(i+1)
else:
m_3.append(i+1)
c=min(len(m_1),len(m_2),len(m_3))
print(c)
for i in range(c):
print(m_1[i],m_2[i],m_3[i])
... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
a=int(input())
m_1=[]
m_2=[]
m_3=[]
b=input().split()
for i in range(len(b)):
if b[i]=='1':
m_1.append(i+1)
elif b[i]=='2':
m_2.append(i+1)
else:
m_3.append(i+1)
c=min(len(m_1),len(m_2),len(m_3))
print(c)
for i in range(c):
print(m_1[i],m_2[i],... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
45 | A | Codecraft III | PROGRAMMING | 900 | [
"implementation"
] | A. Codecraft III | 2 | 256 | Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa... | The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III. | Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December. | [
"November\n3\n",
"May\n24\n"
] | [
"February\n",
"May\n"
] | none | 0 | [
{
"input": "November\n3",
"output": "February"
},
{
"input": "May\n24",
"output": "May"
},
{
"input": "April\n0",
"output": "April"
},
{
"input": "September\n0",
"output": "September"
},
{
"input": "August\n0",
"output": "August"
},
{
"input": "June\n1... | 1,633,800,824 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 6,963,200 |
months = ['January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December']
month = input()
m = int(input())
mp = {}
for i in range(12):
mp[months[i]] = i + 1
x = (mp[month] + m) % 12
if x == 0:
x = 12
print(months[x - 1])
... | Title: Codecraft III
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *... | ```python
months = ['January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December']
month = input()
m = int(input())
mp = {}
for i in range(12):
mp[months[i]] = i + 1
x = (mp[month] + m) % 12
if x == 0:
x = 12
print(months[x - 1])
... | 3.96403 | 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,693,642,838 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
for _ in range(n):
p,q=list(map(int,input().split())
cnt=0
for i in range(n):
if q-p >= 2:
cnt+=1
print(cnt) | 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())
for _ in range(n):
p,q=list(map(int,input().split())
cnt=0
for i in range(n):
if q-p >= 2:
cnt+=1
print(cnt)
``` | -1 | 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,697,484,416 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | a,b = map(int, input().split())
for i in range(a):
if i%2 == 0:
print(b*"#")
elif i%4 == 3:
print("#"+(b-1)*".")
else:
print((b-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
a,b = map(int, input().split())
for i in range(a):
if i%2 == 0:
print(b*"#")
elif i%4 == 3:
print("#"+(b-1)*".")
else:
print((b-1)*"."+"#")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with... | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per... | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n99... | 1,616,062,738 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 307,200 | n=int(input())
lst=[]
for x in range(0,4):
arr=list(input())
a,b,c,d,e,f,g,h,i,j=arr.count('0'),arr.count('1'),arr.count('2'),arr.count('3'),arr.count('4'),arr.count('5'),arr.count('6'),arr.count('7'),arr.count('8'),arr.count('9')
if a>n or b>n or c>n or d>n or e>n or f>n or g>n or h>n or i>n or j>n:
print("... | Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preff... | ```python
n=int(input())
lst=[]
for x in range(0,4):
arr=list(input())
a,b,c,d,e,f,g,h,i,j=arr.count('0'),arr.count('1'),arr.count('2'),arr.count('3'),arr.count('4'),arr.count('5'),arr.count('6'),arr.count('7'),arr.count('8'),arr.count('9')
if a>n or b>n or c>n or d>n or e>n or f>n or g>n or h>n or i>n or j>n:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,595,614,018 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 108 | 6,656,000 | print((1+int(input())*2)//3) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
print((1+int(input())*2)//3)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
14 | C | Four Segments | PROGRAMMING | 1,700 | [
"brute force",
"constructive algorithms",
"geometry",
"implementation",
"math"
] | C. Four Segments | 2 | 64 | Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr... | The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. | Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». | [
"1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n",
"0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0",
"output": "YES"
},
{
"input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "YES"
},
{
"input": "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5",
"output": "NO"
... | 1,527,545,509 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | s=input()
a=[int(i) for i in s.split()]
s=input()
b=[int(i) for i in s.split()]
s=input()
c=[int(i) for i in s.split()]
s=input()
d=[int(i) for i in s.split()]
f=0
v=[]
h=[]
if a[0]==a[2]:
if a[1]>a[3]:
a[1],a[3]=a[3],a[1]
v.append(a)
elif a[1]==a[3]:
if a[0]>a[2]:
a... | Title: Four Segments
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creati... | ```python
s=input()
a=[int(i) for i in s.split()]
s=input()
b=[int(i) for i in s.split()]
s=input()
c=[int(i) for i in s.split()]
s=input()
d=[int(i) for i in s.split()]
f=0
v=[]
h=[]
if a[0]==a[2]:
if a[1]>a[3]:
a[1],a[3]=a[3],a[1]
v.append(a)
elif a[1]==a[3]:
if a[0]>a[2]:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,604,842,361 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 216 | 0 | myList = map(int , input().split())
myList = list(myList)
myList.sort()
n = 6 - myList[-1] + 1
if n == 1:
print("1/6")
if n == 2:
print("1/3")
if n == 3:
print("1/2")
if n == 4:
print("2/3")
if n == 5:
print("5/6")
if n == 6:
print("1/1") | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
myList = map(int , input().split())
myList = list(myList)
myList.sort()
n = 6 - myList[-1] + 1
if n == 1:
print("1/6")
if n == 2:
print("1/3")
if n == 3:
print("1/2")
if n == 4:
print("2/3")
if n == 5:
print("5/6")
if n == 6:
print("1/1")
``` | 3.892 | MatrixStudio/Codeforces-Python-Submissions |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,580,890,989 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | x=input()
y=input()
res=""
for i in range (len(x)):
res=(int(x[i]) ^ int(y[i]))
print(res,end="") | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
x=input()
y=input()
res=""
for i in range (len(x)):
res=(int(x[i]) ^ int(y[i]))
print(res,end="")
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
883 | M | Quadcopter Competition | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w... | The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter sta... | Print the length of minimal path of the quadcopter to surround the flag and return back. | [
"1 5\n5 2\n",
"0 1\n0 0\n"
] | [
"18\n",
"8\n"
] | none | 0 | [
{
"input": "1 5\n5 2",
"output": "18"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "-100 -100\n100 100",
"output": "804"
},
{
"input": "-100 -100\n-100 100",
"output": "406"
},
{
"input": "-100 -100\n100 -100",
"output": "406"
},
{
"input": "1... | 1,612,906,662 | 2,147,483,647 | PyPy 3 | OK | TESTS | 100 | 124 | 0 | x1,y1 = map(int, input().split())
x2,y2 = map(int, input().split())
y = abs(y1-y2)
x = abs(x1-x2)
if x!=0 and y!=0:
sum = (abs(x1-x2)+1)*2 + (abs(y1-y2)+1)*2
elif x == 0:
sum = (abs(y1-y2)+1)*2 +4
elif y == 0:
sum = (abs(x1-x2)+1)*2 +4
print(sum) | Title: Quadcopter Competition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting p... | ```python
x1,y1 = map(int, input().split())
x2,y2 = map(int, input().split())
y = abs(y1-y2)
x = abs(x1-x2)
if x!=0 and y!=0:
sum = (abs(x1-x2)+1)*2 + (abs(y1-y2)+1)*2
elif x == 0:
sum = (abs(y1-y2)+1)*2 +4
elif y == 0:
sum = (abs(x1-x2)+1)*2 +4
print(sum)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
644 | A | Parliament of Berland | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms"
] | null | null | There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chair... | The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively. | If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multi... | [
"3 2 2\n",
"8 4 3\n",
"10 2 2\n"
] | [
"0 3\n1 2\n",
"7 8 3\n0 1 4\n6 0 5\n0 2 0\n",
"-1\n"
] | In the first sample there are many other possible solutions. For example,
and
The following assignment
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats. | 500 | [
{
"input": "3 2 2",
"output": "1 2 \n0 3 "
},
{
"input": "8 4 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 "
},
{
"input": "10 2 2",
"output": "-1"
},
{
"input": "1 1 1",
"output": "1 "
},
{
"input": "8 3 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 "
},
{
"in... | 1,458,241,251 | 122,451 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 30 | 0 | import sys
n, a, b = map(int, input().split())
i, j, c, f = [1, 1, 1, True]
if (n > a*b):
print(-1)
sys.exit()
if (b % 2 != 0):
f = False
while i<=a:
j = 1
while (j<=b):
if (i%2==0 and f):
cc = c+b-j
if (cc <= n):
print(c+b-j, end='')
else:
print('0', end='')
else:
if (c <= n):
prin... | Title: Parliament of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republi... | ```python
import sys
n, a, b = map(int, input().split())
i, j, c, f = [1, 1, 1, True]
if (n > a*b):
print(-1)
sys.exit()
if (b % 2 != 0):
f = False
while i<=a:
j = 1
while (j<=b):
if (i%2==0 and f):
cc = c+b-j
if (cc <= n):
print(c+b-j, end='')
else:
print('0', end='')
else:
if (c <= n)... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,692,198,805 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | def tram(num_lines: int, pairs: int) -> int:
maxPass = 0
differencePass = 0
for i in range(1, num_lines):
outgoingPrev, incomingPrev = pairs[i - 1]
outgoingCurr, incomingCurr = pairs[i]
differencePass = incomingPrev - outgoingCurr + incomingCurr
maxPass = max(maxPass, differe... | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
def tram(num_lines: int, pairs: int) -> int:
maxPass = 0
differencePass = 0
for i in range(1, num_lines):
outgoingPrev, incomingPrev = pairs[i - 1]
outgoingCurr, incomingCurr = pairs[i]
differencePass = incomingPrev - outgoingCurr + incomingCurr
maxPass = max(maxPas... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
988 | B | Substrings Sort | PROGRAMMING | 1,100 | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su... | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | 0 | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "Y... | 1,661,027,022 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n = int(input())
l = []
while n:
l.append(input())
n -= 1
l.sort(key=len)
m = max(l, key=len)
for i, w in enumerate(l):
try:
if w not in l[i + 1]:
print('NO')
exit()
except IndexError:
print('NO')
exit()
print('YES')
for i in l:
print(i)
... | Title: Substrings Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String ... | ```python
n = int(input())
l = []
while n:
l.append(input())
n -= 1
l.sort(key=len)
m = max(l, key=len)
for i, w in enumerate(l):
try:
if w not in l[i + 1]:
print('NO')
exit()
except IndexError:
print('NO')
exit()
print('YES')
for i in l:
print(i)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,616,863,063 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 124 | 307,200 | s = [int(i) for i in input().split()]
t = 0
for i in range(len(s)):
for i1 in range(len(s)):
for i2 in range(len(s)):
s1 = [s[i], s[i1], s[i2]]
s1.sort()
if (s1[0] + s1[1] > s1[2] and s1[0] + s1[2] > s1[1]) and t == 0 and i2 != i and i2 != i1 and i != i1:
... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
s = [int(i) for i in input().split()]
t = 0
for i in range(len(s)):
for i1 in range(len(s)):
for i2 in range(len(s)):
s1 = [s[i], s[i1], s[i2]]
s1.sort()
if (s1[0] + s1[1] > s1[2] and s1[0] + s1[2] > s1[1]) and t == 0 and i2 != i and i2 != i1 and i != i1:... | 0 | MatrixStudio/Codeforces-Python-Submissions |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,689,843,648 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def myfunct(string):
for i in range(len(string)):
if string[i]=='b' and string[i+1]=='a':
print("NO")
var=0
break
else:
a=string.count("a")
b=string.count("b")
c=string.count("c")
var=1
if var==1 and (... | Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
def myfunct(string):
for i in range(len(string)):
if string[i]=='b' and string[i+1]=='a':
print("NO")
var=0
break
else:
a=string.count("a")
b=string.count("b")
c=string.count("c")
var=1
if va... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,495,893,907 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | a, b = map(int, input().split())
if a <= b:
print('Valera')
else:
print('Vladik')
| Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
a, b = map(int, input().split())
if a <= b:
print('Valera')
else:
print('Vladik')
``` | 0 | 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,677,606,902 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 62 | 0 | num=int(input())
n1=input()
n2=input()
s=0
for i in range(num):
if abs(int(n1[i])-int(n2[i]))<5:
s+=abs(int(n1[i])-int(n2[i]))
else:
s+=abs(10-abs(int(n1[i])-int(n2[i])))
print(s) | 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
num=int(input())
n1=input()
n2=input()
s=0
for i in range(num):
if abs(int(n1[i])-int(n2[i]))<5:
s+=abs(int(n1[i])-int(n2[i]))
else:
s+=abs(10-abs(int(n1[i])-int(n2[i])))
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters e... | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "Y... | 1,616,947,526 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 248 | 3,072,000 | n, k = map(int, input().split())
a = input()
mx, cur = 0, 0
for ch in a:
if ch == '.':
mx = max(mx, cur)
cur = 0
else:
cur += 1
print("YES") if mx < k else print("NO")
'''
* So I drown it out
* Like I always do
* Dancing through our house
* With the ghost of you
'''
| Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to t... | ```python
n, k = map(int, input().split())
a = input()
mx, cur = 0, 0
for ch in a:
if ch == '.':
mx = max(mx, cur)
cur = 0
else:
cur += 1
print("YES") if mx < k else print("NO")
'''
* So I drown it out
* Like I always do
* Dancing through our house
* With the ghost of you
'''
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
487 | A | Fight the Monster | PROGRAMMING | 1,800 | [
"binary search",
"brute force",
"implementation"
] | null | null | A monster is attacking the Cyberland!
Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (*HP*), offensive power (*ATK*) and defensive power (*DEF*).
During the battle, every second the monster's HP decrease by *max*(0,<=*ATK**Y*<=-<=*DEF**M*), while Yang's HP ... | The first line contains three integers *HP**Y*,<=*ATK**Y*,<=*DEF**Y*, separated by a space, denoting the initial *HP*, *ATK* and *DEF* of Master Yang.
The second line contains three integers *HP**M*,<=*ATK**M*,<=*DEF**M*, separated by a space, denoting the *HP*, *ATK* and *DEF* of the monster.
The third line contains... | The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win. | [
"1 2 1\n1 100 1\n1 100 100\n",
"100 100 100\n1 1 1\n1 1 1\n"
] | [
"99\n",
"0\n"
] | For the first sample, prices for *ATK* and *DEF* are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.
For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything. | 500 | [
{
"input": "1 2 1\n1 100 1\n1 100 100",
"output": "99"
},
{
"input": "100 100 100\n1 1 1\n1 1 1",
"output": "0"
},
{
"input": "50 80 92\n41 51 56\n75 93 12",
"output": "0"
},
{
"input": "76 63 14\n89 87 35\n20 15 56",
"output": "915"
},
{
"input": "12 59 66\n43 15... | 1,416,591,241 | 841 | Python 3 | CHALLENGED | CHALLENGES | 8 | 716 | 0 | """
Codeforces Contest 278 Div 1 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
h1,a1,d1 = read()
h2,a2,d2 = read()
hc,ac,dc = read()
mn = 10**18
for hi in range(201):
for ai in range(201):
for di in range(201):
if a1-d2+... | Title: Fight the Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is attacking the Cyberland!
Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (*HP*), offensive power (*ATK*) and defensive power (*DEF*).
During t... | ```python
"""
Codeforces Contest 278 Div 1 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
h1,a1,d1 = read()
h2,a2,d2 = read()
hc,ac,dc = read()
mn = 10**18
for hi in range(201):
for ai in range(201):
for di in range(201):
... | -1 | 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,670,172,067 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | inp=str(input())
middle=0
list1=[]
list2=[]
sum1=0
sum2=0
for i in range(len(inp)):
if inp[i]!=“^”:
list1.append(inp[i])
elif inp[i]==“^”:
middle=i
break
for i in range (middle+1, len(inp)-1):
list2.append(inp[i])
list2_num=len(list2)
for i in range(len(list2)):
if list2[i]!=... | 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
inp=str(input())
middle=0
list1=[]
list2=[]
sum1=0
sum2=0
for i in range(len(inp)):
if inp[i]!=“^”:
list1.append(inp[i])
elif inp[i]==“^”:
middle=i
break
for i in range (middle+1, len(inp)-1):
list2.append(inp[i])
list2_num=len(list2)
for i in range(len(list2)):
if ... | -1 | 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,587,842,436 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 16,896,000 | a=int(input())
b=list(map(int,input().split()))
c=[]
d=[]
for x in b:
if x not in c:
c.append(x)
else:
c.remove(x)
d.append(len(c))
print(max(d)) | 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
a=int(input())
b=list(map(int,input().split()))
c=[]
d=[]
for x in b:
if x not in c:
c.append(x)
else:
c.remove(x)
d.append(len(c))
print(max(d))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
573 | A | Bear and Poker | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any nu... | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 500 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724... | 1,588,769,921 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 1,169 | 9,523,200 | n=int(input())
a=list(map(int,input().split()))
def gcd(a,b):#O(loga+logb)
a,b=max(a,b),min(a,b)
if a*b==0:return a
if a%b==0:return b
return gcd(a%b,b)
GCD=gcd(a[0],a[1])
for i in range(1,n):GCD=gcd(a[i],GCD)
def fn(t):
i=0
while t%(2**i)==0:i+=1
t=t//(2**(i-1))
i=0
while ... | Title: Bear and Poker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid wit... | ```python
n=int(input())
a=list(map(int,input().split()))
def gcd(a,b):#O(loga+logb)
a,b=max(a,b),min(a,b)
if a*b==0:return a
if a%b==0:return b
return gcd(a%b,b)
GCD=gcd(a[0],a[1])
for i in range(1,n):GCD=gcd(a[i],GCD)
def fn(t):
i=0
while t%(2**i)==0:i+=1
t=t//(2**(i-1))
i=0
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
744 | A | Hongcow Builds A Nation | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at ... | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**... | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 500 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
... | 1,620,583,677 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 296 | 9,523,200 | nums = input().split(" ")
num1, num2, num3 = int(nums[0]), int(nums[1]), int(nums[2])
lista = []
nodes = list(map(int, input().split(" ")))
def calc(valor):
global x, y
x += 1
usado[valor] = True
y += len(lista[valor])
for i in lista[valor]:
if not usado[i]:
calc(i)
... | Title: Hongcow Builds A Nation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* e... | ```python
nums = input().split(" ")
num1, num2, num3 = int(nums[0]), int(nums[1]), int(nums[2])
lista = []
nodes = list(map(int, input().split(" ")))
def calc(valor):
global x, y
x += 1
usado[valor] = True
y += len(lista[valor])
for i in lista[valor]:
if not usado[i]:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,443,891,764 | 1,064 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 0 | n=int(input())
b=[]
for i in range(n+1):
b.append(0)
for i in range(1 , n**2 + 1):
s=input().split()
x=int(s[0])
y=int(s[1])
if b[x] == 0 and b[y] == 0:
b[x]=1
b[y]=1
print(i , end=' ')
| Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
n=int(input())
b=[]
for i in range(n+1):
b.append(0)
for i in range(1 , n**2 + 1):
s=input().split()
x=int(s[0])
y=int(s[1])
if b[x] == 0 and b[y] == 0:
b[x]=1
b[y]=1
print(i , end=' ')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,594,830,611 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 140 | 20,172,800 |
n = int(input())
x = [int(x) for x in input().split()]
a = x.index(max(x))
x.sort()
print(a + 1 , x[-2]) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
n = int(input())
x = [int(x) for x in input().split()]
a = x.index(max(x))
x.sort()
print(a + 1 , x[-2])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
868 | C | Qualification Rounds | PROGRAMMING | 1,500 | [
"bitmasks",
"brute force",
"constructive algorithms",
"dp"
] | null | null | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset.
*k* experienced teams are participating in the contest. Some of these teams already know some of the prob... | The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams.
Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n",
"3 2\n1 0\n1 1\n0 1\n"
] | [
"NO\n",
"YES\n"
] | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | 1,000 | [
{
"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0",
"output": "NO"
},
{
"input": "3 2\n1 0\n1 1\n0 1",
"output": "YES"
},
{
"input": "10 2\n1 0\n1 0\n0 0\n1 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1",
"output": "YES"
},
{
"input": "10 3\n1 0 0\n0 1 1\n1 0 0\n0 1 0\n0 0 1\n1 0 1\n0 1 1... | 1,508,377,436 | 3,236 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,529,600 | n = int(input())
k = int(input())
p = []
r = "no"
for i in range(0, n):
p.append([])
for j in range(0, k):
p[i].append(0)
for i in range(0, n):
for j in range(0, k):
p[i][j] = int(input())
for i in range(0, k):
for j in range(0, n):
if p[j][i] == 0:
... | Title: Qualification Rounds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset.
... | ```python
n = int(input())
k = int(input())
p = []
r = "no"
for i in range(0, n):
p.append([])
for j in range(0, k):
p[i].append(0)
for i in range(0, n):
for j in range(0, k):
p[i][j] = int(input())
for i in range(0, k):
for j in range(0, n):
if p[j][i] == 0:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
548 | B | Mike and Fun | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"greedy",
"implementation"
] | null | null | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear s... | The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the inf... | After each round, print the current score of the bears. | [
"5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n"
] | [
"3\n4\n3\n3\n4\n"
] | none | 1,000 | [
{
"input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3",
"output": "3\n4\n3\n3\n4"
},
{
"input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1",
"output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1"
},
{
"input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\... | 1,643,995,155 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | s = input()
n = int(s.split()[0])
m = int(s.split()[1])
q = int(s.split()[2])
grid = []
for i in range(n):
s = input()
row = []
for j in range(m):
row.append(int(s.split()[j]))
grid.append(row)
for i in range(q):
s = input()
r = int(s.split()[0])
c = int(s.split()[1])
if grid[... | Title: Mike and Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of ... | ```python
s = input()
n = int(s.split()[0])
m = int(s.split()[1])
q = int(s.split()[2])
grid = []
for i in range(n):
s = input()
row = []
for j in range(m):
row.append(int(s.split()[j]))
grid.append(row)
for i in range(q):
s = input()
r = int(s.split()[0])
c = int(s.split()[1])
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,697,739,405 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 62 | 0 | n = int(input())
game = str(input())
if game.count('A') > game.count('D'):
print('Anton')
elif game.count('A') < game.count('D'):
print('Danik')
else:
print('Friendship') | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
n = int(input())
game = str(input())
if game.count('A') > game.count('D'):
print('Anton')
elif game.count('A') < game.count('D'):
print('Danik')
else:
print('Friendship')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Manao is taking part in a quiz. The quiz consists of *n* consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectl... | The single line contains three space-separated integers *n*, *m* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=109; 0<=≤<=*m*<=≤<=*n*). | Print a single integer — the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109<=+<=9). | [
"5 3 2\n",
"5 4 2\n"
] | [
"3\n",
"6\n"
] | Sample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.
Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong ... | 0 | [
{
"input": "5 3 2",
"output": "3"
},
{
"input": "5 4 2",
"output": "6"
},
{
"input": "300 300 3",
"output": "17717644"
},
{
"input": "300 282 7",
"output": "234881124"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "999999991"
},
{
"input"... | 1,377,855,874 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | q=input().split(" ")
n=int(q[0])
m=int(q[1])
k=int(q[2])
score=0
a=[False]*n
l=0
o=0
for i in range(0,m) :
a[l+o]=True
l=l+2
if l>len(a)-1 :
o=o+1
l=0
u=0
for i in range(0,n) :
if a[i]==True :
u=u+1
score=score+1
else :
u=0
if u==k :
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao is taking part in a quiz. The quiz consists of *n* consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correct... | ```python
q=input().split(" ")
n=int(q[0])
m=int(q[1])
k=int(q[2])
score=0
a=[False]*n
l=0
o=0
for i in range(0,m) :
a[l+o]=True
l=l+2
if l>len(a)-1 :
o=o+1
l=0
u=0
for i in range(0,n) :
if a[i]==True :
u=u+1
score=score+1
else :
u=0
i... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
242 | A | Heads or Tails | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin *x* times, then Petya tosses a coin *y* times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by t... | The single line contains four integers *x*,<=*y*,<=*a*,<=*b* (1<=≤<=*a*<=≤<=*x*<=≤<=100,<=1<=≤<=*b*<=≤<=*y*<=≤<=100). The numbers on the line are separated by a space. | In the first line print integer *n* — the number of possible outcomes of the game. Then on *n* lines print the outcomes. On the *i*-th line print a space-separated pair of integers *c**i*, *d**i* — the number of heads Vasya and Petya got in the *i*-th outcome of the game, correspondingly. Print pairs of integers (*c**i... | [
"3 2 1 1\n",
"2 4 2 2\n"
] | [
"3\n2 1\n3 1\n3 2\n",
"0\n"
] | none | 500 | [
{
"input": "3 2 1 1",
"output": "3\n2 1\n3 1\n3 2"
},
{
"input": "2 4 2 2",
"output": "0"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "4 5 2 3",
"output": "1\n4 3"
},
{
"input": "10 6 3 4",
"output": "15\n5 4\n6 4\n6 5\n7 4\n7 5\n7 6\n8 4\n8 5\n8 6\n9... | 1,588,843,654 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 310 | 23,347,200 | x,y,a,b = map(int,input().split())
list = []
for i in range(a,x+1):
for j in range(b,y+1):
if i>j:
list.append([i,j])
print(len(list))
for pair in list:
print('{} {}'.format(pair[0],pair[1]))
| Title: Heads or Tails
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin *x* times, then Petya tosses a coin *y* times. If the tossing player gets head, he score... | ```python
x,y,a,b = map(int,input().split())
list = []
for i in range(a,x+1):
for j in range(b,y+1):
if i>j:
list.append([i,j])
print(len(list))
for pair in list:
print('{} {}'.format(pair[0],pair[1]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,620,328,776 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 248 | 20,172,800 | s=input()
t=input()
u=0
r=1
for i in range(len(t)):
if(t[i]==s[u]):
u=u+1
r=r+1
print(r) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s=input()
t=input()
u=0
r=1
for i in range(len(t)):
if(t[i]==s[u]):
u=u+1
r=r+1
print(r)
``` | 3 | 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,618,433,807 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | r,c = map(int,input().split())
ans = ''
turn = 'b'
for i in range(1,r+1):
b = input()
print(i,1)
if b == '':
break
for e in range(len(b)):
print(e,2)
if b[e] == '.':
if turn == 'b':
ans += 'B'
turn = 'w'
co... | 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
r,c = map(int,input().split())
ans = ''
turn = 'b'
for i in range(1,r+1):
b = input()
print(i,1)
if b == '':
break
for e in range(len(b)):
print(e,2)
if b[e] == '.':
if turn == 'b':
ans += 'B'
turn = 'w'
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,640,673,556 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 122 | 614,400 | import heapq
def solver():
n, k = map(int, input().split())
arr = [int(x) for x in input().split()]
neg_arr = []
pos_arr = []
for e in (arr):
if e <= 0:
neg_arr.append(e)
else:
pos_arr.append(e)
if len(neg_arr)==0:
max_sum = sum(p... | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
import heapq
def solver():
n, k = map(int, input().split())
arr = [int(x) for x in input().split()]
neg_arr = []
pos_arr = []
for e in (arr):
if e <= 0:
neg_arr.append(e)
else:
pos_arr.append(e)
if len(neg_arr)==0:
max_s... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,698,203,148 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 4 | 498 | 268,390,400 | import math
inp = input().split(" ")
n = int(inp[0])
k = int(inp[1])
d = int(inp[2])
mod_num = 1000000007
results = dict()
def compute(target: int, k:int, d:int):
if target in results:
return
local_results = []
for x in range(d, k+1):
new_target = target - x
i... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
import math
inp = input().split(" ")
n = int(inp[0])
k = int(inp[1])
d = int(inp[2])
mod_num = 1000000007
results = dict()
def compute(target: int, k:int, d:int):
if target in results:
return
local_results = []
for x in range(d, k+1):
new_target = target - x
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,619,392,339 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 77 | 0 | s = input()
testCase = ['h', 'e', 'i', 'd', 'i']
temp = [c for c in s if c in testCase]
temp1 = "".join(dict.fromkeys(temp))
temp.reverse()
temp2 = "".join(dict.fromkeys(temp))
# https://www.programiz.com/python-programming/methods/dictionary/fromkeys
# learned what dict.fromkeys() accomplishes
if temp1 == "heid":
... | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s = input()
testCase = ['h', 'e', 'i', 'd', 'i']
temp = [c for c in s if c in testCase]
temp1 = "".join(dict.fromkeys(temp))
temp.reverse()
temp2 = "".join(dict.fromkeys(temp))
# https://www.programiz.com/python-programming/methods/dictionary/fromkeys
# learned what dict.fromkeys() accomplishes
if temp1 ==... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
25 | C | Roads in Berland | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Roads in Berland | 2 | 256 | There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=300) — amount of cities in Berland. Then there follow *n* lines with *n* integer numbers each — the matrix of shortest distances. *j*-th integer in the *i*-th row — *d**i*,<=*j*, the shortest distance between cities *i* and *j*. It is guaranteed that *d**i*,<=*i*<==<=0... | Output *k* space-separated integers *q**i* (1<=≤<=*i*<=≤<=*k*). *q**i* should be equal to the sum of shortest distances between all pairs of cities after the construction of roads with indexes from 1 to *i*. Roads are numbered from 1 in the input order. Each pair of cities should be taken into account in the sum exactl... | [
"2\n0 5\n5 0\n1\n1 2 3\n",
"3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n"
] | [
"3 ",
"17 12 "
] | none | 0 | [
{
"input": "2\n0 5\n5 0\n1\n1 2 3",
"output": "3 "
},
{
"input": "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1",
"output": "17 12 "
},
{
"input": "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763",
"output": "1480 1480 1480 "
},
{
"input": "4\n0 537 1064 656\n537 0... | 1,669,850,108 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 122 | 2,867,200 | from sys import stdin
def change(a,b,c,caminosViejos):
a,b,c = int(a)-1, int(b)-1, int(c)
caminosViejos[a][b] = min(int(caminosViejos[a][b]), c)
caminosViejos[b][a] = min(int(caminosViejos[b][a]), c)
def floydWarshall(n,a,b, c,caminos):
result = 0
a, b= int(a) - 1, int(b) - 1
f... | Title: Roads in Berland
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to... | ```python
from sys import stdin
def change(a,b,c,caminosViejos):
a,b,c = int(a)-1, int(b)-1, int(c)
caminosViejos[a][b] = min(int(caminosViejos[a][b]), c)
caminosViejos[b][a] = min(int(caminosViejos[b][a]), c)
def floydWarshall(n,a,b, c,caminos):
result = 0
a, b= int(a) - 1, int(b) ... | -1 | MatrixStudio/Codeforces-Python-Submissions |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,504,021,916 | 2,816 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 61 | 0 | l, r, x, y, k = map(int, input().split())
if (k * x <= r) and (k * y >= l) and (((l <= k * (l // k) <= r) and (x <= l // k <= y)) or (
(l <= k * (l // k + 1) <= r) and (x <= l // k + 1 <= y))):
print('YES')
else:
print('NO')
| Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
l, r, x, y, k = map(int, input().split())
if (k * x <= r) and (k * y >= l) and (((l <= k * (l // k) <= r) and (x <= l // k <= y)) or (
(l <= k * (l // k + 1) <= r) and (x <= l // k + 1 <= y))):
print('YES')
else:
print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,683,970,916 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 186 | 13,824,000 | n,m = map(int,input().split())
arr = tuple(map(int,input().split()))
b=s=0
for i in arr:
b+=i
if (b>m):b-=arr[s];s+=1
print(n-s)
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n,m = map(int,input().split())
arr = tuple(map(int,input().split()))
b=s=0
for i in arr:
b+=i
if (b>m):b-=arr[s];s+=1
print(n-s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
325 | D | Reclamation | PROGRAMMING | 2,900 | [
"dsu"
] | null | null | In a far away land, there exists a planet shaped like a cylinder. There are three regions in this planet: top, bottom, and side as shown in the following picture.
Both the top and the bottom areas consist of big cities. The side area consists entirely of the sea.
One day, a city decides that it has too little space a... | The first line consists of three integers *r*, *c*, and *n* (1<=≤<=*r*,<=*c*<=≤<=3000, 1<=≤<=*n*<=≤<=3·105). Then, *n* lines follow, describing the cells in the order you will reclamate them. Each line will consists of two integers: *r**i* and *c**i* (1<=≤<=*r**i*<=≤<=*r*, 1<=≤<=*c**i*<=≤<=*c*), which represents the ce... | You should output a single number representing the number of cells that were successfully turned to land. | [
"3 4 9\n2 2\n3 2\n2 3\n3 4\n3 1\n1 3\n2 1\n1 1\n1 4\n"
] | [
"6\n"
] | The pictures below show the sequence of reclamations that are performed in the example input. Blue cells represent the cells occupied by sea, while other colored cells represent land. The latest cell that are reclamated is colored either yellow or red, depending on whether the addition violates the condition in the sta... | 2,000 | [] | 1,689,638,813 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | print("_RANDOM_GUESS_1689638813.369553")# 1689638813.369572 | Title: Reclamation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a far away land, there exists a planet shaped like a cylinder. There are three regions in this planet: top, bottom, and side as shown in the following picture.
Both the top and the bottom areas consist of big cities. Th... | ```python
print("_RANDOM_GUESS_1689638813.369553")# 1689638813.369572
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,700,220,857 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | n=int(input())
c1=n//100
n=n%100
c2=n//20
n=n%20
c3=n//10
n=n%10
c4=n//5
n=n%5
print(c1+c2+c3+c4+n) | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
n=int(input())
c1=n//100
n=n%100
c2=n//20
n=n%20
c3=n//10
n=n%10
c4=n//5
n=n%5
print(c1+c2+c3+c4+n)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,649,333,802 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 77 | 0 | import sys
input = sys.stdin.readline
a = int(input())
b = int(input())
f = abs(a - b) // 2
s = (abs(a - b) + 1) // 2
print(f * (f + 1) // 2 + s * (s + 1) // 2) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
import sys
input = sys.stdin.readline
a = int(input())
b = int(input())
f = abs(a - b) // 2
s = (abs(a - b) + 1) // 2
print(f * (f + 1) // 2 + s * (s + 1) // 2)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,663,776,794 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | n,m=map(int,input().split())
k=max(n,m)
if k%2==0:
a=k//2
else:
a=(k//2)+1
print(a**2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n,m=map(int,input().split())
k=max(n,m)
if k%2==0:
a=k//2
else:
a=(k//2)+1
print(a**2)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,692,789,294 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | def func(w):
if w <= 2: return "YES"
if w%2 == 0: return "YES"
if w%2 == 1: return "NO"
w = int(input())
print(func(w)) | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
def func(w):
if w <= 2: return "YES"
if w%2 == 0: return "YES"
if w%2 == 1: return "NO"
w = int(input())
print(func(w))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,660,153,546 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 124 | 6,758,400 | n, m = input().split()
m = int(m)
d = dict()
while m:
m -= 1
a, b = input().split()
if len(a) > len(b):
d[a] = b
buffer = []
for word in input().split():
if word in d:
buffer.append(d[word])
else:
buffer.append(word)
print(*buffer) | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n, m = input().split()
m = int(m)
d = dict()
while m:
m -= 1
a, b = input().split()
if len(a) > len(b):
d[a] = b
buffer = []
for word in input().split():
if word in d:
buffer.append(d[word])
else:
buffer.append(word)
print(*buffer)
``` | 3 | 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,047,630 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | # -*- coding: utf-8 -*-
"""
Created on Thu Sep 7 08:44:40 2023
@author: HyFlu
"""
string=input()
if 'H' in string or 'Q' in string or '9' in string:
print('YES')
else:
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
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 7 08:44:40 2023
@author: HyFlu
"""
string=input()
if 'H' in string or 'Q' in string or '9' in string:
print('YES')
else:
print('NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
485 | B | Valuable Resources | PROGRAMMING | 1,300 | [
"brute force",
"greedy"
] | null | null | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes.... | The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. | Print the minimum area of the city that can cover all the mines with valuable resources. | [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
] | [
"4\n",
"9\n"
] | none | 500 | [
{
"input": "2\n0 0\n2 2",
"output": "4"
},
{
"input": "2\n0 0\n0 3",
"output": "9"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "4"
},
{
"input": "3\n3 1\n1 3\n2 2",
"output": "4"
},
{
"input": "3\n0 1\n1 0\n2 ... | 1,556,616,066 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 109 | 0 | n = int(input())
minX, maxX = int(2e9), -int(2e9)
minY, maxY = int(2e9), -int(2e9)
for i in range(n):
x, y = map(int, input().split())
minX = min(minX, x)
maxX = max(maxX, x)
minY = min(minY, y)
maxY = max(maxY, y)
print(max(maxX - minX, maxY - minY) ** 2)
| Title: Valuable Resources
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. Th... | ```python
n = int(input())
minX, maxX = int(2e9), -int(2e9)
minY, maxY = int(2e9), -int(2e9)
for i in range(n):
x, y = map(int, input().split())
minX = min(minX, x)
maxX = max(maxX, x)
minY = min(minY, y)
maxY = max(maxY, y)
print(max(maxX - minX, maxY - minY) ** 2)
``` | 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,444,167,311 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | s = raw_input()
word = "hello"
k = 0
for i in range(len(s)):
if s[i] == word[k]:
k += 1
if k == 5:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = raw_input()
word = "hello"
k = 0
for i in range(len(s)):
if s[i] == word[k]:
k += 1
if k == 5:
print("YES")
else:
print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
566 | F | Clique in the Divisibility Graph | PROGRAMMING | 1,500 | [
"dp",
"math",
"number theory"
] | null | null | As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are conn... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106), that sets the size of set *A*.
The second line contains *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — elements of subset *A*. The numbers in the line follow in the ascending order. | Print a single number — the maximum size of a clique in a divisibility graph for set *A*. | [
"8\n3 4 6 8 10 18 21 24\n"
] | [
"3\n"
] | In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph. | 500 | [
{
"input": "8\n3 4 6 8 10 18 21 24",
"output": "3"
},
{
"input": "5\n2 3 4 8 16",
"output": "4"
},
{
"input": "2\n10 20",
"output": "2"
},
{
"input": "2\n10 21",
"output": "1"
},
{
"input": "5\n250000 333333 500000 666666 1000000",
"output": "3"
},
{
"... | 1,655,742,565 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 55,500,800 | import time
import random
def clique(A, n):
for i in A:
if i % n != 0 and n % i != 0:
return False
return True
def divisorset(A, n):
B = {n}
for i in A:
if i % n == 0 or n % i == 0:
B.add(i)
return B
def maxclique(A... | Title: Clique in the Divisibility Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a cli... | ```python
import time
import random
def clique(A, n):
for i in A:
if i % n != 0 and n % i != 0:
return False
return True
def divisorset(A, n):
B = {n}
for i in A:
if i % n == 0 or n % i == 0:
B.add(i)
return B
def m... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,525,122,313 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 93 | 7,065,600 | n = int(input())
s = input()
cnt0 = 0
cnt1 = 0
for i in range(len(s)):
if(s[i]=='0'):
cnt0 += 1
else:
cnt1 += 1
ans = ""
if(cnt1 > 0):
ans = ans + '1'
for i in range(cnt0):
ans = ans + '0'
print(ans)
| Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
n = int(input())
s = input()
cnt0 = 0
cnt1 = 0
for i in range(len(s)):
if(s[i]=='0'):
cnt0 += 1
else:
cnt1 += 1
ans = ""
if(cnt1 > 0):
ans = ans + '1'
for i in range(cnt0):
ans = ans + '0'
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
747 | E | Comments | PROGRAMMING | 1,700 | [
"dfs and similar",
"expression parsing",
"implementation",
"strings"
] | null | null | A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment ex... | The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas.
It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (... | Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input. | [
"hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0\n",
"a,5,A,0,a,0,A,0,a,0,A,0\n",
"A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0\n"
] | [
"3\nhello test one \nok bye two \na b \n",
"2\na \nA a A a A \n",
"4\nA K M \nB F H L N O \nC D G I P \nE J \n"
] | The first example is explained in the statements. | 2,000 | [
{
"input": "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0",
"output": "3\nhello test one \nok bye two \na b "
},
{
"input": "a,5,A,0,a,0,A,0,a,0,A,0",
"output": "2\na \nA a A a A "
},
{
"input": "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0",
"output": "4\nA K M \n... | 1,585,370,386 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 20 | 1,310 | 207,155,200 | maxn = int(4e6)
store = [ [] for _ in range(maxn)]
visited = [ 0 for _ in range(maxn)]
s = []
c =0
def dfs( index , level , cnt ):
if index > len(s):
return
visited[index] = 1
visited[index+1]=1
store[level].append( s[index])
while (cnt > 0):
index +=2
if index < len(s) and visited[index] == ... | Title: Comments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowerc... | ```python
maxn = int(4e6)
store = [ [] for _ in range(maxn)]
visited = [ 0 for _ in range(maxn)]
s = []
c =0
def dfs( index , level , cnt ):
if index > len(s):
return
visited[index] = 1
visited[index+1]=1
store[level].append( s[index])
while (cnt > 0):
index +=2
if index < len(s) and visited[... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,692,301,127 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | count=0
a=[int (i) for i in input().split()]
b=[]
for i in a:
if i not in b:
b.append(i)
print(len(a)-len(b))
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
count=0
a=[int (i) for i in input().split()]
b=[]
for i in a:
if i not in b:
b.append(i)
print(len(a)-len(b))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,688,671,201 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | l=list(map(int,input().split()))
s=0
x=l[0]
for i in range(1,len(l)):
if x==l[i]:
s += 1
else:
x=l[i]
print(s)
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
l=list(map(int,input().split()))
s=0
x=l[0]
for i in range(1,len(l)):
if x==l[i]:
s += 1
else:
x=l[i]
print(s)
``` | 0 | 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,690,264,142 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | a=list(input())
c=0
for i in a:
if i=='H' or i=='Q' or i=='9':
c=1
break
if c==1:
print("YES")
else:
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
a=list(input())
c=0
for i in a:
if i=='H' or i=='Q' or i=='9':
c=1
break
if c==1:
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,558,857,012 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 216 | 0 | x=int(input())
s=[]
z=[int(n) for n in input().split()]
s+=z
d=[n for n in range(min(z),max(z)+2)]
z.sort()
l=0
for n in range(x):
if z[n]==d[n]:
l=0
continue
else:
l=1
print(d[n])
break
if l==0:
print(d[max(z)])
| Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
x=int(input())
s=[]
z=[int(n) for n in input().split()]
s+=z
d=[n for n in range(min(z),max(z)+2)]
z.sort()
l=0
for n in range(x):
if z[n]==d[n]:
l=0
continue
else:
l=1
print(d[n])
break
if l==0:
print(d[max(z)])
``` | -1 | 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,565,327,527 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 78 | 0 |
t=int(input())
while True:
n=int(input())
print(((((n-6)*n+23)*n-18)*n+24)/24)
t-=1 | 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
t=int(input())
while True:
n=int(input())
print(((((n-6)*n+23)*n-18)*n+24)/24)
t-=1
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
583 | B | Robot's Task | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to colle... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. | Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information. | [
"3\n0 2 0\n",
"5\n4 2 3 0 1\n",
"7\n0 3 1 0 5 2 6\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to... | 1,000 | [
{
"input": "3\n0 2 0",
"output": "1"
},
{
"input": "5\n4 2 3 0 1",
"output": "3"
},
{
"input": "7\n0 3 1 0 5 2 6",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "0"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"out... | 1,493,795,475 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 327 | 5,632,000 | n = int(input())
arr = [int(x) for x in input().split()]
c = 0
ans = 0
cnt = 0
for i in range(n):
for j in range(n):
if arr[j]==-1:
cnt += 1
elif arr[j]<=c:
c += 1
arr[j] = -1
cnt +=1
if cnt==n:
break
else:
cnt = 0
ans += 1
for j in range(n-1,-1,-1):
if arr[j]==-1:
cnt += 1
elif arr[j]<=... | Title: Robot's Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The compu... | ```python
n = int(input())
arr = [int(x) for x in input().split()]
c = 0
ans = 0
cnt = 0
for i in range(n):
for j in range(n):
if arr[j]==-1:
cnt += 1
elif arr[j]<=c:
c += 1
arr[j] = -1
cnt +=1
if cnt==n:
break
else:
cnt = 0
ans += 1
for j in range(n-1,-1,-1):
if arr[j]==-1:
cnt += 1
eli... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states *i*, *j* and *k* are selected, where *i*<=<<=*j*<=<<=*k*... | The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*.
The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=<<=*E*2...<=<<=*E**n*<=≤<=109). It is guaranteed th... | If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9.
Formally, let your answer be *a*, and the jury's answe... | [
"4 4\n1 3 5 7\n",
"10 8\n10 13 15 16 17 19 20 22 24 25\n",
"3 1\n2 5 10\n"
] | [
"0.5\n",
"0.875\n",
"-1\n"
] | In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second example choose states 4, 5 a... | 0 | [
{
"input": "4 4\n1 3 5 7",
"output": "0.5"
},
{
"input": "10 8\n10 13 15 16 17 19 20 22 24 25",
"output": "0.875"
},
{
"input": "3 1\n2 5 10",
"output": "-1"
},
{
"input": "5 3\n4 6 8 9 10",
"output": "0.5"
},
{
"input": "10 128\n110 121 140 158 174 188 251 271 27... | 1,580,202,077 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 389 | 8,806,400 | N,U = map(int,input().strip().split())
E = list(map(int,input().strip().split()))
maxu = -1
j = 2
if N < 3:
print(-1)
for i in range(N-2):
j = max(i+2,j)
if E[j] -E[i] > U:
continue
while j < N and E[j] - E[i] <= U:
j += 1
j -= 1
maxu = max(maxu, (E[j] - E[i+1]) / ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the sche... | ```python
N,U = map(int,input().strip().split())
E = list(map(int,input().strip().split()))
maxu = -1
j = 2
if N < 3:
print(-1)
for i in range(N-2):
j = max(i+2,j)
if E[j] -E[i] > U:
continue
while j < N and E[j] - E[i] <= U:
j += 1
j -= 1
maxu = max(maxu, (E[j] - ... | 3 | 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,514,914,031 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,529,600 | s = input()
k = int(input())
def uneq(s):
s_new = ''
for i in range(len(s)):
if s_new.find(s[i]) == -1 and s[i] != ' ':
s_new += s[i]
return s_new
i = 0
j = 0
if k > len(s):
print('impossible')
exit()
elif len(s) == len(s_new):
print('0')
exit()
s_new = uneq(s)
while i < k... | 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())
def uneq(s):
s_new = ''
for i in range(len(s)):
if s_new.find(s[i]) == -1 and s[i] != ' ':
s_new += s[i]
return s_new
i = 0
j = 0
if k > len(s):
print('impossible')
exit()
elif len(s) == len(s_new):
print('0')
exit()
s_new = uneq(s)
w... | -1 | 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,698,767,198 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | N = int(input())
esimene = list(map(int,input().split()))
teine = list(map(int,input().split()))
esimene = esimene[1:]
teine = teine[1:]
koos = esimene + teine
hulk = set(koos)
if len(hulk) == 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())
esimene = list(map(int,input().split()))
teine = list(map(int,input().split()))
esimene = esimene[1:]
teine = teine[1:]
koos = esimene + teine
hulk = set(koos)
if len(hulk) == N:
print("I become the guy.")
else:
print("Oh, my keyboard!")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
14 | B | Young Photographer | PROGRAMMING | 1,000 | [
"implementation"
] | B. Young Photographer | 2 | 64 | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at t... | The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | [
"3 3\n0 7\n14 2\n4 6\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "3 3\n0 7\n14 2\n4 6",
"output": "1"
},
{
"input": "1 1\n0 10",
"output": "0"
},
{
"input": "2 2\n1 2\n3 2",
"output": "0"
},
{
"input": "3 2\n1 2\n2 3\n3 4",
"output": "-1"
},
{
"input": "2 4\n10 4\n1 5",
"output": "0"
},
{
"input": "1 10\n... | 1,598,070,754 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 6,963,200 | n,x = map(int,input().split())
c = [[0,10000000]]
for i in range(n):
a,b = map(int,input().split())
if(a<=b):
if(c[-1][-1]>=a):
c[-1][0] = max(c[-1][0],a)
c[-1][-1] = min(c[-1][-1],b)
else:
print(-1)
exit()
else:
b,a = a,b... | Title: Young Photographer
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. Bu... | ```python
n,x = map(int,input().split())
c = [[0,10000000]]
for i in range(n):
a,b = map(int,input().split())
if(a<=b):
if(c[-1][-1]>=a):
c[-1][0] = max(c[-1][0],a)
c[-1][-1] = min(c[-1][-1],b)
else:
print(-1)
exit()
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
505 | B | Mr. Kitayuta's Colorful Graph | PROGRAMMING | 1,400 | [
"dfs and similar",
"dp",
"dsu",
"graphs"
] | null | null | Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he giv... | The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c*... | For each query, print the answer in a separate line. | [
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n"
] | [
"2\n1\n0\n",
"1\n1\n1\n1\n2\n"
] | Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | 1,000 | [
{
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4",
"output": "2\n1\n0"
},
{
"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4",
"output": "1\n1\n1\n1\n2"
},
{
"input": "2 1\n1 2 1\n1\n1 2",
"output": "1"
},
{
"input... | 1,655,787,388 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 2,457,600 | import sys
input = sys.stdin.readline
def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
eli... | Title: Mr. Kitayuta's Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting v... | ```python
import sys
input = sys.stdin.readline
def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroo... | 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,661,067,657 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s=input()
s1=''
l1=[]
lcount=0
for i in s:
if i=='l' and lcount<2:
s1=s1+i
lcount=lcount+1
elif i not in l1:
s1=s1+i
if 'hello' in s1:
print('YES')
else:
print('NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
s1=''
l1=[]
lcount=0
for i in s:
if i=='l' and lcount<2:
s1=s1+i
lcount=lcount+1
elif i not in l1:
s1=s1+i
if 'hello' in s1:
print('YES')
else:
print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,657,447,383 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 77 | 0 | inpt = input()
count = 0
for i in range (len(inpt)):
c1 = inpt[i]
for j in range (i+1, len(inpt)):
c2 = inpt[j]
for k in range (j+1,len(inpt)):
c3 = inpt[k]
if c1 == "Q" and c2 == "A" and c3 == "Q":
count += 1
print (count) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
inpt = input()
count = 0
for i in range (len(inpt)):
c1 = inpt[i]
for j in range (i+1, len(inpt)):
c2 = inpt[j]
for k in range (j+1,len(inpt)):
c3 = inpt[k]
if c1 == "Q" and c2 == "A" and c3 == "Q":
count += 1
print (count)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
220 | B | Little Elephant and Array | PROGRAMMING | 1,800 | [
"constructive algorithms",
"data structures"
] | null | null | The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of array *a* and the number of queries to it. The next line contains *n* space-separated positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Next *m* lines contain descriptions of queries, one per line. T... | In *m* lines print *m* integers — the answers to the queries. The *j*-th line should contain the answer to the *j*-th query. | [
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"
] | [
"3\n1\n"
] | none | 1,000 | [
{
"input": "7 2\n3 1 2 2 3 3 7\n1 7\n3 4",
"output": "3\n1"
},
{
"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6",
"output": "1\n0\n2\n1\n1\n3"
},
{
"input": "1 2\n1\n1 1\n1 1",
"output": "1\n1"
},
{
"input": "1 1\n1000000000\n1 1",
"output": "0"
}
] | 1,686,739,795 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def solve(n, m, a, queries):
"""
Solves the Little Elephant array problem.
Args:
n: The size of the array.
m: The number of queries.
a: The array of integers.
queries: The list of queries.
Returns:
A list of integers, where the i-th integer is the answer to the i-th query.
""... | Title: Little Elephant and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant... | ```python
def solve(n, m, a, queries):
"""
Solves the Little Elephant array problem.
Args:
n: The size of the array.
m: The number of queries.
a: The array of integers.
queries: The list of queries.
Returns:
A list of integers, where the i-th integer is the answer to the i-th qu... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
765 | C | Table Tennis Game 2 | PROGRAMMING | 1,200 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* poi... | The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | 1,250 | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "... | 1,501,671,883 | 2,147,483,647 | Python 3 | OK | TESTS | 279 | 62 | 4,608,000 | k,a,b=map(int, input().split())
if a<k and b % k != 0 or b < k and a % k !=0:
print(-1)
else:
print(a//k+b//k)
| Title: Table Tennis Game 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scor... | ```python
k,a,b=map(int, input().split())
if a<k and b % k != 0 or b < k and a % k !=0:
print(-1)
else:
print(a//k+b//k)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,675,107,596 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 124 | 0 | n,m = map(int,input().split())
tc = list(map(int,input().split()))
tc.sort()
mi = tc[n-1] - tc[0]
for i in range(1,m-n+1):
if(tc[i+n-1] - tc[i] < mi):
mi = tc[i+n-1] - tc[i]
print(mi)
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m = map(int,input().split())
tc = list(map(int,input().split()))
tc.sort()
mi = tc[n-1] - tc[0]
for i in range(1,m-n+1):
if(tc[i+n-1] - tc[i] < mi):
mi = tc[i+n-1] - tc[i]
print(mi)
``` | 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,661,197,140 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 716,800 | a = list(map(int, input().split(' ')))
s = list(map(int, input()))
cal = 0
for i in s:
cal += a[i - 1]
print(cal) | 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
a = list(map(int, input().split(' ')))
s = list(map(int, input()))
cal = 0
for i in s:
cal += a[i - 1]
print(cal)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,511,352,442 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 77 | 0 | n, t = map(int, input().split())
a = list(map(int, input().split()))
d = 0
for time in a:
d += 1
t -= 86400 - time
if t <= 0:
break
if t <= 0:
print(d)
else:
print(d + 1) | Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n, t = map(int, input().split())
a = list(map(int, input().split()))
d = 0
for time in a:
d += 1
t -= 86400 - time
if t <= 0:
break
if t <= 0:
print(d)
else:
print(d + 1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,609,304,013 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 48 | 218 | 307,200 | '''http://codeforces.com/contest/129/problem/B'''
n,m = map(int, input().split(" "))
dictX = {}
for i in range(1,n+1):
dictX[i] = []
for j in range(m):
x,y = map(int, input().split(" "))
dictX[x].append(y)
dictX[y].append(x)
for k in range(1,n+1):
if len(dictX[k])==0:
di... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
'''http://codeforces.com/contest/129/problem/B'''
n,m = map(int, input().split(" "))
dictX = {}
for i in range(1,n+1):
dictX[i] = []
for j in range(m):
x,y = map(int, input().split(" "))
dictX[x].append(y)
dictX[y].append(x)
for k in range(1,n+1):
if len(dictX[k])==0:
... | 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,647,240,070 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 187 | 16,793,600 | #!/usr/bin/env python
import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
n = int(wtf[0])
A = map(int, wtf[1].split())
ans = []
T = set()
for a in A:
if a not in T:
T.ad... | 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
#!/usr/bin/env python
import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
n = int(wtf[0])
A = map(int, wtf[1].split())
ans = []
T = set()
for a in A:
if a not in T:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
... | 1,597,475,135 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | s = int(input("Enter the number of students: "))
n = 1
for i in range(1, s):
n += i
if n % s == 0:
print(s)
else:
print(n % s, end=" ") | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think... | ```python
s = int(input("Enter the number of students: "))
n = 1
for i in range(1, s):
n += i
if n % s == 0:
print(s)
else:
print(n % s, end=" ")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexit... | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ... | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"inp... | 1,533,959,382 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 139 | 0 | first_line = list(map(int, input().split()))
n = first_line[0]
a = first_line[1]
b = first_line[2]
ch = list(map(int, input().split()))
def main():
# sort the array in a non-decreasing order
# V will take the first a chores, P the rest
ch.sort()
if a == b:
print(ch[b] - ch[a-1])
else:
... | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th... | ```python
first_line = list(map(int, input().split()))
n = first_line[0]
a = first_line[1]
b = first_line[2]
ch = list(map(int, input().split()))
def main():
# sort the array in a non-decreasing order
# V will take the first a chores, P the rest
ch.sort()
if a == b:
print(ch[b] - ch[a-1])... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,618,002,433 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 3,000 | 0 | n = int(input())
cont=0
for i in range(1,n+1):
for j in range(i,n+1):
if i**2 + j**2 <= n**2 and ((i**2 + j**2)**0.5)%1==0:
cont+=1
print(cont)
| Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
n = int(input())
cont=0
for i in range(1,n+1):
for j in range(i,n+1):
if i**2 + j**2 <= n**2 and ((i**2 + j**2)**0.5)%1==0:
cont+=1
print(cont)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,633,294,246 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 7,065,600 | from collections import defaultdict
n, k = map(int, input().split())
n_tasks = list(map(int, input().split()))
m_tasks = {num: 1 for num in map(int, input().split())}
res = 0
for task in n_tasks:
if task not in m_tasks:
res += 1
m_tasks[task] = 1
print(res)
| Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
from collections import defaultdict
n, k = map(int, input().split())
n_tasks = list(map(int, input().split()))
m_tasks = {num: 1 for num in map(int, input().split())}
res = 0
for task in n_tasks:
if task not in m_tasks:
res += 1
m_tasks[task] = 1
print(res)
``` | 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,681,394,522 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | t=int(input())
a=0
for _ in range(t):
x=input()
if x=='Tetrahedron':
y=4
elif x=='cube':
y=6
elif x=='Octahedron':
y=8
elif x=='Dodecahedron':
y=12
elif x=='Icosahedron':
y=20
a+=y
print(a) | 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
t=int(input())
a=0
for _ in range(t):
x=input()
if x=='Tetrahedron':
y=4
elif x=='cube':
y=6
elif x=='Octahedron':
y=8
elif x=='Dodecahedron':
y=12
elif x=='Icosahedron':
y=20
a+=y
print(a)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,691,002,894 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n, m=[int(el) for el in input().split()]
print(n*m//2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n, m=[int(el) for el in input().split()]
print(n*m//2)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
361 | A | Levko and Table | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them. | [
"2 4\n",
"4 7\n"
] | [
"1 3\n3 1\n",
"2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n"
] | In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table... | 500 | [
{
"input": "2 4",
"output": "4 0 \n0 4 "
},
{
"input": "4 7",
"output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 "
},
{
"input": "1 8",
"output": "8 "
},
{
"input": "9 3",
"output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0... | 1,613,778,589 | 2,147,483,647 | PyPy 3 | OK | TESTS | 22 | 124 | 2,867,200 | n, k = map(int, input().split())
for i in range(n):
lst = [0] * n
lst[i] = k
print(*lst)
| Title: Levko and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortun... | ```python
n, k = map(int, input().split())
for i in range(n):
lst = [0] * n
lst[i] = k
print(*lst)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
887 | B | Cubes for Masha | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*.
To make a number Masha can rotate her cubes and put them in a ro... | In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday.
Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube. | Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1. | [
"3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n",
"3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n"
] | [
"87",
"98"
] | In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8. | 1,000 | [
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7",
"output": "87"
},
{
"input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9",
"output": "98"
},
{
"input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5",
"output": "5"
},
{
"input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8",
... | 1,609,097,344 | 2,147,483,647 | Python 3 | OK | TESTS | 96 | 124 | 307,200 | from itertools import permutations
#C = comb
from math import *
n = int(input())
mat = [list(map(int, input().split())) for _ in range(n)]
mp = {}
for vk in mat:
for el in vk:
mp[str(el)] = True
def app(a):
for per in permutations(a):
if per[0] != 0:
s = ''
... | Title: Cubes for Masha
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her ne... | ```python
from itertools import permutations
#C = comb
from math import *
n = int(input())
mat = [list(map(int, input().split())) for _ in range(n)]
mp = {}
for vk in mat:
for el in vk:
mp[str(el)] = True
def app(a):
for per in permutations(a):
if per[0] != 0:
s = ''
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,639,220,915 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
def is_(n):
d = n%7
check = True
if d%3 == 0:
check = True
else:
check = False
if n%3 == 0:
check = True
return check
for i in range(n):
a = input()
if is_(int(a)):
print('YES')
else:print('NO') | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
n = int(input())
def is_(n):
d = n%7
check = True
if d%3 == 0:
check = True
else:
check = False
if n%3 == 0:
check = True
return check
for i in range(n):
a = input()
if is_(int(a)):
print('YES')
else:print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
44 | I | Toys | PROGRAMMING | 2,300 | [
"brute force",
"combinatorics"
] | I. Toys | 5 | 256 | Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her *n* toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Having seen it, Masha got very upset and started crying. Sasha still ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=10) — the number of toys. | In the first line print the number of different variants of arrangement of toys into piles. Then print all the ways of arranging toys into piles in the order in which Sasha should try them (i.e. every next way must result from the previous one through the operation described in the statement). Every way should be print... | [
"3\n"
] | [
"5\n{1,2,3}\n{1,2},{3}\n{1},{2,3}\n{1},{2},{3}\n{1,3},{2}"
] | none | 0 | [
{
"input": "3",
"output": "5\n{1,2,3}\n{1,2},{3}\n{1},{2,3}\n{1},{2},{3}\n{1,3},{2}"
},
{
"input": "1",
"output": "1\n{1}"
},
{
"input": "2",
"output": "2\n{1,2}\n{1},{2}"
},
{
"input": "4",
"output": "15\n{1,2,3,4}\n{1,2,3},{4}\n{1,2},{3,4}\n{1,2},{3},{4}\n{1,2,4},{3}\n{... | 1,691,053,843 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | import sys
readline = sys.stdin.readline
def read() -> int:
return int(readline().strip())
def solve(n: int) -> list:
if n == 1:
return [[(1,)]]
part1 = solve(n - 1)
result = []
invert = True
for comb in part1:
tmp = [comb + [(n,)]]
for i in range(len(comb)):
... | Title: Toys
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her *n* toys into several piles and then her elder brother Sasha came and gathered all the... | ```python
import sys
readline = sys.stdin.readline
def read() -> int:
return int(readline().strip())
def solve(n: int) -> list:
if n == 1:
return [[(1,)]]
part1 = solve(n - 1)
result = []
invert = True
for comb in part1:
tmp = [comb + [(n,)]]
for i in range(len(comb)):... | 0 | MatrixStudio/Codeforces-Python-Submissions |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,638,537,645 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 560 | 0 | n,d= map(int,input().split())
a = list(map(int,input().split()))
count = 0
ls1 = []
ls = []
for i in range(n):
for j in range(i+1,n):
if abs(a[i] - a[j]) <= d:
count += 2
print(count)
| Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n,d= map(int,input().split())
a = list(map(int,input().split()))
count = 0
ls1 = []
ls = []
for i in range(n):
for j in range(i+1,n):
if abs(a[i] - a[j]) <= d:
count += 2
print(count)
``` | 3.86 | 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,672,841,740 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | a=input()
b=a.count('l')
if(b>=2):
if(a.index('h') < a.index('e') and a.index('e') < a.index('l') and a.index('l') < a.index('o')):
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a=input()
b=a.count('l')
if(b>=2):
if(a.index('h') < a.index('e') and a.index('e') < a.index('l') and a.index('l') < a.index('o')):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,586,039,005 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | a, b, c = map(int, input().split())
out = 'YES'
if b < a :
out = 'NO'
elif b == a :
out = 'YES'
else :
dif = b - a
if dif % c == 0 :
out = 'YES'
else :
out = 'NO'
print(out)
| Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a, b, c = map(int, input().split())
out = 'YES'
if b < a :
out = 'NO'
elif b == a :
out = 'YES'
else :
dif = b - a
if dif % c == 0 :
out = 'YES'
else :
out = 'NO'
print(out)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
955 | B | Not simply beatiful strings | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a ... | The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters. | Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case. | [
"ababa\n",
"zzcxx\n",
"yeee\n"
] | [
"Yes\n",
"Yes\n",
"No\n"
] | In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | 1,000 | [
{
"input": "ababa",
"output": "Yes"
},
{
"input": "zzcxx",
"output": "Yes"
},
{
"input": "yeee",
"output": "No"
},
{
"input": "a",
"output": "No"
},
{
"input": "bbab",
"output": "No"
},
{
"input": "abcd",
"output": "Yes"
},
{
"input": "abc"... | 1,521,900,672 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 108 | 7,168,000 | from collections import Counter
freq_dict = Counter(input())
if len(freq_dict) <= 1 or len(freq_dict) > 4:
print('No')
else:
if len(freq_dict) == 4:
print('Yes')
if len(freq_dict) == 2:
values = freq_dict.values()
if [v for v in values if v < 2]:
print('No')
els... | Title: Not simply beatiful strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, abab... | ```python
from collections import Counter
freq_dict = Counter(input())
if len(freq_dict) <= 1 or len(freq_dict) > 4:
print('No')
else:
if len(freq_dict) == 4:
print('Yes')
if len(freq_dict) == 2:
values = freq_dict.values()
if [v for v in values if v < 2]:
print('No')
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,696,660,794 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a,b=map(int,input().split())
n=0
if a<=b:
n+=1
a*(3**n)
b*(3**n)
print(n) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
a,b=map(int,input().split())
n=0
if a<=b:
n+=1
a*(3**n)
b*(3**n)
print(n)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,695,049,762 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | # A. Elephant
distance = int(input())
result = 0
while True:
if(distance <= 5):
result += 1
break
else :
result += distance // 5
distance -= (distance // 5) * 5
print(result) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
# A. Elephant
distance = int(input())
result = 0
while True:
if(distance <= 5):
result += 1
break
else :
result += distance // 5
distance -= (distance // 5) * 5
print(result)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,684,124,970 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 92 | 0 | n = int(input())
soldiers = list(map(int, input().split()))
count_moves_max = 0
count_moves_min = 0
loopi = True
while loopi:
if soldiers[0] != max(soldiers):
i = soldiers.index(max(soldiers))
soldiers[i], soldiers[i - 1] = soldiers[i - 1], soldiers[i]
count_moves_max += 1
else... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n = int(input())
soldiers = list(map(int, input().split()))
count_moves_max = 0
count_moves_min = 0
loopi = True
while loopi:
if soldiers[0] != max(soldiers):
i = soldiers.index(max(soldiers))
soldiers[i], soldiers[i - 1] = soldiers[i - 1], soldiers[i]
count_moves_max += 1... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,644,753,115 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n = int(input())
ans = ""
while n>7:
n-=7
ans+="7"
while n-4>=4:
n-=4
ans+="4"
if n>0:
print(-1)
else:
print(ans[::-1]) | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
ans = ""
while n>7:
n-=7
ans+="7"
while n-4>=4:
n-=4
ans+="4"
if n>0:
print(-1)
else:
print(ans[::-1])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
225 | C | Barcode | PROGRAMMING | 1,700 | [
"dp",
"matrices"
] | null | null | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome ... | The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The pictur... | In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists. | [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
] | [
"11\n",
"5\n"
] | In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | 1,500 | [
{
"input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..",
"output": "11"
},
{
"input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#",
"output": "24"
},
{
"input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#",
"output": "6"
},
{
"input": "5 ... | 1,663,440,958 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = stack.append(f(*args, **kwargs))
while True:
try:
to = stack.append(stack[-1].send(to))
except... | Title: Barcode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulf... | ```python
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = stack.append(f(*args, **kwargs))
while True:
try:
to = stack.append(stack[-1].send(to))
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ... | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and... | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 ... | 1,479,639,000 | 6,300 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 62 | 0 | n, m = map(int, input().split())
stage = [[None]*m]*n
for i in range(n):
stage[i] = list(map(int, input().split()))
del i
good = 0
for i in range(n):
for j in range(m):
if not stage[i][j]:
if 1 in stage[i][j:]:
good += 1
if 1 in stage[i][:j]:
... | Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to pl... | ```python
n, m = map(int, input().split())
stage = [[None]*m]*n
for i in range(n):
stage[i] = list(map(int, input().split()))
del i
good = 0
for i in range(n):
for j in range(m):
if not stage[i][j]:
if 1 in stage[i][j:]:
good += 1
if 1 in stage[i]... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
398 | B | Painting The Wall | PROGRAMMING | 0 | [
"dp",
"probabilities"
] | null | null | User ainta decided to paint a wall. The wall consists of *n*2 tiles, that are arranged in an *n*<=×<=*n* table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the rules below.
1. Firstly user ainta looks at the wall. If there is at least one painted cell on each ro... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=2·103; 0<=≤<=*m*<=≤<=*min*(*n*2,<=2·104)) — the size of the wall and the number of painted cells.
Next *m* lines goes, each contains two integers *r**i* and *c**i* (1<=≤<=*r**i*,<=*c**i*<=≤<=*n*) — the position of the painted cell. It is guaranteed that t... | In a single line print the expected time to paint the wall in minutes. Your answer will be considered correct if it has at most 10<=-<=4 absolute or relative error. | [
"5 2\n2 3\n4 1\n",
"2 2\n1 1\n1 2\n",
"1 1\n1 1\n"
] | [
"11.7669491886\n",
"2.0000000000\n",
"0.0000000000\n"
] | none | 1,000 | [] | 1,694,378,016 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 102,400 | def main():
n, m = map(int, input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
f = [[0] * (n + 1) for _ in range(n + 1)]
a[0] = b[0] = 1
for i in range(1, n + 1):
a[i] = a[i - 1] * i
b[i] = b[i - 1] / i
for i in range(n + 1):
f[i][0] = f[0][i] = i
for i in range... | Title: Painting The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta decided to paint a wall. The wall consists of *n*2 tiles, that are arranged in an *n*<=×<=*n* table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the r... | ```python
def main():
n, m = map(int, input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
f = [[0] * (n + 1) for _ in range(n + 1)]
a[0] = b[0] = 1
for i in range(1, n + 1):
a[i] = a[i - 1] * i
b[i] = b[i - 1] / i
for i in range(n + 1):
f[i][0] = f[0][i] = i
for ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is ... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ... | 1,678,478,493 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | N = int(input())
flats = input()
lptr, rptr = 0, N - 1
while True:
if flats[lptr] in flats[lptr + 1:rptr]:
lptr += 1
else: break
while True:
if flats[rptr] in flats[lptr:rptr - 1]:
rptr -= 1
else: break
print((rptr - lptr) + 1)
| Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each ... | ```python
N = int(input())
flats = input()
lptr, rptr = 0, N - 1
while True:
if flats[lptr] in flats[lptr + 1:rptr]:
lptr += 1
else: break
while True:
if flats[rptr] in flats[lptr:rptr - 1]:
rptr -= 1
else: break
print((rptr - lptr) + 1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
30 | A | Accounting | PROGRAMMING | 1,400 | [
"brute force",
"math"
] | A. Accounting | 2 | 256 | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there w... | The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). | Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. | [
"2 18 2\n",
"-1 8 3\n",
"0 0 10\n",
"1 16 5\n"
] | [
"3",
"-2",
"5",
"No solution"
] | none | 500 | [
{
"input": "2 18 2",
"output": "3"
},
{
"input": "-1 8 3",
"output": "-2"
},
{
"input": "0 0 10",
"output": "5"
},
{
"input": "1 16 5",
"output": "No solution"
},
{
"input": "0 1 2",
"output": "No solution"
},
{
"input": "3 0 4",
"output": "0"
},... | 1,521,807,557 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 40 | 186 | 21,401,600 | A,B,n = list(map(int,input().split(" ")))
neg = False
if (A == 0 or n == 0) and A!= B: print("No solution");
elif A==B:print(1)
else:
x = B/A
if x < 0:
neg = True;
x = abs(x)
if (x)**(1/n) != int((x)**(1/n)):print("No solution")
elif neg and n%2 ==1: print(-int((x)**(1/n)))
else: print(int((x)**(1/n))) | Title: Accounting
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as th... | ```python
A,B,n = list(map(int,input().split(" ")))
neg = False
if (A == 0 or n == 0) and A!= B: print("No solution");
elif A==B:print(1)
else:
x = B/A
if x < 0:
neg = True;
x = abs(x)
if (x)**(1/n) != int((x)**(1/n)):print("No solution")
elif neg and n%2 ==1: print(-int((x)**(1/n)))
else: print(int((x)**(1/n... | 0 | MatrixStudio/Codeforces-Python-Submissions |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,633,945,338 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 6,758,400 | M,N = map(int, input().split())
x = M*N//2
print(x) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M,N = map(int, input().split())
x = M*N//2
print(x)
``` | 3.956411 | MatrixStudio/Codeforces-Python-Submissions |
435 | A | Queue on Bus Stop | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). | Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. | [
"4 3\n2 3 2 1\n",
"3 4\n1 2 1\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "4 3\n2 3 2 1",
"output": "3"
},
{
"input": "3 4\n1 2 1",
"output": "1"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "6 4\n1 3 2 3 4 1",
"output": "5"
},
{
"input": "6 8\n6 1 1 1 4 5",
... | 1,600,933,791 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | n,m=map(int, input().split())
a=list(map(int, input().split()))
if sum(a)%m==0:
print(sum(a)//m)
else:
print(sum(a)//m+1) | Title: Queue on Bus Stop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand... | ```python
n,m=map(int, input().split())
a=list(map(int, input().split()))
if sum(a)%m==0:
print(sum(a)//m)
else:
print(sum(a)//m+1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.