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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
499 | A | Watching a movie | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie... | The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button.
The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains tw... | Output a single number — the answer to the problem. | [
"2 3\n5 6\n10 12\n",
"1 1\n1 100000\n"
] | [
"6\n",
"100000\n"
] | In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch th... | 500 | [
{
"input": "2 3\n5 6\n10 12",
"output": "6"
},
{
"input": "1 1\n1 100000",
"output": "100000"
},
{
"input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728",
"output": "53974"
},
{
"input": "1... | 1,694,001,377 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 0 | n,x = map(int,input().split())
l,r = [],[]
for i in range(n):
ll,rr = map(int,input().split())
l.append(ll)
r.append(rr)
all_min = 0
curr_end = 1
for i in range(n):
skip_min = (l[i] - curr_end)//x
new_l = curr_end + (skip_min * x)
all_min += r[i] - new_l + 1
curr_end = r[i] + 1
print(all_min) | Title: Watching a movie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the pl... | ```python
n,x = map(int,input().split())
l,r = [],[]
for i in range(n):
ll,rr = map(int,input().split())
l.append(ll)
r.append(rr)
all_min = 0
curr_end = 1
for i in range(n):
skip_min = (l[i] - curr_end)//x
new_l = curr_end + (skip_min * x)
all_min += r[i] - new_l + 1
curr_end = r[i] + 1
prin... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,608,474,444 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | import math
a=int(input())
b=int(input())
c=int(input())
x=math.sqrt((a*c)/b)
y=c/math.sqrt((a*c)/b)
z=(b*(math.sqrt((a*c)/b))/c)
print(4*(x+y+z))
| Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
a=int(input())
b=int(input())
c=int(input())
x=math.sqrt((a*c)/b)
y=c/math.sqrt((a*c)/b)
z=(b*(math.sqrt((a*c)/b))/c)
print(4*(x+y+z))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
339 | B | Xenia and Ringroad | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). Note that Xenia can have multiple consecutive tasks in one house. | Print a single integer — the time Xenia needs to complete all tasks.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n3 2 3\n",
"4 3\n2 3 3\n"
] | [
"6\n",
"2\n"
] | In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units. | 1,000 | [
{
"input": "4 3\n3 2 3",
"output": "6"
},
{
"input": "4 3\n2 3 3",
"output": "2"
},
{
"input": "2 2\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "100 100\n56 46 1 47 5 86 45 35 81 1 ... | 1,698,418,000 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 216 | 13,824,000 | a,b=map(int,input().split())
s=list(map(int,input().split()))
l=[1]
l.extend(s)
time=0
for i in range(len(l)-1):
if l[i]<l[i+1]:
time+=l[i+1]-l[i]
elif l[i]==l[i+1]:
time+=0
else:
time+=a-l[i]+l[i+1]
print(time) | Title: Xenia and Ringroad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recent... | ```python
a,b=map(int,input().split())
s=list(map(int,input().split()))
l=[1]
l.extend(s)
time=0
for i in range(len(l)-1):
if l[i]<l[i+1]:
time+=l[i+1]-l[i]
elif l[i]==l[i+1]:
time+=0
else:
time+=a-l[i]+l[i+1]
print(time)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
793 | B | Igor and his way to work | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"implementation",
"shortest paths"
] | null | null | Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the grid.
Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell; - "*" — a cell with road ... | In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise. | [
"5 5\n..S..\n****.\nT....\n****.\n.....\n",
"5 5\nS....\n****.\n.....\n.****\n..T..\n"
] | [
"YES",
"NO"
] | The first sample is shown on the following picture:
In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture: | 1,000 | [
{
"input": "5 5\nS....\n****.\n.....\n.****\n..T..",
"output": "NO"
},
{
"input": "1 2\nST",
"output": "YES"
},
{
"input": "3 1\nS\n*\nT",
"output": "NO"
},
{
"input": "3 3\n*..\n...\nTS.",
"output": "YES"
},
{
"input": "3 3\nT.*\n*.*\n*S*",
"output": "YES"
... | 1,492,971,159 | 5,259 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 46 | 5,529,600 | __author__ = 'Alexander'
s = [0,0]
t = [0,0]
def rotate(n, m, map):
global s, t
result = ['']*m
for i in range(n):
for j in range(m):
result[j] += map[i][j]
if map[i][j] == 'S': s = [j, i]
if map[i][j] == 'T': t = [j, i]
return result
def Task(... | Title: Igor and his way to work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, th... | ```python
__author__ = 'Alexander'
s = [0,0]
t = [0,0]
def rotate(n, m, map):
global s, t
result = ['']*m
for i in range(n):
for j in range(m):
result[j] += map[i][j]
if map[i][j] == 'S': s = [j, i]
if map[i][j] == 'T': t = [j, i]
return result
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,664,205,476 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 1,740,800 | [n,k] = [int(j) for j in str(input()).split(' ')]
a = [int(j) for j in str(input()).split(' ')]
i = 1
while i < k:
i = i + a[i-1]
# print(i)
if i == k:
print("YES")
else:
print("NO") | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
[n,k] = [int(j) for j in str(input()).split(' ')]
a = [int(j) for j in str(input()).split(' ')]
i = 1
while i < k:
i = i + a[i-1]
# print(i)
if i == k:
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,417,428,769 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 124 | 0 | from sys import stdin
def main():
n = int(stdin.readline().strip())
l = tuple(map(int, stdin.readline().strip().split()))
a, b = map(int, stdin.readline().strip().split())
return sum(l[a-1:b-1])
print(main())
| Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
from sys import stdin
def main():
n = int(stdin.readline().strip())
l = tuple(map(int, stdin.readline().strip().split()))
a, b = map(int, stdin.readline().strip().split())
return sum(l[a-1:b-1])
print(main())
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,699,261,867 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n=int(input())
a=[int(i) for i in input().split()]
mini=maxi=a[0]
ans=0
for i in range(1,n):
if a[i]<mini:
mini=a[i]
ans+=1
if a[i]>maxi:
maxi=a[i]
ans+=1
print(ans) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
a=[int(i) for i in input().split()]
mini=maxi=a[0]
ans=0
for i in range(1,n):
if a[i]<mini:
mini=a[i]
ans+=1
if a[i]>maxi:
maxi=a[i]
ans+=1
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,627,717,815 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 6,963,200 | a = input()
b = input()
a = list(a)
b = list(b)
if len(b) != len(a):
print('NO')
else:
count = 0
for i in range(len(a)):
if a[i] != b[i]:
if i < len(a) - 1:
a[i], a[i + 1] = a[i + 1], a[i]
else:
a[i], a[i - 1] = a[i - 1], a[i]
coun... | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
a = input()
b = input()
a = list(a)
b = list(b)
if len(b) != len(a):
print('NO')
else:
count = 0
for i in range(len(a)):
if a[i] != b[i]:
if i < len(a) - 1:
a[i], a[i + 1] = a[i + 1], a[i]
else:
a[i], a[i - 1] = a[i - 1], a[i]
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1.... | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
}... | 1,549,944,151 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 280 | 7,372,800 | n, k = [int(x) for x in input().split()]
list1 = [int(x) for x in input().split()]
test_bool = False
if len(set(list1[k-1:]))>1:
print(-1)
elif k >= 2:
for i in range(k-2, -1, -1):
if list1[k-1] != list1[i]:
print(i+1)
test_bool = False
break
else:
... | Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the cur... | ```python
n, k = [int(x) for x in input().split()]
list1 = [int(x) for x in input().split()]
test_bool = False
if len(set(list1[k-1:]))>1:
print(-1)
elif k >= 2:
for i in range(k-2, -1, -1):
if list1[k-1] != list1[i]:
print(i+1)
test_bool = False
break
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
412 | B | Network Configuration | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* deno... | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | [
"3 2\n40 20 30\n",
"6 4\n100 20 40 20 50 50\n"
] | [
"30\n",
"40\n"
] | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | 1,000 | [
{
"input": "3 2\n40 20 30",
"output": "30"
},
{
"input": "6 4\n100 20 40 20 50 50",
"output": "40"
},
{
"input": "1 1\n16",
"output": "16"
},
{
"input": "2 1\n10000 17",
"output": "10000"
},
{
"input": "2 2\n200 300",
"output": "200"
},
{
"input": "3 1... | 1,397,846,449 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | n, k = map(int, input().split())
print(list(reversed(list(sorted(list(map(int, input().split()))))))[k - 1])
| Title: Network Configuration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly a... | ```python
n, k = map(int, input().split())
print(list(reversed(list(sorted(list(map(int, input().split()))))))[k - 1])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,683,041,971 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 77 | 409,600 | import bisect
a, b = ([int(x) for x in input().split()])
s=list(input())
s = sorted(s, key = s.count,reverse = True)
se=list(set(s))
import collections
elements_count = collections.Counter(s)
l=[elements_count[se[0]]]
for j in range(1,len(se)):
l.append(elements_count[se[j]])
l.sort()
l.reverse()
p=[l[0... | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
import bisect
a, b = ([int(x) for x in input().split()])
s=list(input())
s = sorted(s, key = s.count,reverse = True)
se=list(set(s))
import collections
elements_count = collections.Counter(s)
l=[elements_count[se[0]]]
for j in range(1,len(se)):
l.append(elements_count[se[j]])
l.sort()
l.reverse... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
621 | C | Wet Shark and Flowers | PROGRAMMING | 1,700 | [
"combinatorics",
"math",
"number theory",
"probabilities"
] | null | null | There are *n* sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks *i* and *i*<=+<=1 are neighbours for all *i* from 1 to *n*<=-<=1. Sharks *n* and 1 are neighbours too.
Each shark will grow some number of flowers *s**i*. For *i*-th shark value *s**i* is random integer equipro... | The first line of the input contains two space-separated integers *n* and *p* (3<=≤<=*n*<=≤<=100<=000,<=2<=≤<=*p*<=≤<=109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that *p* is prime.
The *i*-th of the following *n* lines contains information about *i*-th shark — two space-separat... | Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer... | [
"3 2\n1 2\n420 421\n420420 420421\n",
"3 5\n1 4\n2 3\n11 14\n"
] | [
"4500.0\n",
"0.0\n"
] | A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.
Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of ... | 1,500 | [
{
"input": "3 2\n1 2\n420 421\n420420 420421",
"output": "4500.0"
},
{
"input": "3 5\n1 4\n2 3\n11 14",
"output": "0.0"
},
{
"input": "3 3\n3 3\n2 4\n1 1",
"output": "4666.666666666667"
},
{
"input": "5 5\n5 204\n420 469\n417 480\n442 443\n44 46",
"output": "3451.25"
},... | 1,604,005,077 | 2,147,483,647 | Python 3 | OK | TESTS | 94 | 514 | 8,704,000 | def e(l1, r1, l2, r2, p):
nonprimes_1 = (r1 - l1 + 1) - (r1 // p) + ((l1 - 1) // p)
nonprimes_2 = (r2 - l2 + 1) - (r2 // p) + ((l2 - 1) // p)
return 1 - ((nonprimes_1 * nonprimes_2) / ((r1 - l1 + 1) * (r2 - l2 + 1)))
def main():
n, p = map(int, input().split())
l_r = [tuple(map(int, input().... | Title: Wet Shark and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks *i* and *i*<=+<=1 are neighbours for all *i* from 1 to *n*<=-<=1. Sharks *n* and 1 are neighbours too.
... | ```python
def e(l1, r1, l2, r2, p):
nonprimes_1 = (r1 - l1 + 1) - (r1 // p) + ((l1 - 1) // p)
nonprimes_2 = (r2 - l2 + 1) - (r2 // p) + ((l2 - 1) // p)
return 1 - ((nonprimes_1 * nonprimes_2) / ((r1 - l1 + 1) * (r2 - l2 + 1)))
def main():
n, p = map(int, input().split())
l_r = [tuple(map(int... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
88 | B | Keyboard | PROGRAMMING | 1,500 | [
"implementation"
] | B. Keyboard | 1 | 256 | Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they m... | The first line contains three integers *n*, *m*, *x* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*x*<=≤<=50).
Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys ... | If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes). | [
"2 2 1\nab\ncd\n1\nA\n",
"2 2 1\nab\ncd\n1\ne\n",
"2 2 1\nab\ncS\n5\nabcBA\n",
"3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n"
] | [
"-1\n",
"-1\n",
"1\n",
"2\n"
] | In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.
In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.
In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the key... | 1,000 | [
{
"input": "2 2 1\nab\ncd\n1\nA",
"output": "-1"
},
{
"input": "2 2 1\nab\ncd\n1\ne",
"output": "-1"
},
{
"input": "2 2 1\nab\ncS\n5\nabcBA",
"output": "1"
},
{
"input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG",
"output": "2"
},
... | 1,665,553,849 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 296 | 1,945,600 | n,m,d=map(int, input().split())
d=d**2
key={}
for i in range(26):
key[chr(ord('a')+i)]=-1
key[chr(ord('A')+i)]=-1
a=[]
for i in range(n):
a.append(input())
shift=[]
for i in range(n):
for j in range(m):
if a[i][j]=="S":
shift.append((i,j))
for i in range(n):
for j in range(m):
... | Title: Keyboard
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on ... | ```python
n,m,d=map(int, input().split())
d=d**2
key={}
for i in range(26):
key[chr(ord('a')+i)]=-1
key[chr(ord('A')+i)]=-1
a=[]
for i in range(n):
a.append(input())
shift=[]
for i in range(n):
for j in range(m):
if a[i][j]=="S":
shift.append((i,j))
for i in range(n):
for j in ra... | 3.848376 | MatrixStudio/Codeforces-Python-Submissions |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,570,360,770 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 717 | 307,200 | n = int(input())
arr = list(map(int, input().split()))
new_list = arr.copy()
ans = ""
for a in range(n):
ans+=str(1+sum(x > new_list[a] for x in arr))+" "
print(ans) | Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n = int(input())
arr = list(map(int, input().split()))
new_list = arr.copy()
ans = ""
for a in range(n):
ans+=str(1+sum(x > new_list[a] for x in arr))+" "
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
632 | D | Longest Subsequence | PROGRAMMING | 2,100 | [
"brute force",
"math",
"number theory"
] | null | null | You are given array *a* with *n* elements and the number *m*. Consider some subsequence of *a* and the value of least common multiple (LCM) of its elements. Denote LCM as *l*. Find any longest subsequence of *a* with the value *l*<=≤<=*m*.
A subsequence of *a* is an array we can get by erasing some elements of *a*. It... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=106) — the size of the array *a* and the parameter from the problem statement.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of *a*. | In the first line print two integers *l* and *k**max* (1<=≤<=*l*<=≤<=*m*,<=0<=≤<=*k**max*<=≤<=*n*) — the value of LCM and the number of elements in optimal subsequence.
In the second line print *k**max* integers — the positions of the elements from the optimal subsequence in the ascending order.
Note that you can fin... | [
"7 8\n6 2 9 2 7 2 3\n",
"6 4\n2 2 2 3 3 3\n"
] | [
"6 5\n1 2 4 6 7\n",
"2 3\n1 2 3\n"
] | none | 0 | [
{
"input": "7 8\n6 2 9 2 7 2 3",
"output": "6 5\n1 2 4 6 7"
},
{
"input": "6 4\n2 2 2 3 3 3",
"output": "2 3\n1 2 3"
},
{
"input": "10 50\n39 22 60 88 11 65 41 85 65 100",
"output": "22 2\n2 5"
},
{
"input": "100 343\n999 284 486 785 176 742 856 415 992 601 600 122 460 214 33... | 1,628,958,054 | 4,854 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 264 | 33,280,000 | from collections import defaultdict
import sys
input = sys.stdin.readline
def fast_prime_factorization(n):
d = [(i + 1) % 2 * 2 for i in range(n + 1)]
d[0], d[1] = 0, 1
for i in range(3, n + 1):
if d[i]:
continue
for j in range(i, n + 1, 2 * i):
if not d[j... | Title: Longest Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array *a* with *n* elements and the number *m*. Consider some subsequence of *a* and the value of least common multiple (LCM) of its elements. Denote LCM as *l*. Find any longest subsequence of *a* wit... | ```python
from collections import defaultdict
import sys
input = sys.stdin.readline
def fast_prime_factorization(n):
d = [(i + 1) % 2 * 2 for i in range(n + 1)]
d[0], d[1] = 0, 1
for i in range(3, n + 1):
if d[i]:
continue
for j in range(i, n + 1, 2 * i):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,592,217,002 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 307,200 | r,c=map(int,input().split())
store=[]
for i in range(r):
s=input()
for j in range(c):
if(s[j]=='S'):
store.append((i,j))
if(store==[]):
print(r*c)
else:
store = list(zip(*store))
k=r * c - len(store[0]) * len(store[1])
print([k,0][k<0]) | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
r,c=map(int,input().split())
store=[]
for i in range(r):
s=input()
for j in range(c):
if(s[j]=='S'):
store.append((i,j))
if(store==[]):
print(r*c)
else:
store = list(zip(*store))
k=r * c - len(store[0]) * len(store[1])
print([k,0][k<0])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,619,953,447 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 108 | 2,150,400 |
a=''
b=''
last = -1
one=0
two=0
for j in range(int(input())):
u=int(input())
if u>0:
one+=u
a+=str(u)
last=1
else:
two+=-u
b+=str(-u)
last=2
if one>=two:
if a>b:
print('first')
elif b>a:
pirn... | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
a=''
b=''
last = -1
one=0
two=0
for j in range(int(input())):
u=int(input())
if u>0:
one+=u
a+=str(u)
last=1
else:
two+=-u
b+=str(-u)
last=2
if one>=two:
if a>b:
print('first')
elif b>a:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,670,482,677 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 124 | 0 | n = int(input())
a = list(map(int,input().split()))
z = a.count(0)
f = n - z
print(-1 if z < 1 else 0 if f < 9 else '5'*(f//9*9)+'0'*z) | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n = int(input())
a = list(map(int,input().split()))
z = a.count(0)
f = n - z
print(-1 if z < 1 else 0 if f < 9 else '5'*(f//9*9)+'0'*z)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
238 | C | World Eater Brothers | PROGRAMMING | 2,100 | [
"dfs and similar",
"dp",
"greedy",
"trees"
] | null | null | You must have heard of the two brothers dreaming of ruling the world. With all their previous plans failed, this time they decided to cooperate with each other in order to rule the world.
As you know there are *n* countries in the world. These countries are connected by *n*<=-<=1 directed roads. If you don't consider... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=3000). Each of the next *n*<=-<=1 lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) saying there is a road from country *a**i* to country *b**i*.
Consider that countries are numbered from 1 to ... | In the only line of output print the minimum number of roads that their direction should be changed so that the brothers will be able to rule the world. | [
"4\n2 1\n3 1\n4 1\n",
"5\n2 1\n2 3\n4 3\n4 5\n"
] | [
"1\n",
"0\n"
] | none | 1,500 | [] | 1,690,486,745 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1690486744.9438648")# 1690486744.9438844 | Title: World Eater Brothers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You must have heard of the two brothers dreaming of ruling the world. With all their previous plans failed, this time they decided to cooperate with each other in order to rule the world.
As you know there are *n... | ```python
print("_RANDOM_GUESS_1690486744.9438648")# 1690486744.9438844
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizer... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000... | 1,650,217,567 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <cstdio>
#include <vector>
#include <algorithm>
int main(){
long n; scanf("%ld", &n);
std::vector<long> a(2 * n);
for(long p = 0; p < 2 * n; p++){scanf("%ld", &a[p]);}
sort(a.begin(), a.end());
puts(a[n - 1] < a[n] ? "YES" : "NO");
return 0;
} | Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by... | ```python
#include <cstdio>
#include <vector>
#include <algorithm>
int main(){
long n; scanf("%ld", &n);
std::vector<long> a(2 * n);
for(long p = 0; p < 2 * n; p++){scanf("%ld", &a[p]);}
sort(a.begin(), a.end());
puts(a[n - 1] < a[n] ? "YES" : "NO");
return 0;
}
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,603,263,254 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 307,200 | k=int(input())
q=input()
a=int(q.split(" ")[0])
i=1
if k>3:
while i+1<k:
x=int(q.split(" ")[i])
y=int(q.split(" ")[i+1])
if a%2==x%2:
if a%2==y%2:
i=i+1
else:
print(i+2)
break
else:
if ... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
k=int(input())
q=input()
a=int(q.split(" ")[0])
i=1
if k>3:
while i+1<k:
x=int(q.split(" ")[i])
y=int(q.split(" ")[i+1])
if a%2==x%2:
if a%2==y%2:
i=i+1
else:
print(i+2)
break
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,679,590,503 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 1,638,400 | import math
import itertools
b, c = map(int, input().split())
def prime_factors(num):
while num % 2 == 0:
yield 2
num = num // 2
for i in range(3, int(math.sqrt(num)) + 1, 2):
while num % i == 0:
yield i
num = num // i
if num > 2:
yield num
factors ... | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
import math
import itertools
b, c = map(int, input().split())
def prime_factors(num):
while num % 2 == 0:
yield 2
num = num // 2
for i in range(3, int(math.sqrt(num)) + 1, 2):
while num % i == 0:
yield i
num = num // i
if num > 2:
yield num... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
24 | A | Ring road | PROGRAMMING | 1,400 | [
"graphs"
] | A. Ring road | 2 | 256 | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly tw... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of cities (and roads) in Berland. Next *n* lines contain description of roads. Each road is described by three integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=100) — road is directed from city *a**i* t... | Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. | [
"3\n1 3 1\n1 2 1\n3 2 1\n",
"3\n1 3 1\n1 2 5\n3 2 1\n",
"6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n",
"4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n"
] | [
"1\n",
"2\n",
"39\n",
"0\n"
] | none | 0 | [
{
"input": "3\n1 3 1\n1 2 1\n3 2 1",
"output": "1"
},
{
"input": "3\n1 3 1\n1 2 5\n3 2 1",
"output": "2"
},
{
"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42",
"output": "39"
},
{
"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5",
"output": "0"
},
{
"input": "5\n... | 1,690,534,809 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 154 | 1,536,000 | lines = [w.rstrip() for w in open(0).readlines()]
n, data = int(lines[0]), dict()
for line in lines[1:]:
h, t, c = map(int, line.split())
data[(h,t)] = c
h1, t1, _ = map(int, lines[1].split())
lst = [h1, t1]
while len(lst) < n:
h, t = lst[-2], lst[-1]
x = next(d for d in data if t in [d[0],... | Title: Ring road
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were conne... | ```python
lines = [w.rstrip() for w in open(0).readlines()]
n, data = int(lines[0]), dict()
for line in lines[1:]:
h, t, c = map(int, line.split())
data[(h,t)] = c
h1, t1, _ = map(int, lines[1].split())
lst = [h1, t1]
while len(lst) < n:
h, t = lst[-2], lst[-1]
x = next(d for d in data if t... | 3.958639 | MatrixStudio/Codeforces-Python-Submissions |
909 | C | Python Indentation | PROGRAMMING | 1,800 | [
"dp"
] | null | null | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An ex... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. | Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. | [
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] | [
"1\n",
"2\n"
] | In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one... | 1,500 | [
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns... | 1,514,393,751 | 1,251 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 5,529,600 | n = int(input())
f = True
ans = 0
while n:
x = input()
if x == 'f':
if f == True:
ans+=1
f = False
else:
f = True
n-=1
if ans>1:
ans-=1
ans*=2
print(ans) | Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python... | ```python
n = int(input())
f = True
ans = 0
while n:
x = input()
if x == 'f':
if f == True:
ans+=1
f = False
else:
f = True
n-=1
if ans>1:
ans-=1
ans*=2
print(ans)
``` | 0 | 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,563,702,639 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | def sum(n):
return (n / 2) * (1 + n)
a = int(input())
b = int(input())
c = abs(a - b)
if (c % 2 == 1):
print(int(2 * sum(int(c/2)) + int(c/2 +1) ))
else:
print(int(2 * sum(int(c/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
def sum(n):
return (n / 2) * (1 + n)
a = int(input())
b = int(input())
c = abs(a - b)
if (c % 2 == 1):
print(int(2 * sum(int(c/2)) + int(c/2 +1) ))
else:
print(int(2 * sum(int(c/2))))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,574,409,436 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 498 | 11,161,600 | from sys import stdin,stdout,stderr
def binary(lo,hi,value):
global a
ans=lo
while lo<=hi:
mid=(lo+hi)//2
if a[mid]<=value:
ans=mid
lo=mid+1
else:hi=mid-1
return ans
n,d=map(int,input().split())
a=[int(x)for x in input().split()]
ans=0
for i ... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
from sys import stdin,stdout,stderr
def binary(lo,hi,value):
global a
ans=lo
while lo<=hi:
mid=(lo+hi)//2
if a[mid]<=value:
ans=mid
lo=mid+1
else:hi=mid-1
return ans
n,d=map(int,input().split())
a=[int(x)for x in input().split()]
ans... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
8 | B | Obsession with Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ... | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | 0 | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"... | 1,699,500,404 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 218 | 1,740,800 | from collections import *
# from math import ceil, gcd,inf
from functools import *
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
ss=input()
arr=[(0,0)];forbi=set();f=1;x=0;y=0
for s in ss:
if s=='U':
forbi=forbi |{(x-1,y),(x,y-1),(x,y+1)}
x+=1;y+=0
elif s=='D':... | Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path fr... | ```python
from collections import *
# from math import ceil, gcd,inf
from functools import *
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
ss=input()
arr=[(0,0)];forbi=set();f=1;x=0;y=0
for s in ss:
if s=='U':
forbi=forbi |{(x-1,y),(x,y-1),(x,y+1)}
x+=1;y+=0
el... | 3.93253 | 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,633,425,840 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 109 | 20,172,800 | a, b = list(map(int, input())), list(map(int, input()))
print(''.join([str(a[i] ^ b[i]) for i in range(len(a))]))
| 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
a, b = list(map(int, input())), list(map(int, input()))
print(''.join([str(a[i] ^ b[i]) for i in range(len(a))]))
``` | 3.935175 | MatrixStudio/Codeforces-Python-Submissions |
854 | B | Maxim Buys an Apartment | PROGRAMMING | 1,200 | [
"constructive algorithms",
"math"
] | null | null | Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.
Maxim often visi... | The only line of the input contains two integers: *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=*n*). | Print the minimum possible and the maximum possible number of apartments good for Maxim. | [
"6 3\n"
] | [
"1 3\n"
] | In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartment... | 1,000 | [
{
"input": "6 3",
"output": "1 3"
},
{
"input": "10 1",
"output": "1 2"
},
{
"input": "10 9",
"output": "1 1"
},
{
"input": "8 0",
"output": "0 0"
},
{
"input": "8 8",
"output": "0 0"
},
{
"input": "966871928 890926970",
"output": "1 75944958"
},... | 1,599,741,673 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n,k = map(int,input().split())
if(n<=k):
print(0,0)
elif(n%2==0 and n//2<=k):
print(1,n-k)
elif(n%2==0 and n//2>k):
print(1,2*k)
elif(n%2==1 and n//2<=k):
print(1,n-k+1)
else:
print(1,2*k) | Title: Maxim Buys an Apartment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices d... | ```python
n,k = map(int,input().split())
if(n<=k):
print(0,0)
elif(n%2==0 and n//2<=k):
print(1,n-k)
elif(n%2==0 and n//2>k):
print(1,2*k)
elif(n%2==1 and n//2<=k):
print(1,n-k+1)
else:
print(1,2*k)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,587,988,916 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 170 | 0 |
a , b = input().split()
a = int(a)
b = int(b)
x = [int(x) for x in input().split()]
if sum(x) + (a - 1) * 10 <= b:
print((b - sum(x)) // 5)
else:
print(-1)
| Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
a , b = input().split()
a = int(a)
b = int(b)
x = [int(x) for x in input().split()]
if sum(x) + (a - 1) * 10 <= b:
print((b - sum(x)) // 5)
else:
print(-1)
``` | 3 | 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,695,014,582 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | c = 0
for i in range(int(input())):
a,b = list(map(int, input().split()))
if a == b:
c = c
else:
c += 1
print(c) | 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
c = 0
for i in range(int(input())):
a,b = list(map(int, input().split()))
if a == b:
c = c
else:
c += 1
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,551,753,037 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | entrada = input()
entrada = list(map(int, entrada.split()))
total = 0
for a in entrada:
total += a
repetidos2 = []
repetidos3 = []
novo = []
for a in entrada:
if a in novo:
if a in repetidos2:
repetidos3.append(a)
else:
repetidos2.append(a)
novo.append(a)
maior = total
for rep in repetido... | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
entrada = input()
entrada = list(map(int, entrada.split()))
total = 0
for a in entrada:
total += a
repetidos2 = []
repetidos3 = []
novo = []
for a in entrada:
if a in novo:
if a in repetidos2:
repetidos3.append(a)
else:
repetidos2.append(a)
novo.append(a)
maior = total
for rep i... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,647,579,855 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
a = [i for i in input().split()]
chest = []
biceps = []
back = []
max_array = []
for i in range(0,n) :
if i % 2 == 0 and i != 0:
biceps.append(a[i])
biceps.sort()
elif i % 3 == 0 :
back.append(a[i])
back.sort()
else :
chest.append(a[i])
ches... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
a = [i for i in input().split()]
chest = []
biceps = []
back = []
max_array = []
for i in range(0,n) :
if i % 2 == 0 and i != 0:
biceps.append(a[i])
biceps.sort()
elif i % 3 == 0 :
back.append(a[i])
back.sort()
else :
chest.append(a[i])
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,635,875,133 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 124 | 5,529,600 | s = input()
t = input()
hash1 = {}
for char in s:
if char not in hash1:
hash1[char] = 0
hash1[char] += 1
hash2 = {}
for char in t:
if char not in hash2:
hash2[char]=0
hash2[char] += 1
yay = 0
whoops = 0
for char in hash1.keys():
if char in hash2:
yay += min(... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
s = input()
t = input()
hash1 = {}
for char in s:
if char not in hash1:
hash1[char] = 0
hash1[char] += 1
hash2 = {}
for char in t:
if char not in hash2:
hash2[char]=0
hash2[char] += 1
yay = 0
whoops = 0
for char in hash1.keys():
if char in hash2:
y... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,625,839,937 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main(){
string str="nriajan";
string a="dhakal";
str.append("nirajan");
cout <<str;
}
| Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
#include <bits/stdc++.h>
using namespace std;
int main(){
string str="nriajan";
string a="dhakal";
str.append("nirajan");
cout <<str;
}
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
992 | A | Nastya and an Array | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. | Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. | [
"5\n1 1 1 1 1\n",
"3\n2 0 -1\n",
"4\n5 -6 -5 1\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | 500 | [
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "3\n2 0 -1",
"output": "2"
},
{
"input": "4\n5 -6 -5 1",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n21794 -79194",
"output": "2"
},
{
"input": "3\n-63526 95085 -5239",
... | 1,530,734,188 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | b,a=input(),set(map(int,input().split()))
print(a)
if 0 in a:
a.remove(0)
print(len(a))
| Title: Nastya and an Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second ... | ```python
b,a=input(),set(map(int,input().split()))
print(a)
if 0 in a:
a.remove(0)
print(len(a))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | 0 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 ... | 1,510,507,185 | 4,485 | Python 3 | OK | TESTS | 31 | 234 | 18,841,600 | n = int(input())
a = set()
a.add(0)
t = 0
for r in input().split():
t += 1
x = int(r)
if x in a:
a.remove(x)
a.add(t)
else:
a.add(t)
print(len(a))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages betw... | ```python
n = int(input())
a = set()
a.add(0)
t = 0
for r in input().split():
t += 1
x = int(r)
if x in a:
a.remove(x)
a.add(t)
else:
a.add(t)
print(len(a))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or... | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' a... | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a she... | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves... | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSD... | 1,520,717,030 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 62 | 5,632,000 | n, m = map(int, input().split())
s = []
ok = 1
for i in range(n):
a = input()
s.append(a)
for j in range(m):
if a[i] == 'S':
if i-1 >= 0 and s[i-1][j] == 'W':
ok = 0
if j-1 >= 0 and s[i][j-1] == 'W':
ok = 0
if i+1 < n and s[i+1][j] == 'W':
ok = 0
if j+1 < m and s[i][j+1] == 'W':
ok = 0
... | Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is ... | ```python
n, m = map(int, input().split())
s = []
ok = 1
for i in range(n):
a = input()
s.append(a)
for j in range(m):
if a[i] == 'S':
if i-1 >= 0 and s[i-1][j] == 'W':
ok = 0
if j-1 >= 0 and s[i][j-1] == 'W':
ok = 0
if i+1 < n and s[i+1][j] == 'W':
ok = 0
if j+1 < m and s[i][j+1] == 'W':
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,545,990,550 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | a = int(input())
t = "ROYGBIV"
for i in range(a):
if i > 6:
i %= 7
print(t[i] , end = "")
| Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
a = int(input())
t = "ROYGBIV"
for i in range(a):
if i > 6:
i %= 7
print(t[i] , end = "")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
864 | E | Fire | PROGRAMMING | 2,000 | [
"dp",
"sortings"
] | null | null | Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take *t**i* seconds to save *i*-th item. In addition, for each item, he estimated the value of *d**i* — the moment after which the item *i* will be completely burned and will no long... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of items in Polycarp's house.
Each of the following *n* lines contains three integers *t**i*,<=*d**i*,<=*p**i* (1<=≤<=*t**i*<=≤<=20, 1<=≤<=*d**i*<=≤<=2<=000, 1<=≤<=*p**i*<=≤<=20) — the time needed to save the item *i*, the time after which t... | In the first line print the maximum possible total value of the set of saved items. In the second line print one integer *m* — the number of items in the desired set. In the third line print *m* distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in whi... | [
"3\n3 7 4\n2 6 5\n3 7 6\n",
"2\n5 6 1\n3 3 5\n"
] | [
"11\n2\n2 3 \n",
"1\n1\n1 \n"
] | In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the save... | 2,500 | [
{
"input": "3\n3 7 4\n2 6 5\n3 7 6",
"output": "11\n2\n2 3 "
},
{
"input": "2\n5 6 1\n3 3 5",
"output": "1\n1\n1 "
},
{
"input": "9\n13 18 14\n8 59 20\n9 51 2\n18 32 15\n1 70 18\n14 81 14\n10 88 16\n18 52 3\n1 50 6",
"output": "106\n8\n1 4 9 8 2 5 6 7 "
},
{
"input": "5\n12 4... | 1,628,781,418 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 20,172,800 | n = int(input())
items = [None]*n
for i in range(n):
t,d,p = list(map(int,input().split()))
items[i] = (d,t,p)
I = list(range(n))
I.sort(key = lambda i: items[i])
items.sort()
T = sum(t for _,_,t in items)
dp = [[0]*(T+1) for _ in range(n+1)]
succ = [[None]*(T+1) for _ in range(n+1)]
for i in... | Title: Fire
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take *t**i* seconds to save *i*-th item. In addition, for each item, he estimated the value ... | ```python
n = int(input())
items = [None]*n
for i in range(n):
t,d,p = list(map(int,input().split()))
items[i] = (d,t,p)
I = list(range(n))
I.sort(key = lambda i: items[i])
items.sort()
T = sum(t for _,_,t in items)
dp = [[0]*(T+1) for _ in range(n+1)]
succ = [[None]*(T+1) for _ in range(n+1)]... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
484 | A | Bits | PROGRAMMING | 1,700 | [
"bitmasks",
"constructive algorithms"
] | null | null | Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the... | The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000).
Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018). | For each query print the answer in a separate line. | [
"3\n1 2\n2 4\n1 10\n"
] | [
"1\n3\n7\n"
] | The binary representations of numbers from 1 to 10 are listed below:
1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub>
2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub>
3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub>
4<sub class="lower-index">10</su... | 500 | [
{
"input": "3\n1 2\n2 4\n1 10",
"output": "1\n3\n7"
},
{
"input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10... | 1,565,027,400 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 93 | 716,800 | '''
Created on Aug 5, 2019
@author: Mohamed
'''
def bits(e,b):
if len(bin(e))>len(bin(b)):
z=len(bin(e)[2:])-1
return (2**z)-1
elif len(bin(e))==len(bin(b)):
z=2**(len(bin(e)[2:])-1)-1
e = e & z
b = b & z
r=bits(e,b)
r+=z+1
return r... | Title: Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that ... | ```python
'''
Created on Aug 5, 2019
@author: Mohamed
'''
def bits(e,b):
if len(bin(e))>len(bin(b)):
z=len(bin(e)[2:])-1
return (2**z)-1
elif len(bin(e))==len(bin(b)):
z=2**(len(bin(e)[2:])-1)-1
e = e & z
b = b & z
r=bits(e,b)
r+=z+1
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,680,010,381 | 181 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n,m = map(int, input().split())
ans = 0
for i in range(n):
l=list(map(int,input().split()))
for j in range(len(l)):
if l[j] >= m:
ans+=1
print(ans) | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
n,m = map(int, input().split())
ans = 0
for i in range(n):
l=list(map(int,input().split()))
for j in range(len(l)):
if l[j] >= m:
ans+=1
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
44 | B | Cola | PROGRAMMING | 1,500 | [
"implementation"
] | B. Cola | 2 | 256 | To celebrate the opening of the Winter Computer School the organizers decided to buy in *n* liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly *a* bottles 0.5 in volume, *b* one-liter bottles and *c... | The first line contains four integers — *n*, *a*, *b*, *c* (1<=≤<=*n*<=≤<=10000, 0<=≤<=*a*,<=*b*,<=*c*<=≤<=5000). | Print the unique number — the solution to the problem. If it is impossible to buy exactly *n* liters of cola, print 0. | [
"10 5 5 5\n",
"3 0 0 2\n"
] | [
"9\n",
"0\n"
] | none | 0 | [
{
"input": "10 5 5 5",
"output": "9"
},
{
"input": "3 0 0 2",
"output": "0"
},
{
"input": "1 0 0 0",
"output": "0"
},
{
"input": "1 1 0 0",
"output": "0"
},
{
"input": "1 2 0 0",
"output": "1"
},
{
"input": "1 0 1 0",
"output": "1"
},
{
"in... | 1,580,921,557 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 434 | 1,536,000 | n, a, b ,c = [int(x) for x in input().split()]
count=0
for i in range(c+1):
for j in range(b+1):
t= n - i*2 -j
if t>=0 and a*0.5 >= t:
count+=1
print(count)
| Title: Cola
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
To celebrate the opening of the Winter Computer School the organizers decided to buy in *n* liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volu... | ```python
n, a, b ,c = [int(x) for x in input().split()]
count=0
for i in range(c+1):
for j in range(b+1):
t= n - i*2 -j
if t>=0 and a*0.5 >= t:
count+=1
print(count)
``` | 3.888639 | MatrixStudio/Codeforces-Python-Submissions |
677 | B | Vanya and Food Processor | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed *h* and the processor smashes *k* centimeters of potato each second. If there are less than *k* centimeters remaining, than during this second processor smashes all the remaining potato.
V... | The first line of the input contains integers *n*, *h* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=*h*<=≤<=109) — the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=*h*) — ... | Print a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement. | [
"5 6 3\n5 4 3 2 1\n",
"5 6 3\n5 5 5 5 5\n",
"5 6 3\n1 2 1 1 1\n"
] | [
"5\n",
"10\n",
"2\n"
] | Consider the first sample.
1. First Vanya puts the piece of potato of height 5 into processor. At the end of the second there is only amount of height 2 remaining inside. 1. Now Vanya puts the piece of potato of height 4. At the end of the second there is amount of height 3 remaining. 1. Vanya puts the piece of he... | 1,000 | [
{
"input": "5 6 3\n5 4 3 2 1",
"output": "5"
},
{
"input": "5 6 3\n5 5 5 5 5",
"output": "10"
},
{
"input": "5 6 3\n1 2 1 1 1",
"output": "2"
},
{
"input": "10 100 80\n76 75 73 71 76 74 73 70 78 75",
"output": "10"
},
{
"input": "10 100 88\n11 23 69 6 71 15 25 1 4... | 1,698,999,564 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 93 | 13,619,200 | # https://codeforces.com/contest/677
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n, h, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
filled = 0
for v in a:
if filled + v > h:
ans += 1
filled = v
else:
filled += v
x = filled // ... | Title: Vanya and Food Processor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed *h* and the processor smashes *k* centimeters of potato each second. If there a... | ```python
# https://codeforces.com/contest/677
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n, h, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
filled = 0
for v in a:
if filled + v > h:
ans += 1
filled = v
else:
filled += v
x = ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,694,574,385 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | a,b,c=map(int,input().split())
m=[]
for x in range(c+1):
h=a*x
m.append(h)
add=sum(m)
print(add-b) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
a,b,c=map(int,input().split())
m=[]
for x in range(c+1):
h=a*x
m.append(h)
add=sum(m)
print(add-b)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,682,610,762 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 61 | 0 | def is_composite(x):
# Check if x is a composite number
for i in range(2, int(x**0.5)+1):
if x % i == 0:
return True
return False
n = int(input())
# Find the smallest composite number less than or equal to n/2
for i in range(4, n//2+1):
if is_composite(i) and is_composit... | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
def is_composite(x):
# Check if x is a composite number
for i in range(2, int(x**0.5)+1):
if x % i == 0:
return True
return False
n = int(input())
# Find the smallest composite number less than or equal to n/2
for i in range(4, n//2+1):
if is_composite(i) and i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,690,498,915 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1690498915.1433928")# 1690498915.143415 | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
print("_RANDOM_GUESS_1690498915.1433928")# 1690498915.143415
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,515,864,507 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 5,632,000 | def mashaa():
s=[int(x) for x in input().split()]
father, mother, son, masha = s
carf=0
carm=0
cars=0
a=True
if masha<=2*father:
carf=max(father, masha)
else:
print("-1")
return
if masha<=2*mother:
carm=max(mother, masha)
else:
... | Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
def mashaa():
s=[int(x) for x in input().split()]
father, mother, son, masha = s
carf=0
carm=0
cars=0
a=True
if masha<=2*father:
carf=max(father, masha)
else:
print("-1")
return
if masha<=2*mother:
carm=max(mother, masha)
el... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
914 | B | Conan and Agasa play a Card Game | PROGRAMMING | 1,200 | [
"games",
"greedy",
"implementation"
] | null | null | Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it.
They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he remov... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards Conan has.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105), where *a**i* is the number on the *i*-th card. | If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes). | [
"3\n4 5 7\n",
"2\n1 1\n"
] | [
"Conan\n",
"Agasa\n"
] | In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.
In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it... | 1,000 | [
{
"input": "3\n4 5 7",
"output": "Conan"
},
{
"input": "2\n1 1",
"output": "Agasa"
},
{
"input": "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282",
"output": "Conan"
},
{
"input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165",
"output":... | 1,620,359,674 | 2,147,483,647 | PyPy 3 | OK | TESTS | 91 | 155 | 35,020,800 | input()
mp = {}
for c in input().split():
mp[c] = mp.get(c,0)^1
if sum(mp.values()):
print("Conan")
else:
print("Agasa")
| Title: Conan and Agasa play a Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it.... | ```python
input()
mp = {}
for c in input().split():
mp[c] = mp.get(c,0)^1
if sum(mp.values()):
print("Conan")
else:
print("Agasa")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,614,265,241 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 186 | 0 | a, b, c = map(int, input().split())
x, y = 0, 0
if min(a, b, c) > 0:
x = 1 + (a - 1) // 3 + (b - 1) // 3 + (c - 1) // 3
if min(a, b, c) > 1:
y = 2 + (a - 2) // 3 + (b - 2) // 3 + (c - 2) // 3
print(max(a // 3 + b // 3 + c // 3, x, y)) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
a, b, c = map(int, input().split())
x, y = 0, 0
if min(a, b, c) > 0:
x = 1 + (a - 1) // 3 + (b - 1) // 3 + (c - 1) // 3
if min(a, b, c) > 1:
y = 2 + (a - 2) // 3 + (b - 2) // 3 + (c - 2) // 3
print(max(a // 3 + b // 3 + c // 3, x, y))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
598 | B | Queries on a String | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | null | null | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One ope... | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains thr... | Print the resulting string *s* after processing all *m* queries. | [
"abacaba\n2\n3 6 1\n1 4 2\n"
] | [
"baabcaa\n"
] | The sample is described in problem statement. | 0 | [
{
"input": "abacaba\n2\n3 6 1\n1 4 2",
"output": "baabcaa"
},
{
"input": "u\n1\n1 1 1",
"output": "u"
},
{
"input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4",
"output": "p"
},
{
"input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6",
"output": "ssssssssss"
},
... | 1,632,632,870 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 77 | 8,294,400 | def f(s,k):
k = k%len(s)
return s[len(s)-k:len(s)] + s[0:len(s)-k]
s = str(input())
m=int(input())
for i in range(m):
l,r,k=map(int,input().split())
length = r-l
s = s[0:l-1] + f(s[l-1:r],k) + s[r:len(s)]
print(s) | Title: Queries on a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**... | ```python
def f(s,k):
k = k%len(s)
return s[len(s)-k:len(s)] + s[0:len(s)-k]
s = str(input())
m=int(input())
for i in range(m):
l,r,k=map(int,input().split())
length = r-l
s = s[0:l-1] + f(s[l-1:r],k) + s[r:len(s)]
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,674,069,916 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 327 | 9,011,200 | n = int(input())
arr = []
for _ in range(n):
arr.append(list(map(int, input().split())))
res = 1 if n == 1 else 2
border = arr[0][0]
#print(border, res)
for i in range(1, n - 1):
tree = arr[i]
if border + tree[1] < tree[0]:
border = tree[0]
res += 1
elif border < tree[0] and tree[0] + tree[1] < arr[i ... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
n = int(input())
arr = []
for _ in range(n):
arr.append(list(map(int, input().split())))
res = 1 if n == 1 else 2
border = arr[0][0]
#print(border, res)
for i in range(1, n - 1):
tree = arr[i]
if border + tree[1] < tree[0]:
border = tree[0]
res += 1
elif border < tree[0] and tree[0] + tree[1... | 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,656,358,727 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | a = int(input())
prices = list(map(int, input().split()))
highestbidder = prices.index(max(prices)) + 1
price2 = sorted(prices)
print(highestbidder, (price2[-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
a = int(input())
prices = list(map(int, input().split()))
highestbidder = prices.index(max(prices)) + 1
price2 = sorted(prices)
print(highestbidder, (price2[-2]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,665,438,929 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 184 | 0 | def lower_bound(arr,a,start,end):
ans=-1
while start<=end:
mid=(start+end)//2
if arr[mid]>=a:
ans=mid
end=mid-1
else:
start=mid+1
return ans
n,m=map(int,input().split()) ; arr=list(map(int,input().split())) ; arr.sort() ; maxi=mini=0 ; ar... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
def lower_bound(arr,a,start,end):
ans=-1
while start<=end:
mid=(start+end)//2
if arr[mid]>=a:
ans=mid
end=mid-1
else:
start=mid+1
return ans
n,m=map(int,input().split()) ; arr=list(map(int,input().split())) ; arr.sort() ; maxi=m... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*.
Spring is starting and the Wint... | The first line contains three integers *n*, *k* and *q* (1<=≤<=*n*,<=*q*<=≤<=150<=000,<=1<=≤<=*k*<=≤<=*min*(6,<=*n*)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) ... | For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. | [
"4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n",
"6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n"
] | [
"NO\nYES\nNO\nYES\nYES\n",
"NO\nYES\nNO\nYES\n"
] | In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" — Friend 3 becomes online. 1. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3" — We shou... | 0 | [
{
"input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3",
"output": "NO\nYES\nNO\nYES\nYES"
},
{
"input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3",
"output": "NO\nYES\nNO\nYES"
},
{
"input": "6 3 10\n62417580 78150524 410053501 582708235 ... | 1,459,184,954 | 2,054 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 46 | 4,608,000 | n, k, q = map(int, input().split())
T = list(map(int, input().split()))
S = []
for i in range(q):
type, id = map(int, input().split())
if type == 1:
if len(S) == 0:
S = [id]
else:
if len(S) < k:
S += [id]
else:
S[0] = id
S.sort()
else:
print(["NO", "YES"][int(S and (id in S))])
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the ... | ```python
n, k, q = map(int, input().split())
T = list(map(int, input().split()))
S = []
for i in range(q):
type, id = map(int, input().split())
if type == 1:
if len(S) == 0:
S = [id]
else:
if len(S) < k:
S += [id]
else:
S[0] = id
S.sort()
else:
print(["NO", "YES"][int(S and (id in S))])
``... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
628 | A | Tennis Tournament | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is the number of the participants of the current round):
- let *k* be the maximal power of the number 2 ... | The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement. | Print two integers *x* and *y* — the number of bottles and towels need for the tournament. | [
"5 2 3\n",
"8 2 4\n"
] | [
"20 15\n",
"35 32\n"
] | In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be onl... | 0 | [
{
"input": "5 2 3",
"output": "20 15"
},
{
"input": "8 2 4",
"output": "35 32"
},
{
"input": "10 1 500",
"output": "27 5000"
},
{
"input": "20 500 1",
"output": "19019 20"
},
{
"input": "100 123 99",
"output": "24453 9900"
},
{
"input": "500 1 1",
... | 1,661,568,856 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | x = input().split(" ")
n = int(x[0])
b = int(x[1])
p = int(x[2])
q = n // 2
w = n % 2
x = 0
y = p * n
while q != 1:
if n == 1:
print (x , y)
elif w == 0:
e = ((n)*b) + q
x = x + e
n = n // 2
q = q // 2
w = n % 2
elif w == 1:
e = ((n-1)*b) + q
... | Title: Tennis Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is ... | ```python
x = input().split(" ")
n = int(x[0])
b = int(x[1])
p = int(x[2])
q = n // 2
w = n % 2
x = 0
y = p * n
while q != 1:
if n == 1:
print (x , y)
elif w == 0:
e = ((n)*b) + q
x = x + e
n = n // 2
q = q // 2
w = n % 2
elif w == 1:
e = ((n-1)*b) +... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,690,169,270 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s = input()
t = input()
f = s[::-1]
if f==t and len(s)<=100:
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s = input()
t = input()
f = s[::-1]
if f==t and len(s)<=100:
print("YES")
else:
print("NO")
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
467 | B | Fedor and New Game | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"constructive algorithms",
"implementation"
] | null | null | After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (*m*<=+<=1) players and *n* types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (*m*<=+<=1). Types of soldiers are numbered from 0 to *n... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=20; 1<=≤<=*m*<=≤<=1000).
The *i*-th of the next (*m*<=+<=1) lines contains a single integer *x**i* (1<=≤<=*x**i*<=≤<=2*n*<=-<=1), that describes the *i*-th player's army. We remind you that Fedor is the (*m*<=+<=1)-th player. | Print a single integer — the number of Fedor's potential friends. | [
"7 3 1\n8\n5\n111\n17\n",
"3 3 3\n1\n2\n3\n4\n"
] | [
"0\n",
"3\n"
] | none | 1,000 | [
{
"input": "7 3 1\n8\n5\n111\n17",
"output": "0"
},
{
"input": "3 3 3\n1\n2\n3\n4",
"output": "3"
},
{
"input": "4 2 2\n5\n6\n7",
"output": "2"
},
{
"input": "4 7 4\n9\n10\n5\n12\n4\n12\n7\n10",
"output": "7"
},
{
"input": "2 7 2\n1\n1\n1\n1\n1\n1\n1\n1",
"out... | 1,689,169,116 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 108 | 1,843,200 | def dec(decimal):
binary = (bin(decimal)[2:])
return binary
n,m,k=map(int,input().split())
l=[]
l2=[]
for i in range(m+1):
a=int(input())
l.append(a)
l2.append(dec(a))
ans=[]
val=l[-1]
l=l[:-1]
for i in l:
ans.append(dec(val^i).count("1"))
ctr=0
for i in ans:
if i<... | Title: Fedor and New Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (*m*<=+<=1) players and *n* types of soldiers in total. Play... | ```python
def dec(decimal):
binary = (bin(decimal)[2:])
return binary
n,m,k=map(int,input().split())
l=[]
l2=[]
for i in range(m+1):
a=int(input())
l.append(a)
l2.append(dec(a))
ans=[]
val=l[-1]
l=l[:-1]
for i in l:
ans.append(dec(val^i).count("1"))
ctr=0
for i in ans:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other ... | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3... | 1,593,934,742 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 202 | 14,438,400 | n,x=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
s=0
for i in range(n):
s+=x*l[i]
if(x>1):
x-=1
print(s) | Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co... | ```python
n,x=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
s=0
for i in range(n):
s+=x*l[i]
if(x>1):
x-=1
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
319 | D | Have You Ever Heard About the Word? | PROGRAMMING | 2,800 | [
"greedy",
"hashing",
"string suffix structures",
"strings"
] | null | null | A substring of a string is a contiguous subsequence of that string. So, string bca is substring of string abcabc, but string cc is not.
A repeating block is a string formed by concatenating some string with itself. So, string abcabc is a repeating block, but strings abcabd, ababab are not.
You've got a sequence of La... | In the first line of input you're given a string of small Latin characters with length between 1 to 50000, inclusive. | Print the final string after applying changes. | [
"abccabc\n",
"aaaabaaab\n",
"birdbirdbirdistheword\n"
] | [
"abc\n",
"ab\n",
"birdistheword\n"
] | At the first sample the string transforms as follows: abccabc → abcabc → abc.
At the second sample the string transforms as follows: aaaabaaab → aaabaaab → aabaaab → abaaab → abaab → abab → ab. | 2,500 | [] | 1,372,035,098 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 6,000 | 409,600 | s=input()
n=len(s)
y=list(s)
for i in range(n-1):
if(s[i]==s[i+1]):
y[i]="1"
s=""
while("1" in y):
y.remove("1")
for item in y:
s=s+item
k=True
r=1
for r in range(1,n//2+1):
if(r>len(s)//2):
break
for i in range(0,len(s)-2*r+1):
if(s[i:i+r]==s[i+r:i+2*r]):
... | Title: Have You Ever Heard About the Word?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A substring of a string is a contiguous subsequence of that string. So, string bca is substring of string abcabc, but string cc is not.
A repeating block is a string formed by concatenating some str... | ```python
s=input()
n=len(s)
y=list(s)
for i in range(n-1):
if(s[i]==s[i+1]):
y[i]="1"
s=""
while("1" in y):
y.remove("1")
for item in y:
s=s+item
k=True
r=1
for r in range(1,n//2+1):
if(r>len(s)//2):
break
for i in range(0,len(s)-2*r+1):
if(s[i:i+r]==s[i+r:i+2*... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,700,328,018 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 93 | 0 | n=int(input())
x = [int(i) for i in input().split()]
prev=0
changble=0
rest=0
for i in range(n):
a = x[i]
if a == 0:
prev=0
rest+=1
changble=0
elif a == 1:
if prev != 1:
prev=1
elif changble == 1:
prev=2
else:
... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
n=int(input())
x = [int(i) for i in input().split()]
prev=0
changble=0
rest=0
for i in range(n):
a = x[i]
if a == 0:
prev=0
rest+=1
changble=0
elif a == 1:
if prev != 1:
prev=1
elif changble == 1:
prev=2
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109; *a**i*<=≤<=*a**i*<=+<=1).
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the numbe... | Print *m* integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I... | [
"5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n",
"3\n1 2 3\n2\n1 1\n3 1\n",
"1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n"
] | [
"1\n3\n4\n6\n",
"1\n3\n",
"1\n3\n13\n23\n33\n"
] | The first sample are shown on the picture. | 0 | [
{
"input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3",
"output": "1\n3\n4\n6"
},
{
"input": "3\n1 2 3\n2\n1 1\n3 1",
"output": "1\n3"
},
{
"input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10",
"output": "1\n3\n13\n23\n33"
},
{
"input": "8\n6 10 18 23 30 31 31 33\n1\n5 3",
"output":... | 1,591,718,428 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
#define max(a,b) a>b?a:b
using namespace std;
int main()
{
int m,n,a[100002];
long long int ans=0,w,h;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>w;
ans=max(ans+h,a[w]);
cin>>h;
cout<<ans<<endl;
}
} | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*).
Dima decided to play with the staircase, so he... | ```python
#include<iostream>
#define max(a,b) a>b?a:b
using namespace std;
int main()
{
int m,n,a[100002];
long long int ans=0,w,h;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>w;
ans=max(ans+h,a[w]);
cin>>h;
cout<<ans<<endl;
}
}
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,697,550,197 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 35 | 2,000 | 14,336,000 | import math
# Function to check if a number is prime
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
return False
return True
# Read input
n = int(input())
numbers = list(map(int, input().split()))
# Chec... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
import math
# Function to check if a number is prime
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
return False
return True
# Read input
n = int(input())
numbers = list(map(int, input().split()))... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
505 | A | Mr. Kitayuta's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes... | The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. | If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. | [
"revive\n",
"ee\n",
"kitayuta\n"
] | [
"reviver\n",
"eye",
"NA\n"
] | For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | 500 | [
{
"input": "revive",
"output": "reviver"
},
{
"input": "ee",
"output": "eee"
},
{
"input": "kitayuta",
"output": "NA"
},
{
"input": "evima",
"output": "NA"
},
{
"input": "a",
"output": "aa"
},
{
"input": "yutampo",
"output": "NA"
},
{
"inpu... | 1,607,859,215 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | import sys
s=input()
for x in "qwertyuiopasdfghjklzxcvbnm":
for i in range(len(s)+1):
y=s[:i]+x+s[i:]
print(y)
if y==y[::-1]:
sys.exit(0)
print("NA") | Title: Mr. Kitayuta's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re... | ```python
import sys
s=input()
for x in "qwertyuiopasdfghjklzxcvbnm":
for i in range(len(s)+1):
y=s[:i]+x+s[i:]
print(y)
if y==y[::-1]:
sys.exit(0)
print("NA")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
858 | F | Wizard's Tour | PROGRAMMING | 2,300 | [
"constructive algorithms",
"dfs and similar",
"graphs"
] | null | null | All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!
It is well-known that there are *n* cities in Berland, some pairs of which are connected by bidirectional roads. Each pair of cities is connected by no more than one road. It is not guaranteed that ... | The first line contains two integers *n*, *m* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*m*<=≤<=2·105) — the number of cities and the number of roads in Berland, respectively.
The roads description follow, one in each line. Each description is a pair of two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*)... | In the first line print *w* — the maximum possible number of episodes. The next *w* lines should contain the episodes in format *x*, *y*, *z* — the three integers denoting the ids of the cities in the order of the wizard's visits. | [
"4 5\n1 2\n3 2\n2 4\n3 4\n4 1\n",
"5 8\n5 3\n1 2\n4 5\n5 1\n2 5\n4 3\n1 4\n3 2\n"
] | [
"2\n1 4 2\n4 3 2\n",
"4\n1 4 5\n2 3 4\n1 5 3\n5 2 1\n"
] | none | 3,000 | [
{
"input": "4 5\n1 2\n3 2\n2 4\n3 4\n4 1",
"output": "2\n1 4 2\n4 3 2"
},
{
"input": "5 8\n5 3\n1 2\n4 5\n5 1\n2 5\n4 3\n1 4\n3 2",
"output": "4\n1 4 5\n2 3 4\n1 5 3\n5 2 1"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "... | 1,505,843,110 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 5 | 514 | 268,390,400 | a,b=input().split(' ')
a=int(a)
b=int(b)
s=int(0)
mass=[[0]*a for i in range (a)]
itog=[]
for i in range (b):
c,d=input().split(' ')
c=int(c)
d=int(d)
mass[c-1][d-1]=1
mass[d-1][c-1]=1
for i in range(a):
s=0
for g in range (a):
if mass[i][g]!=0:
for k in r... | Title: Wizard's Tour
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!
It is well-known that there are *n* cities in Berland, some pairs of which are connected by bidirec... | ```python
a,b=input().split(' ')
a=int(a)
b=int(b)
s=int(0)
mass=[[0]*a for i in range (a)]
itog=[]
for i in range (b):
c,d=input().split(' ')
c=int(c)
d=int(d)
mass[c-1][d-1]=1
mass[d-1][c-1]=1
for i in range(a):
s=0
for g in range (a):
if mass[i][g]!=0:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
40 | C | Berland Square | PROGRAMMING | 2,300 | [
"implementation",
"math"
] | C. Berland Square | 2 | 256 | Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1,<=2,<=...,<=*K* and the cen... | The first line contains integers *N*,<=*x*,<=*M*,<=*y*. (1<=≤<=*N*,<=*M*<=≤<=100000,<=<=-<=100000<=≤<=*x*,<=*y*<=≤<=100000,<=*x*<=≠<=*y*). | Print the sought number of parts. | [
"1 0 1 1\n",
"1 0 1 2\n",
"3 3 4 7\n"
] | [
"4\n",
"3\n",
"17\n"
] | Picture for the third sample: | 1,500 | [
{
"input": "1 0 1 1",
"output": "4"
},
{
"input": "1 0 1 2",
"output": "3"
},
{
"input": "3 3 4 7",
"output": "17"
},
{
"input": "2 2 2 3",
"output": "8"
},
{
"input": "1 100000 1 99999",
"output": "4"
},
{
"input": "4 7 3 3",
"output": "17"
},
... | 1,534,121,552 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 216 | 0 | n, x, m, y = list(map(int,input().strip().split(' ')))
s = x
x -= s
y -= s
y = abs(y)
print(n + m + 1 + pow(n + m - y,2)) | Title: Berland Square
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles... | ```python
n, x, m, y = list(map(int,input().strip().split(' ')))
s = x
x -= s
y -= s
y = abs(y)
print(n + m + 1 + pow(n + m - y,2))
``` | 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,646,256,632 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 31 | 0 | n = int(input())
arr = list(map(int, input().split()))
max_index = arr.index(max(arr)) + 1
arr.remove(max(arr))
print(max_index, max(arr))
| 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())
arr = list(map(int, input().split()))
max_index = arr.index(max(arr)) + 1
arr.remove(max(arr))
print(max_index, max(arr))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
379 | D | New Year Letter | PROGRAMMING | 2,000 | [
"bitmasks",
"brute force",
"dp"
] | null | null | Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas).
... | The first line contains four integers *k*,<=*x*,<=*n*,<=*m* (3<=≤<=*k*<=≤<=50; 0<=≤<=*x*<=≤<=109; 1<=≤<=*n*,<=*m*<=≤<=100). | In the first line print string *s*1, consisting of *n* uppercase English letters. In the second line print string *s*2, consisting of *m* uppercase English letters. If there are multiple valid strings, print any of them.
If the required pair of strings doesn't exist, print "Happy new year!" without the quotes. | [
"3 2 2 2\n",
"3 3 2 2\n",
"3 0 2 2\n",
"4 3 2 1\n",
"4 2 2 1\n"
] | [
"AC\nAC\n",
"Happy new year!\n",
"AA\nAA\n",
"Happy new year!\n",
"Happy new year!\n"
] | none | 2,000 | [
{
"input": "3 2 2 2",
"output": "AC\nAC"
},
{
"input": "3 3 2 2",
"output": "Happy new year!"
},
{
"input": "3 0 2 2",
"output": "AA\nAA"
},
{
"input": "4 3 2 1",
"output": "Happy new year!"
},
{
"input": "4 2 2 1",
"output": "Happy new year!"
},
{
"in... | 1,672,633,152 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 623 | 11,571,200 | # Problem: D. New Year Letter
# Contest: Codeforces - Good Bye 2013
# URL: https://codeforces.com/problemset/problem/379/D
# Memory Limit: 256 MB
# Time Limit: 1000 ms
#
# Powered by CP Editor (https://cpeditor.org)
import sys
import bisect
import random
import io, os
from bisect import *
from collections... | Title: New Year Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to... | ```python
# Problem: D. New Year Letter
# Contest: Codeforces - Good Bye 2013
# URL: https://codeforces.com/problemset/problem/379/D
# Memory Limit: 256 MB
# Time Limit: 1000 ms
#
# Powered by CP Editor (https://cpeditor.org)
import sys
import bisect
import random
import io, os
from bisect import *
from c... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,497,140,228 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | (a, b, c, d) = map(int, input().split(' '))
def points(p, t):
return max(3.0/10.0 * p, p - p / 250.0 * t)
if points(a, c) > points(b, d):
print("Misha")
elif points(a, c) < points(b, d):
print("Vasya")
else:
print("Tie")
| Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
(a, b, c, d) = map(int, input().split(' '))
def points(p, t):
return max(3.0/10.0 * p, p - p / 250.0 * t)
if points(a, c) > points(b, d):
print("Misha")
elif points(a, c) < points(b, d):
print("Vasya")
else:
print("Tie")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* qu... | The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=... | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | 0 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1... | 1,585,749,357 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 857 | 33,382,400 | import random, math
from copy import deepcopy as dc
# Function to call the actual solution
def solution(li, que, kque):
out = [0]* len(li)
quem = [0]*len(que)
# Marking all the queries
# which are to be performed
for i in range(len(kque)):
q = kque[i]
quem[q[0]-1] += 1
if q[1] != len(quem):
quem[q[1]]... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements ... | ```python
import random, math
from copy import deepcopy as dc
# Function to call the actual solution
def solution(li, que, kque):
out = [0]* len(li)
quem = [0]*len(que)
# Marking all the queries
# which are to be performed
for i in range(len(kque)):
q = kque[i]
quem[q[0]-1] += 1
if q[1] != len(quem):
... | 3 | 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,604,117,555 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 374 | 6,246,400 | n,m=map(int,input().split(" "))
arr=[]
for i in range(m):
w=input().split(" ")
arr.append(w)
k=input().split(" ")
out=[]
for i in range(len(k)):
for j in range(len(arr)):
if k[i]==arr[j][0] or k[i]==arr[j][1]:
if len(arr[j][0])<=len(arr[j][1]):
out.append(arr[j][0])
elif len(arr[j][0])>len(ar... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n,m=map(int,input().split(" "))
arr=[]
for i in range(m):
w=input().split(" ")
arr.append(w)
k=input().split(" ")
out=[]
for i in range(len(k)):
for j in range(len(arr)):
if k[i]==arr[j][0] or k[i]==arr[j][1]:
if len(arr[j][0])<=len(arr[j][1]):
out.append(arr[j][0])
elif len(arr[j][... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,563,713,423 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | n = int(input())
if n == 2:
print("aa")
elif n == 1:
print("b")
if n%2 == 1:
print((n//3)*("aab")+"b")
elif n%2 == 2:
print((n//3)*("aab"))
else:
print((n//3)*("abb")) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n = int(input())
if n == 2:
print("aa")
elif n == 1:
print("b")
if n%2 == 1:
print((n//3)*("aab")+"b")
elif n%2 == 2:
print((n//3)*("aab"))
else:
print((n//3)*("abb"))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,551,535,826 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | n = int(input())
m = str(input())
a = list(m)
if(a[0]=="S" and a[1]=="F"):
print("YES")
else:
print("NO") | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
n = int(input())
m = str(input())
a = list(m)
if(a[0]=="S" and a[1]=="F"):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,559,475,212 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 |
str1=input()
l1=list(str1)
for i in range(len(l1)-2):
if(l1[i]==l1[i+1]==l1[i+2]):
l1[i+1]=chr(ord(l1[i+1])+1)
else:
if(l1[i]==l1[i+1] and l1[i+1]!=l1[i+2]):
x=chr(ord(l1[i+2])+1)
print(x)
if(l1[i+1]!=x):
l1[i+1]=x
else:
l1[i+1]=chr(ord(l1[i+2])+2)
str2=""
for i in l1:
st... | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wa... | ```python
str1=input()
l1=list(str1)
for i in range(len(l1)-2):
if(l1[i]==l1[i+1]==l1[i+2]):
l1[i+1]=chr(ord(l1[i+1])+1)
else:
if(l1[i]==l1[i+1] and l1[i+1]!=l1[i+2]):
x=chr(ord(l1[i+2])+1)
print(x)
if(l1[i+1]!=x):
l1[i+1]=x
else:
l1[i+1]=chr(ord(l1[i+2])+2)
str2=""
for i i... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,591,344,211 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 307,200 | def dis(x,x1,y,y1):
return ((x-x1)**2 + (y-y1)**2)**0.5
import math
r,x,y,x1,y1=map(int,input().split())
if x==x1 and y==y1:
print(0)
else:
steps=0
distance=dis(x,x1,y,y1)
cos=abs(x-x1)/distance
sin=abs(y-y1)/distance
while distance>2*r:
if x<x1:
x=x+r*cos
... | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
def dis(x,x1,y,y1):
return ((x-x1)**2 + (y-y1)**2)**0.5
import math
r,x,y,x1,y1=map(int,input().split())
if x==x1 and y==y1:
print(0)
else:
steps=0
distance=dis(x,x1,y,y1)
cos=abs(x-x1)/distance
sin=abs(y-y1)/distance
while distance>2*r:
if x<x1:
x=x+r*... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
910 | B | Door Frames | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Petya has equal wooden bars of length *n*. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length *a* and one top side of length *b*. A solid (i.e. continuous without breaks) piece of bar is needed for each side.
Determine a minimal number of wooden bars which are ne... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the length of each wooden bar.
The second line contains a single integer *a* (1<=≤<=*a*<=≤<=*n*) — the length of the vertical (left and right) sides of a door frame.
The third line contains a single integer *b* (1<=≤<=*b*<=≤<=*n*) — the length of t... | Print the minimal number of wooden bars with length *n* which are needed to make the frames for two doors. | [
"8\n1\n2\n",
"5\n3\n4\n",
"6\n4\n2\n",
"20\n5\n6\n"
] | [
"1\n",
"6\n",
"4\n",
"2\n"
] | In the first example one wooden bar is enough, since the total length of all six sides of the frames for two doors is 8.
In the second example 6 wooden bars is enough, because for each side of the frames the new wooden bar is needed. | 1,000 | [
{
"input": "8\n1\n2",
"output": "1"
},
{
"input": "5\n3\n4",
"output": "6"
},
{
"input": "6\n4\n2",
"output": "4"
},
{
"input": "20\n5\n6",
"output": "2"
},
{
"input": "1\n1\n1",
"output": "6"
},
{
"input": "3\n1\n2",
"output": "3"
},
{
"in... | 1,514,299,965 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 5,529,600 | n = int(input())
a = int(input())
b = int(input())
if n >= 4 * a + 2 * b:
ans = 1
#print(1)
elif n >= 4 * a + b:
ans = 2
#print(2)
elif n >= 4 * a and 2 * b <= n:
ans = 2
#print(3)
elif n >= 3 * a + 2 * b:
ans = 2
#print(-7)
elif n >= 3 * a and n >= a + 2 * b:
ans = 2
#print(-6)
... | Title: Door Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has equal wooden bars of length *n*. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length *a* and one top side of length *b*. A solid (i.e. continuous without brea... | ```python
n = int(input())
a = int(input())
b = int(input())
if n >= 4 * a + 2 * b:
ans = 1
#print(1)
elif n >= 4 * a + b:
ans = 2
#print(2)
elif n >= 4 * a and 2 * b <= n:
ans = 2
#print(3)
elif n >= 3 * a + 2 * b:
ans = 2
#print(-7)
elif n >= 3 * a and n >= a + 2 * b:
ans = 2
#pri... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,658,487,773 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 154 | 11,776,000 | s1=input()
s2=input()
s1=list(s1)
s2=list(s2)
if(len(s2)!=len(s1)):
print("NO")
else:
flag=0
dic={}
for i in range(len(s1)):
if(s1[i] in dic.keys()):
dic[s1[i]]+=1
else:
dic[s1[i]]=1
dic1={}
for i in range(len(s1)):
if(s2[i] in di... | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
s1=input()
s2=input()
s1=list(s1)
s2=list(s2)
if(len(s2)!=len(s1)):
print("NO")
else:
flag=0
dic={}
for i in range(len(s1)):
if(s1[i] in dic.keys()):
dic[s1[i]]+=1
else:
dic[s1[i]]=1
dic1={}
for i in range(len(s1)):
if(s... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,652,074,204 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 62 | 0 | a,b = map(int,input().split())
s = input()
res = b*"0"
if res in s:
print(-1)
else:
i = 0
j = 0
while i<len(s)-1 and j<a:
if s[i]=="1":
i+=b
j+=1
else:
i-=1
print(j) | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
a,b = map(int,input().split())
s = input()
res = b*"0"
if res in s:
print(-1)
else:
i = 0
j = 0
while i<len(s)-1 and j<a:
if s[i]=="1":
i+=b
j+=1
else:
i-=1
print(j)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,679,682,022 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n=int(input())
gifts=input().split()
""" Reverse_gifts is just dummy list so that I can place each integer at
its required place"""
reverse_gifts=[range(n)]
""" For converting each item of gifts to integer"""
for num in range(len(gifts)):
gifts[num]=int(gifts[num])
""" It will change the items of reve... | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n=int(input())
gifts=input().split()
""" Reverse_gifts is just dummy list so that I can place each integer at
its required place"""
reverse_gifts=[range(n)]
""" For converting each item of gifts to integer"""
for num in range(len(gifts)):
gifts[num]=int(gifts[num])
""" It will change the ite... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
222 | C | Reducing Fractions | PROGRAMMING | 1,800 | [
"implementation",
"math",
"number theory",
"sortings"
] | null | null | To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t... | The first input line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) that show how many numbers the first set (the numerator) and the second set (the denominator) contain, correspondingly.
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=107) ... | Print the answer to the problem in the form, similar to the form of the input data. The number of values in the sets you print *n**out*,<=*m**out* must satisfy the inequality 1<=≤<=*n**out*,<=*m**out*<=≤<=105, and the actual values in the sets *a**out*,<=*i* and *b**out*,<=*i* must satisfy the inequality 1<=≤<=*a**out*... | [
"3 2\n100 5 2\n50 10\n",
"4 3\n2 5 10 20\n100 1 3\n"
] | [
"2 3\n2 1\n1 1 1\n",
"1 1\n20\n3\n"
] | In the first test sample the numerator equals 1000, the denominator equals 500. If we reduce fraction 1000/500 by the greatest common divisor of the numerator and the denominator (by 500), we obtain fraction 2/1.
In the second test sample the numerator equals 2000, the denominator equals 300. If we reduce fraction 200... | 1,500 | [
{
"input": "3 2\n100 5 2\n50 10",
"output": "2 3\n2 1\n1 1 1"
},
{
"input": "4 3\n2 5 10 20\n100 1 3",
"output": "1 1\n20\n3"
},
{
"input": "2 3\n50 10\n100 5 2",
"output": "2 3\n1 1 \n2 1 1 "
},
{
"input": "1 1\n1\n1",
"output": "1 1\n1 \n1 "
},
{
"input": "3 2\n... | 1,592,598,989 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 1,122 | 84,684,800 | import math as mt
MAXN = 10000001
spf = [0]*(MAXN)
def sieve():
spf[1] = 1
for i in range(2, MAXN):
spf[i] = i
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, mt.ceil(mt.sqrt(MAXN))):
if (spf[i] == i):
for j in range(i * i, MAXN, i):
if (spf[j] == j):
spf[j] = i
... | Title: Reducing Fractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, ... | ```python
import math as mt
MAXN = 10000001
spf = [0]*(MAXN)
def sieve():
spf[1] = 1
for i in range(2, MAXN):
spf[i] = i
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, mt.ceil(mt.sqrt(MAXN))):
if (spf[i] == i):
for j in range(i * i, MAXN, i):
if (spf[j] == j):
sp... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morn... | The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and ... | 500 | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"ou... | 1,553,060,666 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 91,648,000 | t,s,x=map(int,input().split())
l=[]
l.append(t)
j=1
while l[-1]<=x:
if len(l)%2!=0:
z=j*s+t
if z>x:
break
l.append(z)
l.append(z+1)
else:
l.append(z)
l.append(z-1)
j=j+1
if x in l:
print('YES')
else:
print('NO')
| Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times... | ```python
t,s,x=map(int,input().split())
l=[]
l.append(t)
j=1
while l[-1]<=x:
if len(l)%2!=0:
z=j*s+t
if z>x:
break
l.append(z)
l.append(z+1)
else:
l.append(z)
l.append(z-1)
j=j+1
if x in l:
print('YES')
else:
print('N... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
963 | A | Alternating Sum | PROGRAMMING | 1,800 | [
"math",
"number theory"
] | null | null | You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$.
Find out the non-negative ... | The first line contains four integers $n, a, b$ and $k$ $(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$.
The second line contains a sequence of length $k$ consisting of characters '+' and '-'.
If the $i$-th character (0-indexed) is '+', then $s_{i} = 1$, otherwise $s_{i} = -1$.
Note that onl... | Output a single integer — value of given expression modulo $10^{9} + 9$. | [
"2 2 3 3\n+-+\n",
"4 1 5 1\n-\n"
] | [
"7\n",
"999999228\n"
] | In the first example:
$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$ = $2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$ = 7
In the second example:
$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$. | 500 | [
{
"input": "2 2 3 3\n+-+",
"output": "7"
},
{
"input": "4 1 5 1\n-",
"output": "999999228"
},
{
"input": "1 1 4 2\n-+",
"output": "3"
},
{
"input": "3 1 4 4\n+--+",
"output": "45"
},
{
"input": "5 1 1 6\n++---+",
"output": "0"
},
{
"input": "5 2 2 6\n+... | 1,523,976,171 | 2,271 | Python 3 | WRONG_ANSWER | PRETESTS | 8 | 249 | 7,065,600 | M = 10 ** 9 + 9
def pw(x, y):
if (y == 0):
return 1
if (y % 2 == 1):
return x * pw(x, y - 1) % M
t = pw(x, y >> 1)
return t * t % M;
n, a, b, k = map(int, input().split())
m = pw(b, k) * pw(pw(a, k), M - 2) % M
s = input()
b0 = 0;
for i in range(0, k):
if (s[i] == '+'):
b0 += pw(a, n - i) * pw(b, i) % M
... | Title: Alternating Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other w... | ```python
M = 10 ** 9 + 9
def pw(x, y):
if (y == 0):
return 1
if (y % 2 == 1):
return x * pw(x, y - 1) % M
t = pw(x, y >> 1)
return t * t % M;
n, a, b, k = map(int, input().split())
m = pw(b, k) * pw(pw(a, k), M - 2) % M
s = input()
b0 = 0;
for i in range(0, k):
if (s[i] == '+'):
b0 += pw(a, n - i) * pw(b,... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
769 | A | Year of University Entrance | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups f... | The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed tha... | Print the year of Igor's university entrance. | [
"3\n2014 2016 2015\n",
"1\n2050\n"
] | [
"2015\n",
"2050\n"
] | In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance. | 500 | [
{
"input": "3\n2014 2016 2015",
"output": "2015"
},
{
"input": "1\n2050",
"output": "2050"
},
{
"input": "1\n2010",
"output": "2010"
},
{
"input": "1\n2011",
"output": "2011"
},
{
"input": "3\n2010 2011 2012",
"output": "2011"
},
{
"input": "3\n2049 20... | 1,488,705,077 | 76,277 | Python 3 | OK | TESTS | 45 | 62 | 4,608,000 | n = int(input())
a = []
a = input().split()
i = 0
s = 0
while i < n:
s = s + int(a[i])
i = i + 1
x = s/n
print(int(x))
| Title: Year of University Entrance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of correspond... | ```python
n = int(input())
a = []
a = input().split()
i = 0
s = 0
while i < n:
s = s + int(a[i])
i = i + 1
x = s/n
print(int(x))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,624,163,273 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 3,379,200 | a = input().split()
n = int(a[0])
m = int(a[1])
lista = input().split()
pos = 0
neg = 0
for i in range(len(lista)):
if(lista[i]=='1'):
pos+=1
else:
neg+=1
for i in range(m):
a = input().split()
l = int(a[0])-1
r = int(a[1])-1
qtd = r-l+1
flag = 1
limite = min(neg, pos)
e = 0
while (e<=limite... | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
a = input().split()
n = int(a[0])
m = int(a[1])
lista = input().split()
pos = 0
neg = 0
for i in range(len(lista)):
if(lista[i]=='1'):
pos+=1
else:
neg+=1
for i in range(m):
a = input().split()
l = int(a[0])-1
r = int(a[1])-1
qtd = r-l+1
flag = 1
limite = min(neg, pos)
e = 0
while ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,606,020,049 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 451 | 14,131,200 |
# seg=[0]*100005
# def build_query(ind,low,high):
# if low==high:
# seg[ind]=arr[low]
# return
# mid=low+(high-low)//2
# build_query(2*ind+1,low,mid) #left call
# build_query(2*ind+2,mid+1,high) #right call
# seg[ind]=min(seg[2*ind+1],seg[2*ind+2])
# def query(ind,low,high,l,r):
# ... | Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
# seg=[0]*100005
# def build_query(ind,low,high):
# if low==high:
# seg[ind]=arr[low]
# return
# mid=low+(high-low)//2
# build_query(2*ind+1,low,mid) #left call
# build_query(2*ind+2,mid+1,high) #right call
# seg[ind]=min(seg[2*ind+1],seg[2*ind+2])
# def query(ind,low,high,... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original strin... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
... | 1,585,234,137 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 108 | 307,200 | n, k = [int(x) for x in input().split()]
string = input()
maximum_size = 0
current_size = 0
last_size = None
before_last_size = None
last_char = None
for char in string:
if last_char is None:
last_char = char
elif last_char != char: # We changed a->b or b->a
possible_maximum_size = current_siz... | Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ... | ```python
n, k = [int(x) for x in input().split()]
string = input()
maximum_size = 0
current_size = 0
last_size = None
before_last_size = None
last_char = None
for char in string:
if last_char is None:
last_char = char
elif last_char != char: # We changed a->b or b->a
possible_maximum_size = c... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
544 | B | Sea and Islands | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to... | The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. | If the answer doesn't exist, print "NO" (without the quotes) in a single line.
Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is t... | [
"5 2\n",
"5 25\n"
] | [
"YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n",
"NO\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS"
},
{
"input": "5 25",
"output": "NO"
},
{
"input": "82 6047",
"output": "NO"
},
{
"input": "6 5",
"output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS"
},
{
"input": "10 80",
"outpu... | 1,561,922,362 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 155 | 1,843,200 | n, k = map(int, input().split())
m = 0
if(n%2==0):
m = n*n//2
else:
m = ((n+1)*(n+1))//4 + ((n-1)*(n-1))//4
if(m < k):
print("NO")
else:
print("YES")
for i in range(n):
s = ""
for j in range(n):
if(i%2==1):
if(k > 0):
if(j%2==1):
s += "L"
k -= 1
else:
s += "S"
else:
... | Title: Sea and Islands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on... | ```python
n, k = map(int, input().split())
m = 0
if(n%2==0):
m = n*n//2
else:
m = ((n+1)*(n+1))//4 + ((n-1)*(n-1))//4
if(m < k):
print("NO")
else:
print("YES")
for i in range(n):
s = ""
for j in range(n):
if(i%2==1):
if(k > 0):
if(j%2==1):
s += "L"
k -= 1
else:
s += "S"
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
475 | A | Bayan Bus | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of *k* participants who should be picked up at the airport. When a... | The only line of input contains integer *k*, (0<=≤<=*k*<=≤<=34), denoting the number of participants. | Print the figure of a bus with *k* passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six ... | [
"9\n",
"20\n"
] | [
"+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n",
"+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|... | none | 500 | [
{
"input": "9",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "20",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.... | 1,412,516,463 | 2,463 | Python 3 | CHALLENGED | CHALLENGES | 4 | 61 | 0 | k=int(input())
print("+------------------------+")
s=1
kc=k
sh=1
while s<=4:
sh=1
print("|",end="")
if(s==1):
while(sh<=12):
if(sh!=12):
if k>0:
print("O.",end="")
if(k==kc):
... | Title: Bayan Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The ... | ```python
k=int(input())
print("+------------------------+")
s=1
kc=k
sh=1
while s<=4:
sh=1
print("|",end="")
if(s==1):
while(sh<=12):
if(sh!=12):
if k>0:
print("O.",end="")
if(k==kc):
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,508,414,153 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 62 | 5,529,600 | n = int(input())
a = int(input()) # kr sov
b = int(input()) # kr os
c = int(input()) # sov os
s = 0
point = 'k'
n -= 1
while n > 0:
if point == 'k':
if a >= b:
s += b
point = 'o'
n -= 1
continue
else:
s += a
... | Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
n = int(input())
a = int(input()) # kr sov
b = int(input()) # kr os
c = int(input()) # sov os
s = 0
point = 'k'
n -= 1
while n > 0:
if point == 'k':
if a >= b:
s += b
point = 'o'
n -= 1
continue
else:
s += a
... | 3 | 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,614,686,262 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | try:
n,m = map(int, input().split())
if n>m:
j=0
s=""
while n>0:
if j%2==0:
s = s + "B"
j = j + 1
n = n-1
else:
if m>0:
s = s + "G"
j = j + 1
... | 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
try:
n,m = map(int, input().split())
if n>m:
j=0
s=""
while n>0:
if j%2==0:
s = s + "B"
j = j + 1
n = n-1
else:
if m>0:
s = s + "G"
j = j... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
803 | F | Coprime Subsequences | PROGRAMMING | 2,000 | [
"bitmasks",
"combinatorics",
"number theory"
] | null | null | Let's call a non-empty sequence of positive integers *a*1,<=*a*2... *a**k* coprime if the greatest common divisor of all elements of this sequence is equal to 1.
Given an array *a* consisting of *n* positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109<... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100000).
The second line contains *n* integer numbers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=100000). | Print the number of coprime subsequences of *a* modulo 109<=+<=7. | [
"3\n1 2 3\n",
"4\n1 1 1 1\n",
"7\n1 3 5 15 3 105 35\n"
] | [
"5\n",
"15\n",
"100\n"
] | In the first example coprime subsequences are:
1. 1 1. 1, 2 1. 1, 3 1. 1, 2, 3 1. 2, 3
In the second example all subsequences are coprime. | 0 | [
{
"input": "3\n1 2 3",
"output": "5"
},
{
"input": "4\n1 1 1 1",
"output": "15"
},
{
"input": "7\n1 3 5 15 3 105 35",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n100000",
"output": "0"
},
{
"input": "5\n10 8 6 4 6",
"outpu... | 1,638,939,808 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 27 | 467 | 10,547,200 | def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
N = max(A)
C = ... | Title: Coprime Subsequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a non-empty sequence of positive integers *a*1,<=*a*2... *a**k* coprime if the greatest common divisor of all elements of this sequence is equal to 1.
Given an array *a* consisting of *n* positive integ... | ```python
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
N = ma... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,644,593,988 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 31 | 102,400 | # import math
from collections import Counter, deque, defaultdict
from math import *
from bisect import bisect_right
mod = 1000000007
# from functools import reduce
# from itertools import permutations
# import queue
def solve():
a, b = map(int, input().split())
if abs(a - b) <= 1:
... | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
# import math
from collections import Counter, deque, defaultdict
from math import *
from bisect import bisect_right
mod = 1000000007
# from functools import reduce
# from itertools import permutations
# import queue
def solve():
a, b = map(int, input().split())
if abs(a - b) <= ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,597,351,882 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n, k, m, d = map(int, input().split())
ans = 0
for i in range(1, d+1):
hi = min(m, n//(k*(i-1)+1), lo = n//(k*i+1)
if(hi > lo) ans = max(ans, i*hi)
print(ans) | Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
n, k, m, d = map(int, input().split())
ans = 0
for i in range(1, d+1):
hi = min(m, n//(k*(i-1)+1), lo = n//(k*i+1)
if(hi > lo) ans = max(ans, i*hi)
print(ans)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
280 | B | Maximum Xor Secondary | PROGRAMMING | 1,800 | [
"data structures",
"implementation",
"two pointers"
] | null | null | Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=><=1) is such maximum element *x**j*, that the following inequality holds: .
The lucky number of the sequence of distinct positive integers *x*1,<=*x*2,<... | The first line contains integer *n* (1<=<<=*n*<=≤<=105). The second line contains *n* distinct integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=109). | Print a single integer — the maximum lucky number among all lucky numbers of sequences *s*[*l*..*r*]. | [
"5\n5 2 1 4 3\n",
"5\n9 8 3 5 7\n"
] | [
"7\n",
"15\n"
] | For the first sample you can choose *s*[4..5] = {4, 3} and its lucky number is (4 *xor* 3) = 7. You can also choose *s*[1..2].
For the second sample you must choose *s*[2..5] = {8, 3, 5, 7}. | 1,000 | [
{
"input": "5\n5 2 1 4 3",
"output": "7"
},
{
"input": "5\n9 8 3 5 7",
"output": "15"
},
{
"input": "10\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446",
"output": "128869996"
},
{
"input": "10\n4547989 39261040 94929326 38131456 26174... | 1,678,841,550 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 124 | 18,636,800 | import heapq;
import math;
from collections import deque, Counter;
import sys;
mod = 998244353;
input = sys.stdin.readline;
n = int(input())
array = list(map(int, input().split()))
stack = []
ans = 0;
for num in array:
while stack:
ans = max(ans, num ^ stack[-1]... | Title: Maximum Xor Secondary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=><=1) is such maximum element *x**j*, that the ... | ```python
import heapq;
import math;
from collections import deque, Counter;
import sys;
mod = 998244353;
input = sys.stdin.readline;
n = int(input())
array = list(map(int, input().split()))
stack = []
ans = 0;
for num in array:
while stack:
ans = max(ans, num ^... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,457,023,517 | 617 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 46 | 0 | n = int(input())
ans1, ans2 = 1, 1
data1 = list(map(int, input().split()))
data2 = list(map(int, input().split()))
for i in range(n):
ans1 = ans1 | data1[i]
ans2 = ans2 | data2[i]
print(ans1 + ans2) | Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
n = int(input())
ans1, ans2 = 1, 1
data1 = list(map(int, input().split()))
data2 = list(map(int, input().split()))
for i in range(n):
ans1 = ans1 | data1[i]
ans2 = ans2 | data2[i]
print(ans1 + ans2)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,561,319,326 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | a,b=map(int,input().split())
if b==0 and a==0:
print("NO")
elif a==b or abs(a-b)==1:
print("YES")
else:
print("NO") | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
a,b=map(int,input().split())
if b==0 and a==0:
print("NO")
elif a==b or abs(a-b)==1:
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) —... | Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to ... | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2... | 1,574,415,588 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 31 | 280 | 0 | n, m, k = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
ava = k
i = n-1
ans = 0
result = False
while i >= 0:
if ava >= m:
result = True
break
ava += (l[i]-1)
i -= 1
ans += 1
if result:
print(ans)
else:
print(-1) | Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his f... | ```python
n, m, k = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
ava = k
i = n-1
ans = 0
result = False
while i >= 0:
if ava >= m:
result = True
break
ava += (l[i]-1)
i -= 1
ans += 1
if result:
print(ans)
else:
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,632,648,163 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 216 | 20,172,800 | n=input()
a=len(n)
c=0
d=0
for i in range(a):
if(n[i].isupper()):
c=c+1
else:
d=d+1
if(c>d):
print(n.upper())
else:
print(n.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
n=input()
a=len(n)
c=0
d=0
for i in range(a):
if(n[i].isupper()):
c=c+1
else:
d=d+1
if(c>d):
print(n.upper())
else:
print(n.lower())
``` | 3.908425 | MatrixStudio/Codeforces-Python-Submissions |
862 | B | Mahmoud and Ehab and the bipartiteness | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *... | The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105).
The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree.
It's guaranteed that the given graph is a tree. | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | [
"3\n1 2\n1 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n"
] | [
"0\n",
"2\n"
] | Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))
Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph)
In the first test case the only edge that can be added in such a way, that ... | 1,000 | [
{
"input": "3\n1 2\n1 3",
"output": "0"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6",
"output": "16"
},
{
"input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4",
"output": "16"
},
{
"in... | 1,562,496,739 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 967 | 15,974,400 | WHITE, BLACK = 0, 1
def dfs(adj, node_colors):
stk = [0]
node_colors[0] = WHITE
while stk:
node = stk.pop()
for i in range(len(adj[node])):
if node_colors[adj[node][i]] == -1:
node_colors[adj[node][i]] = 1 - node_colors[node]
stk.appen... | Title: Mahmoud and Ehab and the bipartiteness
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a gra... | ```python
WHITE, BLACK = 0, 1
def dfs(adj, node_colors):
stk = [0]
node_colors[0] = WHITE
while stk:
node = stk.pop()
for i in range(len(adj[node])):
if node_colors[adj[node][i]] == -1:
node_colors[adj[node][i]] = 1 - node_colors[node]
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
682 | D | Alyona and Strings | PROGRAMMING | 1,900 | [
"dp",
"strings"
] | null | null | After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar.
Alyona has her favourite positive integer *k* and bec... | In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively.
The second line of the input contains string *s*, consisting of lowercase English letters.
The thi... | In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence.
It is guaranteed, that at least one desired sequence exists. | [
"3 2 2\nabc\nab\n",
"9 12 4\nbbaaababb\nabbbabbaaaba\n"
] | [
"2\n",
"7\n"
] | The following image describes the answer for the second sample case: | 2,000 | [
{
"input": "3 2 2\nabc\nab",
"output": "2"
},
{
"input": "9 12 4\nbbaaababb\nabbbabbaaaba",
"output": "7"
},
{
"input": "11 11 4\naaababbabbb\nbbbaaaabaab",
"output": "7"
},
{
"input": "15 9 4\nababaaabbaaaabb\nbbaababbb",
"output": "8"
},
{
"input": "2 7 1\nbb\nb... | 1,467,038,668 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | read = lambda: map(int, input().split())
n, m, k = read()
s = input()
t = input()
| Title: Alyona and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to string... | ```python
read = lambda: map(int, input().split())
n, m, k = read()
s = input()
t = input()
``` | 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.