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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not ... | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20... | 1,694,345,929 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 31 | 0 | n = int(input())
a = list(map(int, input().split()))
count = [0]*100
for i in a:
count[i] += 1
for i in range(100):
if count[i] > 0:
print((str(i) + ' ') * count[i], end='') | Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the bo... | ```python
n = int(input())
a = list(map(int, input().split()))
count = [0]*100
for i in a:
count[i] += 1
for i in range(100):
if count[i] > 0:
print((str(i) + ' ') * count[i], end='')
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
31 | B | Sysadmin Bob | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"strings"
] | B. Sysadmin Bob | 0 | 256 | Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitra... | The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». | If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of the... | [
"a@aa@a\n",
"a@a@a\n",
"@aa@a\n"
] | [
"a@a,a@a\n",
"No solution\n",
"No solution\n"
] | none | 1,000 | [
{
"input": "a@aa@a",
"output": "a@a,a@a"
},
{
"input": "a@a@a",
"output": "No solution"
},
{
"input": "@aa@a",
"output": "No solution"
},
{
"input": "aba@caba@daba",
"output": "aba@c,aba@daba"
},
{
"input": "asd@qwasd@qwasd@qwasd@qwasd@qw",
"output": "asd@q,wa... | 1,643,433,555 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | s = input().split('@')
if('' in s):
print('No solution')
else:
r = s[1:len(s)-1]
flag = 0
for i in range(len(r)):
if(len(r[i]) < 2):
flag = 1
break
if(flag == 1):
print('No solution')
else:
t = s[0]
for i in range(1,len(s)-1):
t += '@' + s[i][0] + ',' +s[i][1:]
t += '@' + s... | Title: Sysadmin Bob
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of t... | ```python
s = input().split('@')
if('' in s):
print('No solution')
else:
r = s[1:len(s)-1]
flag = 0
for i in range(len(r)):
if(len(r[i]) < 2):
flag = 1
break
if(flag == 1):
print('No solution')
else:
t = s[0]
for i in range(1,len(s)-1):
t += '@' + s[i][0] + ',' +s[i][1:]
t ... | 0 | MatrixStudio/Codeforces-Python-Submissions |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,690,032,025 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | t = int(input())
m = 0
c = 0
while t>0:
x,y = [int(i) for i in input().split()]
if(x>y):
m+=1
elif(x<y):
c+=1
t-=1
if(m>c):
print("Mishka\n\n")
elif(m<c):
print("Chris\n\n")
else:
print("Friendship is magic!^^\n\n") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
t = int(input())
m = 0
c = 0
while t>0:
x,y = [int(i) for i in input().split()]
if(x>y):
m+=1
elif(x<y):
c+=1
t-=1
if(m>c):
print("Mishka\n\n")
elif(m<c):
print("Chris\n\n")
else:
print("Friendship is magic!^^\n\n")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,661,276,547 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 124 | 0 | def PROBLEM():
N=int(input())
l=list(map(int,input().split()))
x=FUNCTION(l,N)
print(x,len(set(l)))
def FUNCTION(l,N):
MaxC=l.count(l[0])
C=l[0]
for i in l:
if i!=C:
if l.count(i)>MaxC:
MaxC=l.count(i)
return MaxC
PROBLEM() | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
def PROBLEM():
N=int(input())
l=list(map(int,input().split()))
x=FUNCTION(l,N)
print(x,len(set(l)))
def FUNCTION(l,N):
MaxC=l.count(l[0])
C=l[0]
for i in l:
if i!=C:
if l.count(i)>MaxC:
MaxC=l.count(i)
return MaxC
PROB... | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
879 | A | Borya's Diagnosis | PROGRAMMING | 900 | [
"implementation"
] | null | null | It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get t... | First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000). | Output a single integer — the minimum day at which Borya can visit the last doctor. | [
"3\n2 2\n1 2\n2 2\n",
"2\n10 1\n6 5\n"
] | [
"4\n",
"11\n"
] | In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11. | 500 | [
{
"input": "3\n2 2\n1 2\n2 2",
"output": "4"
},
{
"input": "2\n10 1\n6 5",
"output": "11"
},
{
"input": "3\n6 10\n3 3\n8 2",
"output": "10"
},
{
"input": "4\n4 8\n10 10\n4 2\n8 2",
"output": "14"
},
{
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8",
"output": "14"
},
... | 1,605,439,630 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n = int(input())
s, d = map(int, input().split())
min_d = s
for i in range(n - 1):
s, d = map(int, input().split())
while s < min_d:
s += d
min_d += s - min_d
print(min_d) | Title: Borya's Diagnosis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed o... | ```python
n = int(input())
s, d = map(int, input().split())
min_d = s
for i in range(n - 1):
s, d = map(int, input().split())
while s < min_d:
s += d
min_d += s - min_d
print(min_d)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
331 | C1 | The Great Julya Calendar | PROGRAMMING | 1,100 | [
"dp"
] | null | null | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open ... | The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co... | Print a single integer — the minimum number of subtractions that turns the magic number to a zero. | [
"24\n"
] | [
"5"
] | In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | 20 | [
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
... | 1,685,754,222 | 2,147,483,647 | PyPy 3-64 | OK | TESTS1 | 24 | 528 | 10,956,800 | N = int(input())
table = [-1] * (N+1)
table[0] = 0
for i in range(1, min(N, 9)+1):
table[i] = 1
for i in range(10, N+1):
numbers = list(map(int, list(str(i))))
# print(numbers)
minimum = 999_999_999
for number in numbers:
if number == 0:
continue
minimum = min... | Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i... | ```python
N = int(input())
table = [-1] * (N+1)
table[0] = 0
for i in range(1, min(N, 9)+1):
table[i] = 1
for i in range(10, N+1):
numbers = list(map(int, list(str(i))))
# print(numbers)
minimum = 999_999_999
for number in numbers:
if number == 0:
continue
min... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,623,339,867 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 77 | 0 | import math
n,t,k,d=map(int,input().split())
if(k>=n):
print("NO")
else:
c=math.ceil(n/k)
s=t*c
k=t+d
if(s>k):
print("YES")
else:
print("NO")
| Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
import math
n,t,k,d=map(int,input().split())
if(k>=n):
print("NO")
else:
c=math.ceil(n/k)
s=t*c
k=t+d
if(s>k):
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
770 | B | Maximize Sum of Digits | PROGRAMMING | 1,300 | [
"*special",
"implementation",
"math"
] | null | null | Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. | The first line contains the positive integer *x* (1<=≤<=*x*<=≤<=1018) — the integer which Anton has. | Print the positive integer which doesn't exceed *x* and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros. | [
"100\n",
"48\n",
"521\n"
] | [
"99\n",
"48\n",
"499\n"
] | none | 1,000 | [
{
"input": "100",
"output": "99"
},
{
"input": "48",
"output": "48"
},
{
"input": "521",
"output": "499"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input": "39188",
"output":... | 1,698,382,076 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n=int(input())
if n<10:
print(n)
exit()
k=9
while k<n:
k=9+k*10
if k==n:
print(k)
else:
k=int(str(n)[0]+str(k))
m=len(str(n))-1
r=k
while r<n:
r=int(str(k)[:m]+str(int(str(k)[m])-1)+str(k)[k+1::])
print(r)
| Title: Maximize Sum of Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are sev... | ```python
n=int(input())
if n<10:
print(n)
exit()
k=9
while k<n:
k=9+k*10
if k==n:
print(k)
else:
k=int(str(n)[0]+str(k))
m=len(str(n))-1
r=k
while r<n:
r=int(str(k)[:m]+str(int(str(k)[m])-1)+str(k)[k+1::])
print(r)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
474 | A | Keyboard | PROGRAMMING | 900 | [
"implementation"
] | null | null | Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean... | First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ... | Print a line that contains the original message. | [
"R\ns;;upimrrfod;pbr\n"
] | [
"allyouneedislove\n"
] | none | 500 | [
{
"input": "R\ns;;upimrrfod;pbr",
"output": "allyouneedislove"
},
{
"input": "R\nwertyuiop;lkjhgfdsxcvbnm,.",
"output": "qwertyuiolkjhgfdsazxcvbnm,"
},
{
"input": "L\nzxcvbnm,kjhgfdsaqwertyuio",
"output": "xcvbnm,.lkjhgfdswertyuiop"
},
{
"input": "R\nbubbuduppudup",
"outp... | 1,674,322,566 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 77 | 0 | def original_message(string, direction):
keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./"
original_string = ""
for char in string:
index = keyboard.index(char)
if direction == "R":
index -= 1
else:
index += 1
original_char = keyboard[index]
... | Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately.... | ```python
def original_message(string, direction):
keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./"
original_string = ""
for char in string:
index = keyboard.index(char)
if direction == "R":
index -= 1
else:
index += 1
original_char = keyboard[inde... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,697,637,773 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s=input()
x=max(s)
for i in range(len(s):
if x==s[i]:
print(s[i] end=" ") | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
s=input()
x=max(s)
for i in range(len(s):
if x==s[i]:
print(s[i] end=" ")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
774 | D | Lie or Truth | PROGRAMMING | 1,500 | [
"*special",
"constructive algorithms",
"implementation",
"sortings"
] | null | null | Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*.
While Vasya was walking, his little brother Stepan played with Vasya's cub... | The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of integers written on cubes in the Vasya's order.
... | Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes). | [
"5 2 4\n3 4 2 3 1\n3 2 3 4 1\n",
"3 1 2\n1 2 3\n3 1 2\n",
"4 2 4\n1 1 1 1\n1 1 1 1\n"
] | [
"TRUTH\n",
"LIE\n",
"TRUTH\n"
] | In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and... | 0 | [
{
"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1",
"output": "TRUTH"
},
{
"input": "3 1 2\n1 2 3\n3 1 2",
"output": "LIE"
},
{
"input": "4 2 4\n1 1 1 1\n1 1 1 1",
"output": "TRUTH"
},
{
"input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2",
"output": "TRUTH"
},
{
"input": "7 1 4\n2 5 5 5... | 1,699,845,069 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 |
def solve():
line1=input()
line2=input()
line3=input()
n,l,r=[int(x) for x in line1.split()]
before=[int(x) for x in line2.split()]
after=[int(x) for x in line3.split()]
if before != after and before[:l - 2] == after[:l - 2] and before[r:] == after[r:]:
print("TRUTH")
else:
... | Title: Lie or Truth
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,... | ```python
def solve():
line1=input()
line2=input()
line3=input()
n,l,r=[int(x) for x in line1.split()]
before=[int(x) for x in line2.split()]
after=[int(x) for x in line3.split()]
if before != after and before[:l - 2] == after[:l - 2] and before[r:] == after[r:]:
print("TRUTH")
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,684,296,317 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 62 | 3,072,000 | import sys
ll = []
x = int(input())
mm =sys.stdin.read().split("\n");mm.remove("")
nn = set("".join(mm))
if len(nn) != 2 :
print("NO")
exit()
first = mm[0][0]
second = list(nn)[list(nn).index(first)-1]
ss =[]
for i in range((x+1)//2):
ss.append(i*second+first+(x-2*(i+1))*second+first*((i!=x//2))... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
import sys
ll = []
x = int(input())
mm =sys.stdin.read().split("\n");mm.remove("")
nn = set("".join(mm))
if len(nn) != 2 :
print("NO")
exit()
first = mm[0][0]
second = list(nn)[list(nn).index(first)-1]
ss =[]
for i in range((x+1)//2):
ss.append(i*second+first+(x-2*(i+1))*second+first*(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
21 | A | Jabber ID | PROGRAMMING | 1,900 | [
"implementation",
"strings"
] | A. Jabber ID | 0 | 256 | Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive. - <hostname> — is... | The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive. | Print YES or NO. | [
"[email protected]\n",
"[email protected]/contest.icpc/12\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "mike@codeforces.com",
"output": "YES"
},
{
"input": "john.smith@codeforces.ru/contest.icpc/12",
"output": "NO"
},
{
"input": "test@test.ri/abacaba",
"output": "YES"
},
{
"input": "@ops",
"output": "NO"
},
{
"input": "this-is-the-test",
"output": "N... | 1,597,670,629 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 14 | 139 | 0 | s=input()
if(len(s.split('@'))!=2):
print("NO")
quit()
a,b=s.split('@')[0],s.split('@')[1]
bo=0
for e in a:
if(not e.isalnum()):
if(e=='_'):
continue
bo=1
if(1>len(a) or len(a)>16):
bo=1
if('/' in b):
if(b.count('/')>1):
bo=1
c,d=b.split('/')[0... | Title: Jabber ID
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «... | ```python
s=input()
if(len(s.split('@'))!=2):
print("NO")
quit()
a,b=s.split('@')[0],s.split('@')[1]
bo=0
for e in a:
if(not e.isalnum()):
if(e=='_'):
continue
bo=1
if(1>len(a) or len(a)>16):
bo=1
if('/' in b):
if(b.count('/')>1):
bo=1
c,d=b.sp... | 0 | MatrixStudio/Codeforces-Python-Submissions |
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,659,003,186 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 77 | 6,041,600 | n = int(input())
p = list(map(int,input().split()))
color = list(map(int,input().split()))
a = [i for i in range(1,n+1)]
adj = [[] for i in range(n+1)]
for i in range(len(p)):
adj[i+2].append(p[i])
adj[p[i]].append(i+2)
vis = [0 for i in range(n+1)]
clr = [0 for i in range(1,n+1)]
def dfs(r):
c... | Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
n = int(input())
p = list(map(int,input().split()))
color = list(map(int,input().split()))
a = [i for i in range(1,n+1)]
adj = [[] for i in range(n+1)]
for i in range(len(p)):
adj[i+2].append(p[i])
adj[p[i]].append(i+2)
vis = [0 for i in range(n+1)]
clr = [0 for i in range(1,n+1)]
def dfs(... | 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,658,219,921 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | n=int(input())
d=list(map(int,input().split()))
a,b=map(int,input().split())
print(sum(d[a-1:a-1+(b-a)]))
| Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
n=int(input())
d=list(map(int,input().split()))
a,b=map(int,input().split())
print(sum(d[a-1:a-1+(b-a)]))
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,650,467,150 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 154 | 614,400 | from sys import stdin, stdout
def rd(): return stdin.readline().strip()
def wtl(x): stdout.write(str(x) + '\n')
n, mp, f = int(rd()), dict(), dict()
nm, sc = ["" for i in range(n)], [0 for i in range(n)]
for i in range(n):
inp = rd().split()
nm[i], sc[i] = inp[0], int(inp[1])
if nm[i] in mp:
... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
from sys import stdin, stdout
def rd(): return stdin.readline().strip()
def wtl(x): stdout.write(str(x) + '\n')
n, mp, f = int(rd()), dict(), dict()
nm, sc = ["" for i in range(n)], [0 for i in range(n)]
for i in range(n):
inp = rd().split()
nm[i], sc[i] = inp[0], int(inp[1])
if nm[i] in... | 3.918422 | MatrixStudio/Codeforces-Python-Submissions |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus likes palindromes very much. There was his birthday recently. *k* of his friends came to him to congratulate him, and each of them presented to him a string *s**i* having the same length *n*. We denote the beauty of the *i*-th string by *a**i*. It can happen that *a**i* is negative — that means that Santa d... | The first line contains two positive integers *k* and *n* divided by space and denoting the number of Santa friends and the length of every string they've presented, respectively (1<=≤<=*k*,<=*n*<=≤<=100<=000; *n*·*k* <=≤<=100<=000).
*k* lines follow. The *i*-th of them contains the string *s**i* and its beauty *a**i*... | In the only line print the required maximum possible beauty. | [
"7 3\nabb 2\naaa -3\nbba -1\nzyz -4\nabb 5\naaa 7\nxyx 4\n",
"3 1\na 1\na 2\na 3\n",
"2 5\nabcde 10000\nabcde 10000\n"
] | [
"12\n",
"6\n",
"0\n"
] | In the first example Santa can obtain abbaaaxyxaaabba by concatenating strings 5, 2, 7, 6 and 3 (in this order). | 0 | [
{
"input": "7 3\nabb 2\naaa -3\nbba -1\nzyz -4\nabb 5\naaa 7\nxyx 4",
"output": "12"
},
{
"input": "3 1\na 1\na 2\na 3",
"output": "6"
},
{
"input": "2 5\nabcde 10000\nabcde 10000",
"output": "0"
},
{
"input": "10 10\nnjxbzflaka -1\nfelbvvtkja 6\ngxiuztqkcw 5\naomvscmtti 6\nj... | 1,691,830,160 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 62 | 2,764,800 | # nikitagoder (md: bobwish)
from collections import defaultdict
import sys
def main():
k, n = map(int, input().split())
m = defaultdict(list)
for _ in range(k):
s, a = input().split()
a = int(a)
m[s].append(a)
ans1 = 0
ans = 0
max1 = -sys.maxsi... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus likes palindromes very much. There was his birthday recently. *k* of his friends came to him to congratulate him, and each of them presented to him a string *s**i* having the same length *n*. We denote the beauty of th... | ```python
# nikitagoder (md: bobwish)
from collections import defaultdict
import sys
def main():
k, n = map(int, input().split())
m = defaultdict(list)
for _ in range(k):
s, a = input().split()
a = int(a)
m[s].append(a)
ans1 = 0
ans = 0
max1 = ... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — ... | The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has... | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
}... | 1,689,708,965 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | a=int(input())
b=int(input())
c=int(input())
print(c // 4 + c // 4 * 2 + c // 4 * 4) | Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa... | ```python
a=int(input())
b=int(input())
c=int(input())
print(c // 4 + c // 4 * 2 + c // 4 * 4)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
218 | A | Mountain Scenery | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting th... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100). The next line contains 2*n*<=+<=1 space-separated integers *r*1,<=*r*2,<=...,<=*r*2*n*<=+<=1 (0<=≤<=*r**i*<=≤<=100) — the *y* coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the gi... | Print 2*n*<=+<=1 integers *y*1,<=*y*2,<=...,<=*y*2*n*<=+<=1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. | [
"3 2\n0 5 3 5 1 5 2\n",
"1 1\n0 2 0\n"
] | [
"0 5 3 4 1 4 2 \n",
"0 1 0 \n"
] | none | 500 | [
{
"input": "3 2\n0 5 3 5 1 5 2",
"output": "0 5 3 4 1 4 2 "
},
{
"input": "1 1\n0 2 0",
"output": "0 1 0 "
},
{
"input": "1 1\n1 100 0",
"output": "1 99 0 "
},
{
"input": "3 1\n0 1 0 1 0 2 0",
"output": "0 1 0 1 0 1 0 "
},
{
"input": "3 1\n0 1 0 2 0 1 0",
"out... | 1,686,172,250 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def f(k,peaks):
i=1
while k>0:
t = peaks[i]-1
if t > peaks[i-1] and t > peaks[i+1]:
peaks[i] = t
k-=1
i+=2
return peaks
nk=input()
k=[int(i) for i in nk.split(" ")][1]
peaks=input()
peaks=[int(i) for i in peaks.split(" ")]
print(f(k,peak... | Title: Mountain Scenery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordi... | ```python
def f(k,peaks):
i=1
while k>0:
t = peaks[i]-1
if t > peaks[i-1] and t > peaks[i+1]:
peaks[i] = t
k-=1
i+=2
return peaks
nk=input()
k=[int(i) for i in nk.split(" ")][1]
peaks=input()
peaks=[int(i) for i in peaks.split(" ")]
prin... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤... | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sam... | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"inp... | 1,566,454,109 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 218 | 307,200 |
# n = 8
# k = 3
# a = [1, 1, 2, 2, 3, 3, 4, 5]
n, k = map(int, input().split())
a = list(map(int, input().split()))
uniq = [0]*n
le = 0
ri = 0
pr = 0
sa = len(a)
ha = False
x0 = 0
y0 = 0
cnt = 0
if (k == 1):
print('1 1')
else:
for le in range(0,sa-k+1):
if (uniq[a[le]-1] == 0):
... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<... | ```python
# n = 8
# k = 3
# a = [1, 1, 2, 2, 3, 3, 4, 5]
n, k = map(int, input().split())
a = list(map(int, input().split()))
uniq = [0]*n
le = 0
ri = 0
pr = 0
sa = len(a)
ha = False
x0 = 0
y0 = 0
cnt = 0
if (k == 1):
print('1 1')
else:
for le in range(0,sa-k+1):
if (uniq[a[le]-1]... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 ... | 1,448,868,648 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 154 | 0 | l =[13, 19, 31, 37, 43, 53, 61, 79, 101, 113, 139, 163, 173, 199, 211, 223, 241, 269, 277, 331, 353, 373, 397, 457, 463, 509, 521, 541, 577, 601, 619, 631, 727, 773, 787, 811, 829, 853, 883, 907, 919, 947, 967, 991]
n,k = list(map(int,input().split()))
km = 0
for i in l:
if i <= n:
km += 1
else:
break
pri... | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob... | ```python
l =[13, 19, 31, 37, 43, 53, 61, 79, 101, 113, 139, 163, 173, 199, 211, 223, 241, 269, 277, 331, 353, 373, 397, 457, 463, 509, 521, 541, 577, 601, 619, 631, 727, 773, 787, 811, 829, 853, 883, 907, 919, 947, 967, 991]
n,k = list(map(int,input().split()))
km = 0
for i in l:
if i <= n:
km += 1
else:
... | 3.9615 | MatrixStudio/Codeforces-Python-Submissions |
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=... | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"in... | 1,580,120,680 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 280 | 307,200 | """
author - Sayan Bose
date - 26.01.2020
Brooklyn 99 is love!
"""
def solve():
n = int(input())
top = int(input())
li = []
for _ in range(n):
li.append(list(map(int, input().split())))
t1 = [abs(top-7)]
t = []
for i in li:
temp = [i[0], abs(i[0] -... | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other... | ```python
"""
author - Sayan Bose
date - 26.01.2020
Brooklyn 99 is love!
"""
def solve():
n = int(input())
top = int(input())
li = []
for _ in range(n):
li.append(list(map(int, input().split())))
t1 = [abs(top-7)]
t = []
for i in li:
temp = [i[0], ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,444,466,583 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | #!/usr/bin/python3
n=int(input())
answer=0
n2=1
while(n!=0):
i=n%10
n=n//10
num=0
if i == 4:
num=1
else:
num=2
answer+=num*n2
n2*=2
print(answer)
| Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
#!/usr/bin/python3
n=int(input())
answer=0
n2=1
while(n!=0):
i=n%10
n=n//10
num=0
if i == 4:
num=1
else:
num=2
answer+=num*n2
n2*=2
print(answer)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,686,453,072 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | n = int(input())
fingers = [int(x) for x in input().split()]
total = sum(fingers)
n += 1
result = 0
for i in range(1, 6):
if (total + i) % n != 1:
result += 1
print(result)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())
fingers = [int(x) for x in input().split()]
total = sum(fingers)
n += 1
result = 0
for i in range(1, 6):
if (total + i) % n != 1:
result += 1
print(result)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w... | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ... | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input"... | 1,544,806,092 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 218 | 0 | r,c=map(int,input().split())
o=[]
s=''
fc,lc=c//2,c//2-1
for i in range(r):
d=input()
o.append(d)
if '*'in d:
s+='*'
if d.index('*')<fc:
fc=d.find('*')
if d.rindex("*")>lc:
lc=d.rfind('*')
else:
s+='.'
fr,lr=s.index('*'),s.rindex('*'... | Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe... | ```python
r,c=map(int,input().split())
o=[]
s=''
fc,lc=c//2,c//2-1
for i in range(r):
d=input()
o.append(d)
if '*'in d:
s+='*'
if d.index('*')<fc:
fc=d.find('*')
if d.rindex("*")>lc:
lc=d.rfind('*')
else:
s+='.'
fr,lr=s.index('*'),s.... | 0 | MatrixStudio/Codeforces-Python-Submissions |
485 | B | Valuable Resources | PROGRAMMING | 1,300 | [
"brute force",
"greedy"
] | null | null | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes.... | The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. | Print the minimum area of the city that can cover all the mines with valuable resources. | [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
] | [
"4\n",
"9\n"
] | none | 500 | [
{
"input": "2\n0 0\n2 2",
"output": "4"
},
{
"input": "2\n0 0\n0 3",
"output": "9"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "4"
},
{
"input": "3\n3 1\n1 3\n2 2",
"output": "4"
},
{
"input": "3\n0 1\n1 0\n2 ... | 1,626,332,224 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 6,758,400 | n = int(input())
m = -1
for _ in range(n):
n, k = list(map(int, input().split()))
m = max(m, n, k)
print(m**2) | Title: Valuable Resources
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. Th... | ```python
n = int(input())
m = -1
for _ in range(n):
n, k = list(map(int, input().split()))
m = max(m, n, k)
print(m**2)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,694,002,179 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | the_list = input().split()
the_list = [int(item) for item in the_list]
def arrange_funct(n, m , g, b):
the_standing =""
for i in range(n):
the_standing += g
for i in range(0, m-n):
the_standing += b
return the_standing
if the_list[0] >= the_list[1]:
print(arrange_funct(the_list[1], t... | 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
the_list = input().split()
the_list = [int(item) for item in the_list]
def arrange_funct(n, m , g, b):
the_standing =""
for i in range(n):
the_standing += g
for i in range(0, m-n):
the_standing += b
return the_standing
if the_list[0] >= the_list[1]:
print(arrange_funct(the_... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
847 | A | Union of Doubly Linked Lists | PROGRAMMING | 1,500 | [
"implementation"
] | null | null | Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each eleme... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of memory cells where the doubly linked lists are located.
Each of the following *n* lines contains two integers *l**i*, *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=*n*) — the cells of the previous and the next element of list for cell *i*. Value *l**... | Print *n* lines, the *i*-th line must contain two integers *l**i* and *r**i* — the cells of the previous and the next element of list for cell *i* after all lists from the input are united in a single list. If there are many solutions print any of them. | [
"7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0\n"
] | [
"4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0\n"
] | none | 0 | [
{
"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0",
"output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"
},
{
"input": "2\n2 0\n0 1",
"output": "2 0\n0 1"
},
{
"input": "1\n0 0",
"output": "0 0"
},
{
"input": "4\n0 2\n1 0\n0 4\n3 0",
"output": "0 2\n1 3\n2 4\n3 0"
},
{
"i... | 1,540,490,015 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
#include<vector>
using namespace std;
int main(){
int t, n, p, s, cake, diff;
cin >> t;
while(t--){
cake = 0;
diff = 0;
cin >> n >> p;
for(int i = 0; i < n; i++){
cin >> s;
if(s>=p/2) cake++;
else if(s<=p... | Title: Union of Doubly Linked Lists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this proble... | ```python
#include<iostream>
#include<vector>
using namespace std;
int main(){
int t, n, p, s, cake, diff;
cin >> t;
while(t--){
cake = 0;
diff = 0;
cin >> n >> p;
for(int i = 0; i < n; i++){
cin >> s;
if(s>=p/2) cake++;
el... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,669,141,639 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 216 | 13,516,800 | n,k=map(int,input().split())
arr=list(map(int,input().split()))
ne=[];po=[]
for i in range(n):
if arr[i]<0 and k>0:
arr[i]=(-1)* arr[i]
k-=1
arr.sort()
if k&1==0:
print(sum(arr))
else:
print(sum(arr)-2*arr[0]) | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
n,k=map(int,input().split())
arr=list(map(int,input().split()))
ne=[];po=[]
for i in range(n):
if arr[i]<0 and k>0:
arr[i]=(-1)* arr[i]
k-=1
arr.sort()
if k&1==0:
print(sum(arr))
else:
print(sum(arr)-2*arr[0])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
390 | A | Inna and Alarm Clock | PROGRAMMING | 0 | [
"implementation"
] | null | null | Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square.
The mornin... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100).
Note that a single point in the room can conta... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | [
"4\n0 0\n0 1\n0 2\n1 0\n",
"4\n0 0\n0 1\n1 0\n1 1\n",
"4\n1 1\n1 2\n2 3\n3 3\n"
] | [
"2\n",
"2\n",
"3\n"
] | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | 500 | [
{
"input": "4\n0 0\n0 1\n0 2\n1 0",
"output": "2"
},
{
"input": "4\n0 0\n0 1\n1 0\n1 1",
"output": "2"
},
{
"input": "4\n1 1\n1 2\n2 3\n3 3",
"output": "3"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 ... | 1,566,975,259 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 312 | 1,843,200 | n = int(input())
listx = []
listy = []
for i in range(0,n):
a = (input().split())
y = int(a[1])
x = int(a[0])
listx.append(x)
listy.append(y)
setx = set(listx)
sety = set(listy)
mylist = [len(setx),len(sety)]
print(min(mylist)) | Title: Inna and Alarm Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner a... | ```python
n = int(input())
listx = []
listy = []
for i in range(0,n):
a = (input().split())
y = int(a[1])
x = int(a[0])
listx.append(x)
listy.append(y)
setx = set(listx)
sety = set(listy)
mylist = [len(setx),len(sety)]
print(min(mylist))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\n1 1 ... | 1,561,623,483 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 155 | 3,276,800 | from collections import defaultdict
MyDict = defaultdict(list)
input()
X = list(map(int, input().split()))
for i in range(len(X)):
MyDict[X[i]].append(i)
MIN = 10 ** 9
for i in MyDict.keys():
if len(MyDict[i]) > 1:
Temp = sorted(MyDict[i])
MIN = min(min(Temp[j]-Temp[j-1] for j in ran... | Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
I... | ```python
from collections import defaultdict
MyDict = defaultdict(list)
input()
X = list(map(int, input().split()))
for i in range(len(X)):
MyDict[X[i]].append(i)
MIN = 10 ** 9
for i in MyDict.keys():
if len(MyDict[i]) > 1:
Temp = sorted(MyDict[i])
MIN = min(min(Temp[j]-Temp[j-1] fo... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,695,755,465 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
companies = []
for _ in range(n):
data = list(map(int, input().split()))
max_salary = max(data[1:])
companies.append(max_salary)
max_max_salary = max(companies)
total_increase = 0
for salary in companies:
total_increase += max_max_salary - salary
print(total_increase)
... | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
companies = []
for _ in range(n):
data = list(map(int, input().split()))
max_salary = max(data[1:])
companies.append(max_salary)
max_max_salary = max(companies)
total_increase = 0
for salary in companies:
total_increase += max_max_salary - salary
print(total_increase)
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,671,625,697 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | b=int(input())
l=[]
if(b%2==0):
for i in range(0,b,2):
l.append(i+2)
l.append(i+1)
print(*l)
else:
print(-1) | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
b=int(input())
l=[]
if(b%2==0):
for i in range(0,b,2):
l.append(i+2)
l.append(i+1)
print(*l)
else:
print(-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
952 | B | A Map of the Cat | PROGRAMMING | 1,900 | [
"brute force",
"interactive"
] | null | null | If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
You have met a cat. Can you figure out whether it's normal... | none | none | [] | [] | Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer. | 0 | [
{
"input": "5 0 1 2 5 3 5 4 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 5 6 6 7 8 9 10 11",
"output": "Correct answer 'grumpy'"
},
{
"input": "10 6 5 7 5 6 11 5 8 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "7 10 8 9 6 5 5 11 5 6",
"output": "Co... | 1,669,072,828 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import sys
#sys.setrecursionlimit(20000)
#from collections import deque #Counter
#from itertools import accumulate
#from functools import product
#import math
def rl():
return sys.stdin.readline().strip()
def rl_types(types):
str_list = [x for x in sys.stdin.readline().strip().split(' ')]
return [types[i]... | Title: A Map of the Cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from ... | ```python
import sys
#sys.setrecursionlimit(20000)
#from collections import deque #Counter
#from itertools import accumulate
#from functools import product
#import math
def rl():
return sys.stdin.readline().strip()
def rl_types(types):
str_list = [x for x in sys.stdin.readline().strip().split(' ')]
return... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,690,936,113 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | dias = int(input())
dinero = list(map(int,input().split()))
canti_num_ord = 1
j = 1
for i in range(1,dias):
if dinero[i] >= dinero[i-1]:
j += 1
else:
canti_num_ord = j
j = 1
print(max(canti_num_ord,j)) | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
dias = int(input())
dinero = list(map(int,input().split()))
canti_num_ord = 1
j = 1
for i in range(1,dias):
if dinero[i] >= dinero[i-1]:
j += 1
else:
canti_num_ord = j
j = 1
print(max(canti_num_ord,j))
``` | 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,599,796,943 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import math
n,k=map(int,raw_input().split())
l=[]
for j in range(1,(int(math.sqrt(n))+1)):
if n%j==0:
l.append(j)
if n//j !=j:
l.append(n//j)
l.sort()
print l[k-1] if len(l)>=k else -1 | 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
n,k=map(int,raw_input().split())
l=[]
for j in range(1,(int(math.sqrt(n))+1)):
if n%j==0:
l.append(j)
if n//j !=j:
l.append(n//j)
l.sort()
print l[k-1] if len(l)>=k else -1
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,614,527,614 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | t=int(input())
count=0
total=0
x=True
if t==1:
print(1)
else:
for i in range(1,t+1):
count=count+(i*(i+1))//2
total=total+count
print(total) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
t=int(input())
count=0
total=0
x=True
if t==1:
print(1)
else:
for i in range(1,t+1):
count=count+(i*(i+1))//2
total=total+count
print(total)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,619,798,938 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 528 | 307,200 | arr = list(map(int, input().split(" ")))
t = arr[0]
s = [arr[1], arr[2]]
d = [arr[3], arr[4]]
str = input()
y_mov = d[1] - s[1]
x_mov = d[0] - s[0]
directions = []
if(x_mov<0):
directions.append("W")
elif(x_mov>0):
directions.append("E")
elif(x_mov==0):
directions.append(0)
if(y_mo... | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
arr = list(map(int, input().split(" ")))
t = arr[0]
s = [arr[1], arr[2]]
d = [arr[3], arr[4]]
str = input()
y_mov = d[1] - s[1]
x_mov = d[0] - s[0]
directions = []
if(x_mov<0):
directions.append("W")
elif(x_mov>0):
directions.append("E")
elif(x_mov==0):
directions.append(0)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
18 | A | Triangle | PROGRAMMING | 1,500 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t... | The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero. | If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER. | [
"0 0 2 0 0 1\n",
"2 3 4 5 6 6\n",
"-1 0 2 0 0 1\n"
] | [
"RIGHT\n",
"NEITHER\n",
"ALMOST\n"
] | none | 0 | [
{
"input": "0 0 2 0 0 1",
"output": "RIGHT"
},
{
"input": "2 3 4 5 6 6",
"output": "NEITHER"
},
{
"input": "-1 0 2 0 0 1",
"output": "ALMOST"
},
{
"input": "27 74 85 23 100 99",
"output": "NEITHER"
},
{
"input": "-97 -19 17 62 30 -76",
"output": "NEITHER"
},... | 1,602,876,664 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 218 | 307,200 | def dist(x1, y1, x2, y2):
return (x2 - x1) ** 2 + (y2 - y1) ** 2
def right_triangle(x1,y1,x2,y2,x3,y3):
first = dist(x1, y1, x2, y2)
second = dist(x1, y1, x3, y3)
third = dist(x2, y2, x3, y3)
mas1 = [first, second, third]
mas1.sort()
if mas1[0] + mas1[1] == mas1[2] and mas1[0] * ... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer co... | ```python
def dist(x1, y1, x2, y2):
return (x2 - x1) ** 2 + (y2 - y1) ** 2
def right_triangle(x1,y1,x2,y2,x3,y3):
first = dist(x1, y1, x2, y2)
second = dist(x1, y1, x3, y3)
third = dist(x2, y2, x3, y3)
mas1 = [first, second, third]
mas1.sort()
if mas1[0] + mas1[1] == mas1[2] and ... | 3.943211 | MatrixStudio/Codeforces-Python-Submissions |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,699,574,438 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 1,843,200 | n = int(input())
a = []
b = []
i = 0
while i < n:
x = input().split()
a.append(x[0])
b.append(x[-1])
i = i + 1
alex = 1
for i in range(n):
for l in range(1, n):
if a[i] < a[l] and b[i] > b[l]:
alex = alex + 1
if alex >= 2:
print("Happy Alex")
else:
print... | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n = int(input())
a = []
b = []
i = 0
while i < n:
x = input().split()
a.append(x[0])
b.append(x[-1])
i = i + 1
alex = 1
for i in range(n):
for l in range(1, n):
if a[i] < a[l] and b[i] > b[l]:
alex = alex + 1
if alex >= 2:
print("Happy Alex")
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to ... | The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. | Print one integer — the number of minutes Sonya and Filya will be able to spend together. | [
"1 10 9 20 1\n",
"1 100 50 200 75\n"
] | [
"2\n",
"50\n"
] | In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | 500 | [
{
"input": "1 10 9 20 1",
"output": "2"
},
{
"input": "1 100 50 200 75",
"output": "50"
},
{
"input": "6 6 5 8 9",
"output": "1"
},
{
"input": "1 1000000000 1 1000000000 1",
"output": "999999999"
},
{
"input": "5 100 8 8 8",
"output": "0"
},
{
"input":... | 1,516,108,329 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 5,632,000 | l1,r1,l2,r2,k =map(int,input().split())
#between
if l1<=l2 and r2<=r1:
if k in range(l2,r2+1):
print(r2-l2)
else:
print(r2-l2+1)
# outer bahar lower in
elif l1<=l2 and l2<r1 and r2>r1:
if k in range(l2,r1+1):
print(r1-l2)
else:
print(r1-l2+1)
# lower bahar
elif l1>l2 and r2<=r1:
if k in ... | Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi... | ```python
l1,r1,l2,r2,k =map(int,input().split())
#between
if l1<=l2 and r2<=r1:
if k in range(l2,r2+1):
print(r2-l2)
else:
print(r2-l2+1)
# outer bahar lower in
elif l1<=l2 and l2<r1 and r2>r1:
if k in range(l2,r1+1):
print(r1-l2)
else:
print(r1-l2+1)
# lower bahar
elif l1>l2 and r2<=r1:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,573,157,749 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 124 | 0 | n,m=map(int,input().split())
k=input()
s=[]
for i in k:
s.append(i)
for i in range(m):
a,b,c,d=input().split()
for j in range(int(a)-1,int(b)):
if s[j]==c:
s[j]=d
for i in s:
print(i,end='') | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
n,m=map(int,input().split())
k=input()
s=[]
for i in k:
s.append(i)
for i in range(m):
a,b,c,d=input().split()
for j in range(int(a)-1,int(b)):
if s[j]==c:
s[j]=d
for i in s:
print(i,end='')
``` | 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,622,904,954 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 921,600 | n = int(input())
s = "aabb" * n
print(s[:n])
| 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())
s = "aabb" * n
print(s[:n])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,693,662,400 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
ca = 0
ba = 0
for i in range(n):
a,b = list(map(int,input().split()))
if a > b:
ca += 1
elif b > a:
ba += 1
if ca > ba:
print('Mishaka')
elif ba > ca:
print('Chris')
else:
print('Friendship is magic!^^')
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n = int(input())
ca = 0
ba = 0
for i in range(n):
a,b = list(map(int,input().split()))
if a > b:
ca += 1
elif b > a:
ba += 1
if ca > ba:
print('Mishaka')
elif ba > ca:
print('Chris')
else:
print('Friendship is magic!^^')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
464 | E | The Classic Problem | PROGRAMMING | 3,000 | [
"data structures",
"graphs",
"shortest paths"
] | null | null | You are given a weighted undirected graph on *n* vertices and *m* edges. Find the shortest path from vertex *s* to vertex *t* or else state that such path doesn't exist. | The first line of the input contains two space-separated integers — *n* and *m* (1<=≤<=*n*<=≤<=105; 0<=≤<=*m*<=≤<=105).
Next *m* lines contain the description of the graph edges. The *i*-th line contains three space-separated integers — *u**i*, *v**i*, *x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; 0<=≤<=*x**i*<=≤<=105). That... | In the first line print the remainder after dividing the length of the shortest path by 1000000007 (109<=+<=7) if the path exists, and -1 if the path doesn't exist.
If the path exists print in the second line integer *k* — the number of vertices in the shortest path from vertex *s* to vertex *t*; in the third line pri... | [
"4 4\n1 4 2\n1 2 0\n2 3 0\n3 4 0\n1 4\n",
"4 3\n1 2 4\n2 3 5\n3 4 6\n1 4\n",
"4 2\n1 2 0\n3 4 1\n1 4\n"
] | [
"3\n4\n1 2 3 4 \n",
"112\n4\n1 2 3 4 \n",
"-1\n"
] | A path from vertex *s* to vertex *t* is a sequence *v*<sub class="lower-index">0</sub>, ..., *v*<sub class="lower-index">*k*</sub>, such that *v*<sub class="lower-index">0</sub> = *s*, *v*<sub class="lower-index">*k*</sub> = *t*, and for any *i* from 0 to *k* - 1 vertices *v*<sub class="lower-index">*i*</sub> and *v*<s... | 2,500 | [] | 1,684,119,996 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 5,000 | 323,788,800 | # https://codeforces.com/contest/464/problem/E
import heapq
def dijkstra(adj_list, start, target):
n = len(adj_list)
distance = [float('inf')] * n
prev = [-1] * n
distance[start] = 0
heap = [(0, start)]
while heap:
dist, node = heapq.heappop(heap)
if node == targe... | Title: The Classic Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a weighted undirected graph on *n* vertices and *m* edges. Find the shortest path from vertex *s* to vertex *t* or else state that such path doesn't exist.
Input Specification:
The first line of the i... | ```python
# https://codeforces.com/contest/464/problem/E
import heapq
def dijkstra(adj_list, start, target):
n = len(adj_list)
distance = [float('inf')] * n
prev = [-1] * n
distance[start] = 0
heap = [(0, start)]
while heap:
dist, node = heapq.heappop(heap)
if nod... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,591,715,288 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 2,560,000 | def sumOfDigits(n):
lst = list(str(n))
count = 0
for i in lst:
count+=int(i)
return count
n = int(input())
sett = set()
if n==2:
print(1, 1, sep="\n")
else:
for i in range(n, 1, -1):
if (sumOfDigits(i)+i==n):
sett.add(i)
print(len(sett))
for x i... | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
def sumOfDigits(n):
lst = list(str(n))
count = 0
for i in lst:
count+=int(i)
return count
n = int(input())
sett = set()
if n==2:
print(1, 1, sep="\n")
else:
for i in range(n, 1, -1):
if (sumOfDigits(i)+i==n):
sett.add(i)
print(len(sett))
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,564,997,964 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 248 | 0 | n=input()
g=n.lower()
for i in range(len(g)):
if g[-1-i].isalpha():
c=g[-1-i]
break
z=["a","e","i","i","o","u","y"]
if c in z:
print("YES")
else:
print("NO") | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
n=input()
g=n.lower()
for i in range(len(g)):
if g[-1-i].isalpha():
c=g[-1-i]
break
z=["a","e","i","i","o","u","y"]
if c in z:
print("YES")
else:
print("NO")
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,665,139,462 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 1,715 | 19,660,800 | def bsearch(x, lst):
count = 0
l = 0
r = len(lst) - 1
while l <= r:
m = (r + l) // 2
if lst[m] <= x:
count = m + 1
l = m + 1
else:
r = m - 1
return count
n, n1 = map(int, input().split())
lst = list(map(int, input().split()))
lst1 = list(... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
def bsearch(x, lst):
count = 0
l = 0
r = len(lst) - 1
while l <= r:
m = (r + l) // 2
if lst[m] <= x:
count = m + 1
l = m + 1
else:
r = m - 1
return count
n, n1 = map(int, input().split())
lst = list(map(int, input().split()))
ls... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
888 | A | Local Extrema | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=><=*... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*. | Print the number of local extrema in the given array. | [
"3\n1 2 3\n",
"4\n1 5 2 5\n"
] | [
"0\n",
"2\n"
] | none | 0 | [
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "4\n1 5 2 5",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n548",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n3 2 3",
"output": "1"
},
{
"inp... | 1,518,301,758 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 77 | 5,632,000 | n = int(input())
count = 0
a = [int(i) for i in input().split()]
for i in range(1, n - 1):
if a[i] > a[i - 1] and a[i] > a[i + 1] or a[i] < a[i - 1] and a[i] < a[i + 1]:
count += 1
print(count) | Title: Local Extrema
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element c... | ```python
n = int(input())
count = 0
a = [int(i) for i in input().split()]
for i in range(1, n - 1):
if a[i] > a[i - 1] and a[i] > a[i + 1] or a[i] < a[i - 1] and a[i] < a[i + 1]:
count += 1
print(count)
``` | 3 | 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,642,338,231 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n=int(input(""))
a=list(map(int,input("").split()))
t1=0
t2=0
t3=0
for i in range (len(a)):
if i%3==0:
t1+=a[i]
elif i%3==1:
t2+=a[i]
else:
t3+=a[i]
if t1==max(t2,t3,t1):
print("chest")
elif t2==max(t3,t1,t2):
print("biceps")
else:
print("back") | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n=int(input(""))
a=list(map(int,input("").split()))
t1=0
t2=0
t3=0
for i in range (len(a)):
if i%3==0:
t1+=a[i]
elif i%3==1:
t2+=a[i]
else:
t3+=a[i]
if t1==max(t2,t3,t1):
print("chest")
elif t2==max(t3,t1,t2):
print("biceps")
else:
print("back")... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,698,105,673 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # Input
s = input() # Starting position
t = input() # Target position
# Extract row and column numbers for both positions
s_row, s_col = int(s[1]), ord(s[0]) - ord('a') + 1
t_row, t_col = int(t[1]), ord(t[0]) - ord('a') + 1
# Calculate the number of moves in the row and column directions
row_moves = abs(t_... | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
# Input
s = input() # Starting position
t = input() # Target position
# Extract row and column numbers for both positions
s_row, s_col = int(s[1]), ord(s[0]) - ord('a') + 1
t_row, t_col = int(t[1]), ord(t[0]) - ord('a') + 1
# Calculate the number of moves in the row and column directions
row_move... | 0 | MatrixStudio/Codeforces-Python-Submissions |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,514,650,962 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 46 | 5,529,600 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 30 17:12:56 2017
@author: apple
"""
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
b.sort()
if (b[-1]+b[-2])>= sum(a):
print('YES')
else:
prnt('NO') | Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 30 17:12:56 2017
@author: apple
"""
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
b.sort()
if (b[-1]+b[-2])>= sum(a):
print('YES')
else:
prnt('NO')
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
886 | D | Restoration of string | PROGRAMMING | 2,000 | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings in the set.
Each of the next *n* lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct.
The total length of the strings doesn't exceed 105. | Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings. | [
"4\nmail\nai\nlru\ncf\n",
"3\nkek\npreceq\ncheburek\n"
] | [
"cfmailru\n",
"NO\n"
] | One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum. | 2,000 | [
{
"input": "4\nmail\nai\nlru\ncf",
"output": "cfmailru"
},
{
"input": "3\nkek\npreceq\ncheburek",
"output": "NO"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nab\nba",
"output": "NO"
},
{
"input": "2\nac\nbc",
"output": "NO"
},
{
"input": "2\nc... | 1,510,507,649 | 4,949 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 |
n=int(input())
a=[]
b=[]
for i in range(n):
s=input()
b.append(s)
for i in b:
k=i
fl=True
for j in a:
if k in j:
fl=False
if fl:
a.append(k)
if len(a)==n:
print('NO')
else:
b=[True]*len(a)
for i in range(len(a)-1):
for j in ran... | Title: Restoration of string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily fr... | ```python
n=int(input())
a=[]
b=[]
for i in range(n):
s=input()
b.append(s)
for i in b:
k=i
fl=True
for j in a:
if k in j:
fl=False
if fl:
a.append(k)
if len(a)==n:
print('NO')
else:
b=[True]*len(a)
for i in range(len(a)-1):
fo... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
246 | A | Buggy Sorting | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ... | You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. | Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, yo... | [
"1\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "3 2 1 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "5",
"output": "5 4 3 2 1 "
},
{
"input": "6",
"output": "6 5 4 3 2 1 "
},
{
"input... | 1,598,036,313 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 6,758,400 | sz = int(input())
if sz == 1:
print (-1)
else:
print(*reversed(range(sz)), sep=', ') | Title: Buggy Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a*... | ```python
sz = int(input())
if sz == 1:
print (-1)
else:
print(*reversed(range(sz)), sep=', ')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,696,932,585 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | username = input ().lower()
container = []
for dt in username:
if dt not in container:
container .append(dt)
totalchar = len(container)
if totalchar%2 == 0:
print ("CHAT WITH HER!")
else:
print ("IGNORE HIM!")
quit()
| Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
username = input ().lower()
container = []
for dt in username:
if dt not in container:
container .append(dt)
totalchar = len(container)
if totalchar%2 == 0:
print ("CHAT WITH HER!")
else:
print ("IGNORE HIM!")
quit()
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,509,368,447 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 62 | 0 | n, t = map(int, input().split())
a = list(map(int, input().split()))
i = 0
while t>0:
t-=86400-a[i]
i+=1
print(i) | Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n, t = map(int, input().split())
a = list(map(int, input().split()))
i = 0
while t>0:
t-=86400-a[i]
i+=1
print(i)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,688,870,044 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,m,a,b=map(int,input().split())
s=0
if m*a>b:
d=n//m
n-=(m*d)
s+=(b*d)
s+=n*a
print(s) | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
n,m,a,b=map(int,input().split())
s=0
if m*a>b:
d=n//m
n-=(m*d)
s+=(b*d)
s+=n*a
print(s)
``` | 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,548,531,878 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 186 | 0 | s_1=list(str(input()))
s_2=list(str(input()))
k=len(s_2)
if len(s_1)!=len(s_1):
print('NO')
exit()
if len(s_1)==len(s_2):
for i in range (len(s_1)):
if s_1[i]!=s_2[k-1]:
print('NO')
exit()
k-=1
print('YES')
| 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_1=list(str(input()))
s_2=list(str(input()))
k=len(s_2)
if len(s_1)!=len(s_1):
print('NO')
exit()
if len(s_1)==len(s_2):
for i in range (len(s_1)):
if s_1[i]!=s_2[k-1]:
print('NO')
exit()
k-=1
print('YES')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
639 | B | Bear and Forgotten Tree 3 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"graphs",
"trees"
] | null | null | A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell... | The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively. | If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).
Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. Y... | [
"5 3 2\n",
"8 5 2\n",
"8 4 2\n"
] | [
"1 2\n1 3\n3 4\n3 5",
"-1\n",
"4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n"
] | Below you can see trees printed to the output in the first sample and the third sample. | 750 | [
{
"input": "5 3 2",
"output": "1 2\n2 3\n1 4\n5 1"
},
{
"input": "8 5 2",
"output": "-1"
},
{
"input": "8 4 2",
"output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5"
},
{
"input": "2 1 1",
"output": "1 2"
},
{
"input": "10 3 3",
"output": "1 2\n2 3\n3 4\n5 2\n6 2\n7 2... | 1,584,937,083 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 234 | 2,150,400 | from __future__ import print_function
import sys
from collections import *
from heapq import *
from functools import *
import re
from itertools import *
INF=float("inf")
NINF=float("-inf")
try:
input=raw_input
except:
pass
def read_string():
return input()
def read_string_line():
return [x for x in ... | Title: Bear and Forgotten Tree 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a t... | ```python
from __future__ import print_function
import sys
from collections import *
from heapq import *
from functools import *
import re
from itertools import *
INF=float("inf")
NINF=float("-inf")
try:
input=raw_input
except:
pass
def read_string():
return input()
def read_string_line():
return [x... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
631 | C | Report | PROGRAMMING | 1,700 | [
"data structures",
"sortings"
] | null | null | Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of commodities in the report and the number of managers, respectively.
The second line contains *n* integers *a**i* (|*a**i*|<=≤<=109) — the initial report before it gets to the first manager.
Then follow *m* lin... | Print *n* integers — the final report, which will be passed to Blake by manager number *m*. | [
"3 1\n1 2 3\n2 2\n",
"4 2\n1 2 4 3\n2 3\n1 2\n"
] | [
"2 1 3 ",
"2 4 1 3 "
] | In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.
In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the r... | 1,500 | [
{
"input": "3 1\n1 2 3\n2 2",
"output": "2 1 3 "
},
{
"input": "4 2\n1 2 4 3\n2 3\n1 2",
"output": "2 4 1 3 "
},
{
"input": "4 1\n4 3 2 1\n1 4",
"output": "1 2 3 4 "
},
{
"input": "5 1\n1 2 3 4 5\n2 5",
"output": "5 4 3 2 1 "
},
{
"input": "6 2\n3 1 2 6 4 5\n1 6\n... | 1,615,205,057 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 1,996 | 40,960,000 | from sys import stdin,stdout
nmbr = lambda: int(input())
lst = lambda: list(map(int, input().split()))
for _ in range(1):#nmbr():
n,m=lst()
a=lst()
l=[lst() for _ in range(m)]
suf=[0]*(1+m)
suf[m-1]=l[m-1][1]
for i in range(m-2,-1,-1):
suf[i]=max(suf[i+1],l[i][1])
# ans=a.... | Title: Report
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that... | ```python
from sys import stdin,stdout
nmbr = lambda: int(input())
lst = lambda: list(map(int, input().split()))
for _ in range(1):#nmbr():
n,m=lst()
a=lst()
l=[lst() for _ in range(m)]
suf=[0]*(1+m)
suf[m-1]=l[m-1][1]
for i in range(m-2,-1,-1):
suf[i]=max(suf[i+1],l[i][1])
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
741 | B | Arpa's weak amphitheater and Mehrdad's valuable Hoses | PROGRAMMING | 1,600 | [
"dfs and similar",
"dp",
"dsu"
] | null | null | Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses *x* and *y* are in the same friendship group if... | The first line contains integers *n*, *m* and *w* (1<=<=≤<=<=*n*<=<=≤<=<=1000, , 1<=≤<=*w*<=≤<=1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=1000) — the weights of the ... | Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed *w*. | [
"3 1 5\n3 2 5\n2 4 2\n1 2\n",
"4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n"
] | [
"6\n",
"7\n"
] | In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hose... | 1,000 | [
{
"input": "3 1 5\n3 2 5\n2 4 2\n1 2",
"output": "6"
},
{
"input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3",
"output": "7"
},
{
"input": "10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\n1 7\n2 4\n3 6\n5 7\n1 5",
"output": "238... | 1,548,635,813 | 2,147,483,647 | PyPy 3 | OK | TESTS | 68 | 904 | 8,601,600 | R = lambda: map(int, input().split())
n, m, w = R()
ws = [0] + list(R())
bs = [0] + list(R())
g = [[] for x in range(n + 1)]
for i in range(m):
x, y = R()
g[x].append(y)
g[y].append(x)
cs = [0] * (n + 1)
cnt = 1
for i in range(1, n + 1):
if not cs[i]:
cs[i] = cnt
q = []
... | Title: Arpa's weak amphitheater and Mehrdad's valuable Hoses
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. ... | ```python
R = lambda: map(int, input().split())
n, m, w = R()
ws = [0] + list(R())
bs = [0] + list(R())
g = [[] for x in range(n + 1)]
for i in range(m):
x, y = R()
g[x].append(y)
g[y].append(x)
cs = [0] * (n + 1)
cnt = 1
for i in range(1, n + 1):
if not cs[i]:
cs[i] = cnt
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,592,636,587 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 216 | 0 | # https://codeforces.com/problemset/problem/32/B
"""
Ternary notation in Berland is as follows:
* . is 0
* -. is 1
* -- is 3
"""
import sys
t_number = sys.stdin.readline().strip()
n = len(t_number)
number = ''
flag = 0
for i in range(n):
# Character has already been considered so sk... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
# https://codeforces.com/problemset/problem/32/B
"""
Ternary notation in Berland is as follows:
* . is 0
* -. is 1
* -- is 3
"""
import sys
t_number = sys.stdin.readline().strip()
n = len(t_number)
number = ''
flag = 0
for i in range(n):
# Character has already been consid... | 3.946 | MatrixStudio/Codeforces-Python-Submissions |
58 | B | Coins | PROGRAMMING | 1,300 | [
"greedy"
] | B. Coins | 2 | 256 | In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d... | The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin. | Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coin... | [
"10\n",
"4\n",
"3\n"
] | [
"10 5 1\n",
"4 2 1\n",
"3 1\n"
] | none | 1,000 | [
{
"input": "10",
"output": "10 5 1"
},
{
"input": "4",
"output": "4 2 1"
},
{
"input": "3",
"output": "3 1"
},
{
"input": "2",
"output": "2 1"
},
{
"input": "5",
"output": "5 1"
},
{
"input": "6",
"output": "6 3 1"
},
{
"input": "7",
"o... | 1,652,094,107 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 1,843,200 | def coins():
a=int(input())
c=[]
for i in range(a,0,-1):
if a%i==0:
c.append(i)
a=i
print(*c)
coins() | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following... | ```python
def coins():
a=int(input())
c=[]
for i in range(a,0,-1):
if a%i==0:
c.append(i)
a=i
print(*c)
coins()
``` | 3.965567 | MatrixStudio/Codeforces-Python-Submissions |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,488,428,877 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #---------------EL FUTURO ES INCIERTO--------------#
arr = ["012","102","120","210","201","021"]
n = int(input())
m = int(input())
n = n%len(arr)
print arr[n][m] | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
#---------------EL FUTURO ES INCIERTO--------------#
arr = ["012","102","120","210","201","021"]
n = int(input())
m = int(input())
n = n%len(arr)
print arr[n][m]
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,451,488,367 | 467 | Python 3 | OK | TESTS | 38 | 62 | 512,000 | import datetime
a, b, c = input().split()
a = int(a)
ans = 0
for i in range(1, 13):
for s in range(1, 32):
try:
x = datetime.datetime(2016, i, s)
if c == 'week' and x.weekday() == a - 1:
ans += 1
if c == 'month' and s == a:
ans... | Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
import datetime
a, b, c = input().split()
a = int(a)
ans = 0
for i in range(1, 13):
for s in range(1, 32):
try:
x = datetime.datetime(2016, i, s)
if c == 'week' and x.weekday() == a - 1:
ans += 1
if c == 'month' and s == a:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
760 | B | Frodo and pillows | PROGRAMMING | 1,500 | [
"binary search",
"greedy"
] | null | null | *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge... | The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. | Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n"
] | [
"2\n",
"4\n",
"3\n"
] | In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third exa... | 1,000 | [
{
"input": "4 6 2",
"output": "2"
},
{
"input": "3 10 3",
"output": "4"
},
{
"input": "3 6 1",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000 1",
"output": "1000000000"
},
{
... | 1,497,291,787 | 4,387 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | hobbits_nr, pillows_nr, frodos_place = (int(x) for x in input().split())
pillows_nr = pillows_nr - hobbits_nr
frodos_pillows = 1
# [left, right) -- it's a half-interval
left = frodos_place
right = frodos_place + 1
while pillows_nr >= right - left:
pillows_nr -= right - left
frodos_pillows += 1
... | Title: Frodo and pillows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma... | ```python
hobbits_nr, pillows_nr, frodos_place = (int(x) for x in input().split())
pillows_nr = pillows_nr - hobbits_nr
frodos_pillows = 1
# [left, right) -- it's a half-interval
left = frodos_place
right = frodos_place + 1
while pillows_nr >= right - left:
pillows_nr -= right - left
frodos_pillow... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to ... | The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. | Print one integer — the number of minutes Sonya and Filya will be able to spend together. | [
"1 10 9 20 1\n",
"1 100 50 200 75\n"
] | [
"2\n",
"50\n"
] | In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | 500 | [
{
"input": "1 10 9 20 1",
"output": "2"
},
{
"input": "1 100 50 200 75",
"output": "50"
},
{
"input": "6 6 5 8 9",
"output": "1"
},
{
"input": "1 1000000000 1 1000000000 1",
"output": "999999999"
},
{
"input": "5 100 8 8 8",
"output": "0"
},
{
"input":... | 1,634,958,598 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 46 | 17,715,200 | a,b,aa,bb,c = map(int,input().split())
a,b = max(a,aa),min(b,bb)
if a < b:
num = b - a + 1
print(num - 1 if a <= c <= b else num)
else:
print(0) | Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi... | ```python
a,b,aa,bb,c = map(int,input().split())
a,b = max(a,aa),min(b,bb)
if a < b:
num = b - a + 1
print(num - 1 if a <= c <= b else num)
else:
print(0)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
526 | A | King of Thieves | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
An interesting feature of the game is that you can design your own levels that wil... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of segments on the level.
Next line contains the scheme of the level represented as a string of *n* characters '*' and '.'. | If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes). | [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n"
] | [
"yes",
"no"
] | In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14. | 500 | [
{
"input": "16\n.**.*..*.***.**.",
"output": "yes"
},
{
"input": "11\n.*.*...*.*.",
"output": "no"
},
{
"input": "53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.",
"output": "yes"
},
{
"input": "71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.*... | 1,428,322,989 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 61 | 0 | n = int(input())
s = input()
f = False
for i in range(n // 4):
if s[i] == '*':
for j in range(1, n//4):
if s[i] == s[i+j] == s[i+2*j] == s[i+3*j]:
f = True
break
if f:
print('yes')
else:
print('no') | Title: King of Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obsta... | ```python
n = int(input())
s = input()
f = False
for i in range(n // 4):
if s[i] == '*':
for j in range(1, n//4):
if s[i] == s[i+j] == s[i+2*j] == s[i+3*j]:
f = True
break
if f:
print('yes')
else:
print('no')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,692,172,735 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | a,b,c=map(int,input().split())
v=int(str(a)+str(0))
s=v + b-v%b
print(str(s)+ "0"*(c-1)) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a,b,c=map(int,input().split())
v=int(str(a)+str(0))
s=v + b-v%b
print(str(s)+ "0"*(c-1))
``` | 0 | 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,669,499,423 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 1,843,200 | n, t = list(map(int,input().split()))
p = [n]
numbers = [0]*n
p = list(map(int, input().split()))
for i in range(len(p)):
if i == 0:
numbers[0] = 1 + p[0]
elif i == (numbers[i-1]-1):
numbers[i] = numbers[i-1] + p[i]
if t in numbers:
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, t = list(map(int,input().split()))
p = [n]
numbers = [0]*n
p = list(map(int, input().split()))
for i in range(len(p)):
if i == 0:
numbers[0] = 1 + p[0]
elif i == (numbers[i-1]-1):
numbers[i] = numbers[i-1] + p[i]
if t in numbers:
print('YES')
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,650,826,157 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 1 | 77 | 2,150,400 | import math as m
n=int(input())
if(n==1):
print(1)
else:
print(m.comb(2*(n-1),n-1)) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
import math as m
n=int(input())
if(n==1):
print(1)
else:
print(m.comb(2*(n-1),n-1))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,596,991,180 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 7,270,400 | n = int(input())
c=[]
for i in range (n):
a,b=map(str,input().split())
c.append(a+b)
n = [c.count(c[i]) for i in range(len(c))]
print(max(n)) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
c=[]
for i in range (n):
a,b=map(str,input().split())
c.append(a+b)
n = [c.count(c[i]) for i in range(len(c))]
print(max(n))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage... | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\n... | 1,664,812,959 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | matrix = []
for x in range(3):
a = input()
matrix.append(a)
result = 0
for x in range(3):
for y in range(3):
if matrix[x][y] == matrix[2-x][2-y]:
result += 1
if result == 9:
print("YES")
else:
print("NO") | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin... | ```python
matrix = []
for x in range(3):
a = input()
matrix.append(a)
result = 0
for x in range(3):
for y in range(3):
if matrix[x][y] == matrix[2-x][2-y]:
result += 1
if result == 9:
print("YES")
else:
print("NO")
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,643,251,702 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a, b = map(int, input().split())
ctr = a
while a > 0:
a = int(a / b)
ctr += a
print(ctr) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
a, b = map(int, input().split())
ctr = a
while a > 0:
a = int(a / b)
ctr += a
print(ctr)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
792 | D | Paths in a Complete Binary Tree | PROGRAMMING | 1,900 | [
"bitmasks",
"trees"
] | null | null | *T* is a complete binary tree consisting of *n* vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So *n* is a number such t... | The first line contains two integer numbers *n* and *q* (1<=≤<=*n*<=≤<=1018, *q*<=≥<=1). *n* is such that *n*<=+<=1 is a power of 2.
The next 2*q* lines represent queries; each query consists of two consecutive lines. The first of these two lines contains *u**i* (1<=≤<=*u**i*<=≤<=*n*), the second contains non-empty st... | Print *q* numbers, *i*-th number must be the answer to the *i*-th query. | [
"15 2\n4\nUURL\n8\nLRLLLLLLLL\n"
] | [
"10\n5\n"
] | none | 0 | [
{
"input": "15 2\n4\nUURL\n8\nLRLLLLLLLL",
"output": "10\n5"
},
{
"input": "1 1\n1\nL",
"output": "1"
},
{
"input": "1 1\n1\nR",
"output": "1"
},
{
"input": "1 1\n1\nU",
"output": "1"
},
{
"input": "1 10\n1\nURLRLULUR\n1\nLRRRURULULL\n1\nLURURRUUUU\n1\nRRULLLRRUL\... | 1,593,684,456 | 2,147,483,647 | PyPy 3 | OK | TESTS | 17 | 2,510 | 11,264,000 | def l(a):
b=bin(a)[2:]
b="0"*(e-len(b))+b
d=len(b)
for i in range(d-1,-1,-1):
if b[i]=="1":
c=d-1-i
break
if c==0:
return -1
return (a-2**(c-1))
def r(a):
b=bin(a)[2:]
b="0"*(e-len(b))+b
d=len(b)
for i in range(d-1,-1,-1):
... | Title: Paths in a Complete Binary Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*T* is a complete binary tree consisting of *n* vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two ch... | ```python
def l(a):
b=bin(a)[2:]
b="0"*(e-len(b))+b
d=len(b)
for i in range(d-1,-1,-1):
if b[i]=="1":
c=d-1-i
break
if c==0:
return -1
return (a-2**(c-1))
def r(a):
b=bin(a)[2:]
b="0"*(e-len(b))+b
d=len(b)
for i in range(d-... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,601,948,959 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 307,200 | def output(x:str,y:str)->None:
sections = int(x) # takes the number of sections
heights=[int(i) for i in y.split(' ')] # takes the heights of the sections
scores=[] # create list of amount of watered sections for each section watering
for i in range(sections): # loops on all the sections to create t... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
def output(x:str,y:str)->None:
sections = int(x) # takes the number of sections
heights=[int(i) for i in y.split(' ')] # takes the heights of the sections
scores=[] # create list of amount of watered sections for each section watering
for i in range(sections): # loops on all the sections t... | -1 | MatrixStudio/Codeforces-Python-Submissions |
552 | A | Vanya and Table | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of rectangles.
Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1<=≤<=*x*2<=≤<=100, 1<=≤<=*y*1<=≤<=*y*2<=≤<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *... | In a single line print the sum of all values in the cells of the table. | [
"2\n1 1 2 3\n2 2 3 3\n",
"2\n1 1 3 3\n1 1 3 3\n"
] | [
"10\n",
"18\n"
] | Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110
So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will ... | 500 | [
{
"input": "2\n1 1 2 3\n2 2 3 3",
"output": "10"
},
{
"input": "2\n1 1 3 3\n1 1 3 3",
"output": "18"
},
{
"input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13",
"output": "510"
},
{
"input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11",
"o... | 1,483,994,656 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 327 | 4,710,400 | g=[0]*105*105
n=int(input())
for k in range(n):
x1,y1,x2,y2=map(int,input().split())
for i in range(y1,y2+1):
for j in range(x1,x2+1):
g[i*105+j]+=1
print(sum(g)) | Title: Vanya and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vany... | ```python
g=[0]*105*105
n=int(input())
for k in range(n):
x1,y1,x2,y2=map(int,input().split())
for i in range(y1,y2+1):
for j in range(x1,x2+1):
g[i*105+j]+=1
print(sum(g))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,596,497,071 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 6,963,200 | m = list(map(int , input().split()))
n = m[0]
x = m[1]
d = 0
r = []
for i in range(n):
h = input().split()
if h[0] == "+":
x += int(h[1])
elif h[0] == "-":
if x >= int(h[1]):
x -= int(h[1])
else:
d += 1
print(x , d) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
m = list(map(int , input().split()))
n = m[0]
x = m[1]
d = 0
r = []
for i in range(n):
h = input().split()
if h[0] == "+":
x += int(h[1])
elif h[0] == "-":
if x >= int(h[1]):
x -= int(h[1])
else:
d += 1
print(x , d)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,440,816,372 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 102,400 | n = int(input())
print(n,end = ' ')
for i in range (1,n):
print(i,end =' ') | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
n = int(input())
print(n,end = ' ')
for i in range (1,n):
print(i,end =' ')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
732 | D | Exams | PROGRAMMING | 1,700 | [
"binary search",
"greedy",
"sortings"
] | null | null | Vasiliy has an exam period which will continue for *n* days. He has to pass exams on *m* subjects. Subjects are numbered from 1 to *m*.
About every day we know exam for which one of *m* subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any da... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of days in the exam period and the number of subjects.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (0<=≤<=*d**i*<=≤<=*m*), where *d**i* is the number of subject, the exam of which can be passed on the day numb... | Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. | [
"7 2\n0 1 0 2 1 0 2\n2 1\n",
"10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4\n",
"5 1\n1 1 1 1 1\n5\n"
] | [
"5\n",
"9\n",
"-1\n"
] | In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day.
In the second example Vasiliy should prepare for the exam number 3 during the first four d... | 2,000 | [
{
"input": "7 2\n0 1 0 2 1 0 2\n2 1",
"output": "5"
},
{
"input": "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4",
"output": "9"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "-1"
},
{
"input": "100 10\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 ... | 1,691,940,626 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 296 | 24,678,400 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
alph = 'abcdefghijklmnopqrstuvwxyz'
#pow(x,mod-2,mod)
def find(days):
C = B[:... | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy has an exam period which will continue for *n* days. He has to pass exams on *m* subjects. Subjects are numbered from 1 to *m*.
About every day we know exam for which one of *m* subjects can be passed on that day. Perhap... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
alph = 'abcdefghijklmnopqrstuvwxyz'
#pow(x,mod-2,mod)
def find(days):
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,519,284,558 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 61 | 5,632,000 | a, b = input().split()
a, b = int(a), int(b)
p1 = [int(x) for x in input().split()]
p2 = [int(x) for x in input().split()]
p1.remove(max(p1))
m = max(p2) * max(p1)
mn = min(p1) * min(p2)
if (m > mn):
print(m)
else:
print(mn) | Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
a, b = input().split()
a, b = int(a), int(b)
p1 = [int(x) for x in input().split()]
p2 = [int(x) for x in input().split()]
p1.remove(max(p1))
m = max(p2) * max(p1)
mn = min(p1) * min(p2)
if (m > mn):
print(m)
else:
print(mn)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 ... | 1,613,925,941 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 186 | 1,433,600 | from math import sqrt
n,k=list(map(int,input().split()))
a=[]
for i in range(1,n+1):
z=0
for j in range(2,int(sqrt(i))+1):
if i%j==0:
z=1
break
if z==0:
a.append(i)
b=0
d=[]
for i in a:
if i!=1:
for j in range(len(a)-1):
c=a[j]+... | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob... | ```python
from math import sqrt
n,k=list(map(int,input().split()))
a=[]
for i in range(1,n+1):
z=0
for j in range(2,int(sqrt(i))+1):
if i%j==0:
z=1
break
if z==0:
a.append(i)
b=0
d=[]
for i in a:
if i!=1:
for j in range(len(a)-1):
... | 3.942819 | 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,564,399,757 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 186 | 8,294,400 | from sys import stdin,stdout
input = stdin.readline
print = stdout.write
s = list(input())
s.pop()
for i in range(1, len(s)):
if s[i] == s[i-1] and i != len(s)-1:
if s[i-1] != 'a' and s[i+1] != 'a':
s[i] = 'a'
elif s[i-1] != 'b' and s[i+1] != 'b':
s[i] = 'b'
... | 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
from sys import stdin,stdout
input = stdin.readline
print = stdout.write
s = list(input())
s.pop()
for i in range(1, len(s)):
if s[i] == s[i-1] and i != len(s)-1:
if s[i-1] != 'a' and s[i+1] != 'a':
s[i] = 'a'
elif s[i-1] != 'b' and s[i+1] != 'b':
s[i] = '... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
12 | D | Ball | PROGRAMMING | 2,400 | [
"data structures",
"sortings"
] | D. Ball | 2 | 256 | *N* ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can ... | The first line contains one integer *N* (1<=≤<=*N*<=≤<=500000). The second line contains *N* integer numbers *B**i*, separated by single spaces. The third and the fourth lines contain sequences *I**i* and *R**i* in the same format. It is guaranteed that 0<=≤<=*B**i*,<=*I**i*,<=*R**i*<=≤<=109. | Output the answer to the problem. | [
"3\n1 4 2\n4 3 2\n2 5 3\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "3\n1 4 2\n4 3 2\n2 5 3",
"output": "1"
},
{
"input": "5\n2 8 10 0 7\n7 7 3 0 10\n2 8 3 2 2",
"output": "1"
},
{
"input": "5\n3 0 0 2 0\n7 10 7 4 0\n9 1 6 1 9",
"output": "1"
},
{
"input": "5\n5 4 0 2 5\n8 3 1 0 10\n4 5 0 0 5",
"output": "2"
},
{
"input... | 1,630,155,657 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 6,963,200 | N= int(input())
A=[]
A.append(input().split())
A.append(input().split())
A.append(input().split())
count=0
for m in range(N):
for n in range(N):
if (m != n):
if ((A[0][m]< A[0][n]) and (A[1][m]< A[1][n]) and (A[2][m]< A[2][n]) ):
count +=1
break
print(count) | Title: Ball
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*N* ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that th... | ```python
N= int(input())
A=[]
A.append(input().split())
A.append(input().split())
A.append(input().split())
count=0
for m in range(N):
for n in range(N):
if (m != n):
if ((A[0][m]< A[0][n]) and (A[1][m]< A[1][n]) and (A[2][m]< A[2][n]) ):
count +=1
break
print(count)
``` | 0 | 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,667,544,754 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 2,764,800 | x = int(input(), 2)
y = int(input(), 2)
n = len(x)
z = bin(x^y)[2:]
if n - z > 0:
z = ("0"*(n-z)) + z
print(z) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
x = int(input(), 2)
y = int(input(), 2)
n = len(x)
z = bin(x^y)[2:]
if n - z > 0:
z = ("0"*(n-z)) + z
print(z)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,642,480,959 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | def get_median(s):
n=len(s)
mi=n//2
if n%2==0:
mi=mi-1
#print(s[mi])
return (mi,s[mi])
else:
#print(s[mi])
return (mi,s[mi])
l=int(input())
s=input()
n=len(s)
res=""
i=2
while i:
res=""
while n:
temp=get_median(s)
... | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
def get_median(s):
n=len(s)
mi=n//2
if n%2==0:
mi=mi-1
#print(s[mi])
return (mi,s[mi])
else:
#print(s[mi])
return (mi,s[mi])
l=int(input())
s=input()
n=len(s)
res=""
i=2
while i:
res=""
while n:
temp=get_medi... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,584,697,632 | 252 | Python 3 | OK | TESTS | 38 | 109 | 307,200 | ans=0
t="0123456789"
vo="aeiou"
s=input()
for i in s:
if i not in t:
if i in vo:
ans+=1
else:
if i in "13579":
ans+=1
print(ans)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
ans=0
t="0123456789"
vo="aeiou"
s=input()
for i in s:
if i not in t:
if i in vo:
ans+=1
else:
if i in "13579":
ans+=1
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,587,503,361 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 56 | 216 | 307,200 | # =============================
# Problem - 37A : Towers
# Python3
# Author - wdaubry
# =============================
'''
For each figure, what change from the different ways to
cover the figure depends on the position of the vertical
diamond, there can only be one. So answer is n.
'''
def main(... | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
# =============================
# Problem - 37A : Towers
# Python3
# Author - wdaubry
# =============================
'''
For each figure, what change from the different ways to
cover the figure depends on the position of the vertical
diamond, there can only be one. So answer is n.
'''
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,660,653,008 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | a = int(input())
j = [input() for i in range(a)]
x = j[0]
for i in j:
if j.count(i) > j.count(x):
x = i
print(x)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
a = int(input())
j = [input() for i in range(a)]
x = j[0]
for i in j:
if j.count(i) > j.count(x):
x = i
print(x)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
103 | B | Cthulhu | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | B. Cthulhu | 2 | 256 | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=).
Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). Fo... | Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is. | [
"6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n",
"6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n"
] | [
"FHTAGN!",
"NO"
] | Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1.
A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* > 0).
A rooted tree is a tree where one ve... | 1,000 | [
{
"input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4",
"output": "FHTAGN!"
},
{
"input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2",
"output": "NO"
},
{
"input": "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8",
"output": "FHTAGN!"
},
{
"input": "5 4\n1 5\n1 3\n1 4\n3 2",
"outpu... | 1,539,195,792 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 248 | 0 | n,m=map(int,input().split())
g=[[]for _ in range(n)]
for _ in range(m):
a,b=map(int,input().split())
g[a-1].append(b-1)
g[b-1].append(a-1)
v=[-1]*n
c=[-1,-1]
r=0
def dfs(x,p):
v[x]=p
global r,c
r+=1
for j in g[x]:
if v[j]==-1:
dfs(j,x)
elif v[x]!... | Title: Cthulhu
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively colle... | ```python
n,m=map(int,input().split())
g=[[]for _ in range(n)]
for _ in range(m):
a,b=map(int,input().split())
g[a-1].append(b-1)
g[b-1].append(a-1)
v=[-1]*n
c=[-1,-1]
r=0
def dfs(x,p):
v[x]=p
global r,c
r+=1
for j in g[x]:
if v[j]==-1:
dfs(j,x)
... | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,691,576,534 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | FILE = False
if FILE:
with open('input.txt', 'r') as file:
lines = file.readlines()
word = lines[0].split(' ')
word = word[0]
else:
line = input()
word = line.split(' ')
word = word[0]
word_c = []
for letter in word:
word_c.append(letter)
status = True
for x in 'hello':
if stat... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
FILE = False
if FILE:
with open('input.txt', 'r') as file:
lines = file.readlines()
word = lines[0].split(' ')
word = word[0]
else:
line = input()
word = line.split(' ')
word = word[0]
word_c = []
for letter in word:
word_c.append(letter)
status = True
for x in 'hello':... | 0 | MatrixStudio/Codeforces-Python-Submissions |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,623,141,818 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 310 | 0 | s,t=input(),input()
l,m=0,0
while m<len(t):
if s[l]==t[m]:
l+=1
m+=1
print(l+1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s,t=input(),input()
l,m=0,0
while m<len(t):
if s[l]==t[m]:
l+=1
m+=1
print(l+1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,660,997,189 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 248 | 1,740,800 | import math
from multiprocessing.dummy import Array
# from re import S
t,sx,sy,a,b=map(int,input().split())
# t=True
# for i in range(int(input())):
# n=int(input())
# arr=list(map(int,input().split()))
# n,m=map(int,input().split())
s=input()
# cnt=0
for i in range(t):
if(s[i]=='N' and b>sy):
... | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
import math
from multiprocessing.dummy import Array
# from re import S
t,sx,sy,a,b=map(int,input().split())
# t=True
# for i in range(int(input())):
# n=int(input())
# arr=list(map(int,input().split()))
# n,m=map(int,input().split())
s=input()
# cnt=0
for i in range(t):
if(s[i]=='N' an... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,685,360,239 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 404 | 0 |
def e(n, a):
m = 1
for i in range(n):
mn = 1
while a[i] != -1:
i = a[i] - 1
mn += 1
m = max(mn, m)
print(m)
if __name__ == '__main__':
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
d = e(n, a) | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
def e(n, a):
m = 1
for i in range(n):
mn = 1
while a[i] != -1:
i = a[i] - 1
mn += 1
m = max(mn, m)
print(m)
if __name__ == '__main__':
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
d =... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,648,897,357 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 140 | 9,523,200 | import math
n,k=map(int,input().split())
ar=list(map(int,input().split()))
s=0
for x in range(n):
s+=math.ceil(ar[x]/k)
print(math.ceil(s/2)) | Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
import math
n,k=map(int,input().split())
ar=list(map(int,input().split()))
s=0
for x in range(n):
s+=math.ceil(ar[x]/k)
print(math.ceil(s/2))
``` | 3 | 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,689,277 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,k=map(int,input().split())
i=1
divc=0
while divc<k:
if n>i:
if n%i ==0:
divc+=1
div=i
else:
div=-1
break
i+=1
print(div)
| 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
n,k=map(int,input().split())
i=1
divc=0
while divc<k:
if n>i:
if n%i ==0:
divc+=1
div=i
else:
div=-1
break
i+=1
print(div)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
36 | A | Extra-terrestrial Intelligence | PROGRAMMING | 1,300 | [
"implementation"
] | A. Extra-terrestrial Intelligence | 2 | 64 | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | [
"8\n00111000\n",
"7\n1001011\n",
"7\n1010100\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "8\n00111000",
"output": "YES"
},
{
"input": "7\n1001011",
"output": "NO"
},
{
"input": "7\n1010100",
"output": "YES"
},
{
"input": "5\n10101",
"output": "YES"
},
{
"input": "3\n111",
"output": "YES"
},
{
"input": "10\n0011111011",
"outp... | 1,522,072,617 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 7,065,600 | n = int(input())
s = input()
c = []
a = []
for i in range(len(s)):
if(s[i]=="1"):
c.append(i)
for i in range(1,len(c)):
a.append(abs(c[i]-c[i-1]))
b = set(a)
print(c,a,b)
if(len(b)==1):
print("YES")
else:
print("NO") | Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* da... | ```python
n = int(input())
s = input()
c = []
a = []
for i in range(len(s)):
if(s[i]=="1"):
c.append(i)
for i in range(1,len(c)):
a.append(abs(c[i]-c[i-1]))
b = set(a)
print(c,a,b)
if(len(b)==1):
print("YES")
else:
print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
91 | B | Queue | PROGRAMMING | 1,500 | [
"binary search",
"data structures"
] | B. Queue | 2 | 256 | There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*.
The *i*-th walrus becomes displeased if there's a younger... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of walruses in the queue. The second line contains integers *a**i* (1<=≤<=*a**i*<=≤<=109).
Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly youn... | Print *n* numbers: if the *i*-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the *i*-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | [
"6\n10 8 5 3 50 45\n",
"7\n10 4 6 3 2 8 15\n",
"5\n10 3 1 10 11\n"
] | [
"2 1 0 -1 0 -1 ",
"4 2 1 0 -1 -1 -1 ",
"1 0 -1 -1 -1 "
] | none | 1,000 | [
{
"input": "6\n10 8 5 3 50 45",
"output": "2 1 0 -1 0 -1 "
},
{
"input": "7\n10 4 6 3 2 8 15",
"output": "4 2 1 0 -1 -1 -1 "
},
{
"input": "5\n10 3 1 10 11",
"output": "1 0 -1 -1 -1 "
},
{
"input": "13\n18 9 8 9 23 20 18 18 33 25 31 37 36",
"output": "2 0 -1 -1 2 1 -1 -1 ... | 1,635,411,368 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 124 | 28,979,200 | # n, m = map(int, input().split())
# a = []
# for i in range(n):
# a.append(list(map(int, input().split())))
# q = int(input())
# for i in range(q):
# s = 0
# x1, y1, x2, y2 = map(int, input().split())
# if (x2 < x1 and y2 < y1):
# x1, x2 = x2, x1
# y1, y2 = y2, y1
# elif ... | Title: Queue
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus ... | ```python
# n, m = map(int, input().split())
# a = []
# for i in range(n):
# a.append(list(map(int, input().split())))
# q = int(input())
# for i in range(q):
# s = 0
# x1, y1, x2, y2 = map(int, input().split())
# if (x2 < x1 and y2 < y1):
# x1, x2 = x2, x1
# y1, y2 = y2, y1
#... | 0 | MatrixStudio/Codeforces-Python-Submissions |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,680,944,632 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 61 | 2,355,200 | s=input()
t=input()
c=0
s1=len(s)-1
t1=len(t)-1
while(s1>=0 and t1>=0):
if(s[s1]!=t[t1]):
break
c+=1
s1-=1
t1-=1
print(len(s)+len(t)-2*c) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s=input()
t=input()
c=0
s1=len(s)-1
t1=len(t)-1
while(s1>=0 and t1>=0):
if(s[s1]!=t[t1]):
break
c+=1
s1-=1
t1-=1
print(len(s)+len(t)-2*c)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,621,633,763 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 0 | n = int(input())
c = 0
while n > 9:
n = sum([int(str(n)[i]) for i in range(len(str(n)))])
c += 1
print(c)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
n = int(input())
c = 0
while n > 9:
n = sum([int(str(n)[i]) for i in range(len(str(n)))])
c += 1
print(c)
``` | 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.