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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | none | none | none | 0 | [
"none"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | 0 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 ... | 1,510,713,947 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 171 | 13,926,400 | n = int(input())
a = [0] + list(map(int, input().split()))
vis = [False] * len(a)
ans = 1
for x in a[1:]:
if not vis[x]:
vis[x] = True
else:
ans += 1
print(ans)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages betw... | ```python
n = int(input())
a = [0] + list(map(int, input().split()))
vis = [False] * len(a)
ans = 1
for x in a[1:]:
if not vis[x]:
vis[x] = True
else:
ans += 1
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
61 | E | Enemy is weak | PROGRAMMING | 1,900 | [
"data structures",
"trees"
] | E. Enemy is weak | 5 | 256 | The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | The first line of input contains a single number *n* (3<=≤<=*n*<=≤<=106) — the number of men in Roman army. Next line contains *n* different positive integers *a**i* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*a**i*<=≤<=109) — powers of men in the Roman army. | A single integer number, the weakness of the Roman army.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"3\n3 2 1\n",
"3\n2 3 1\n",
"4\n10 8 3 1\n",
"4\n1 5 4 3\n"
] | [
"1\n",
"0\n",
"4\n",
"1\n"
] | none | 2,500 | [
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "0"
},
{
"input": "4\n10 8 3 1",
"output": "4"
},
{
"input": "4\n1 5 4 3",
"output": "1"
},
{
"input": "9\n10 9 5 6 8 3 4 7 11",
"output": "20"
},
{
"input": "7\n11 3 8 4 2 9 6",
... | 1,573,824,907 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 5,000 | 46,592,000 | n = int(input())
powers = list(map(int, input().split()))
powers = list((enumerate(powers)))
dyn = {}
powers.sort(key=lambda x: x[1])
res = 0
dyn[powers[-1][1]] = 0
for k in range(1, n):
tmp_sum = 0
cur_elem = powers[n - k - 1]
for i in range(n - k, n):
tmp_elem = powers[i]
if tmp_elem[0] <... | Title: Enemy is weak
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roma... | ```python
n = int(input())
powers = list(map(int, input().split()))
powers = list((enumerate(powers)))
dyn = {}
powers.sort(key=lambda x: x[1])
res = 0
dyn[powers[-1][1]] = 0
for k in range(1, n):
tmp_sum = 0
cur_elem = powers[n - k - 1]
for i in range(n - k, n):
tmp_elem = powers[i]
if tmp... | 0 | MatrixStudio/Codeforces-Python-Submissions |
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooo... | 1,604,140,037 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 140 | 0 | n = int(input())
a = 1
b = 1
name = []
for i in range(n):
if i+1 > b:
(a, b) = (b, a + b)
name.append("O" if (i+1 == b) else "o")
print("".join(name))
| Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should o... | ```python
n = int(input())
a = 1
b = 1
name = []
for i in range(n):
if i+1 > b:
(a, b) = (b, a + b)
name.append("O" if (i+1 == b) else "o")
print("".join(name))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,674,930,246 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n, c = map(int, input().split())
nums = [int(x) for x in input().split()][:n]
appear = 0
for i in range(n - 1):
if nums[i + 1] - nums[i] <= c:
appear += 1
else:
appear = 1
print(appear)
| Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
n, c = map(int, input().split())
nums = [int(x) for x in input().split()][:n]
appear = 0
for i in range(n - 1):
if nums[i + 1] - nums[i] <= c:
appear += 1
else:
appear = 1
print(appear)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
33 | B | String Problem | PROGRAMMING | 1,800 | [
"shortest paths"
] | B. String Problem | 2 | 256 | Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can change one arbitrary ch... | The first input line contains two initial non-empty strings *s* and *t*, consisting of lower case Latin letters. The length of each string doesn't exceed 105. The following line contains integer *n* (0<=≤<=*n*<=≤<=500) — amount of possible changings. Then follow *n* lines, each containing characters *A**i* and *B**i* (... | If the answer exists, output the answer to the problem, and the resulting string. Otherwise output -1 in the only line. If the answer is not unique, output any. | [
"uayd\nuxxd\n3\na x 8\nx y 13\nd c 3\n",
"a\nb\n3\na b 2\na b 3\nb a 5\n",
"abc\nab\n6\na b 4\na b 7\nb a 8\nc b 11\nc a 3\na c 0\n"
] | [
"21\nuxyd\n",
"2\nb\n",
"-1\n"
] | none | 1,000 | [
{
"input": "uayd\nuxxd\n3\na x 8\nx y 13\nd c 3",
"output": "21\nuxyd"
},
{
"input": "a\nb\n3\na b 2\na b 3\nb a 5",
"output": "2\nb"
},
{
"input": "abc\nab\n6\na b 4\na b 7\nb a 8\nc b 11\nc a 3\na c 0",
"output": "-1"
},
{
"input": "xhtuopq\nrtutbz\n10\nh x 10\nx d 3\nr u 4... | 1,613,704,692 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 122 | 614,400 | import os
import time
import matplotlib
import numpy as np
import torch
from torch.autograd import Variable
matplotlib.use('agg')
import random
import matplotlib.pyplot as plt
class AverageMeter(object):
"""Computes and stores the average and current value"""
def __init__(self):
... | Title: String Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to mak... | ```python
import os
import time
import matplotlib
import numpy as np
import torch
from torch.autograd import Variable
matplotlib.use('agg')
import random
import matplotlib.pyplot as plt
class AverageMeter(object):
"""Computes and stores the average and current value"""
def __init__(self... | -1 | MatrixStudio/Codeforces-Python-Submissions |
868 | B | Race Against Time | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with ... | Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand. | Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"12 30 45 3 11\n",
"12 0 1 12 1\n",
"3 47 0 4 9\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | 500 | [
{
"input": "12 30 45 3 11",
"output": "NO"
},
{
"input": "12 0 1 12 1",
"output": "YES"
},
{
"input": "3 47 0 4 9",
"output": "YES"
},
{
"input": "10 22 59 6 10",
"output": "YES"
},
{
"input": "3 1 13 12 3",
"output": "NO"
},
{
"input": "11 19 28 9 10"... | 1,627,502,465 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 45 | 62 | 6,963,200 | def mod_60(num):
while num >= 60:
num -= 60
return num
Input = input()
Input = Input.split()
arcs = [0, 0, 0]
for i in range(len(Input)):
Input[i] = int(Input[i])
hToMin = Input[0]*5 + Input[1]/12.0 + Input[2]/720.0
Min = min(Input[3], Input[4]) * 5
Max = max(Input[3], Input[4]) * 5
mod_60(hToMin)
... | Title: Race Against Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time par... | ```python
def mod_60(num):
while num >= 60:
num -= 60
return num
Input = input()
Input = Input.split()
arcs = [0, 0, 0]
for i in range(len(Input)):
Input[i] = int(Input[i])
hToMin = Input[0]*5 + Input[1]/12.0 + Input[2]/720.0
Min = min(Input[3], Input[4]) * 5
Max = max(Input[3], Input[4]) * 5
mod_6... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,598,461,737 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 216 | 0 | n = int(input());d=0
for i in range(n+1):
if i*(i+1)//2 == n:
d=1
break
if d==1:
print("YES")
else:
print("NO") | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
n = int(input());d=0
for i in range(n+1):
if i*(i+1)//2 == n:
d=1
break
if d==1:
print("YES")
else:
print("NO")
``` | 3.946 | MatrixStudio/Codeforces-Python-Submissions |
609 | B | The Best Gift | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find th... | The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed ... | Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109. | [
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] | [
"5\n",
"18\n"
] | The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books. | 0 | [
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2... | 1,629,525,186 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 92 | 20,172,800 | a, b = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
def factorial(n):
if n == 0:
return 1
return factorial(n - 1) * n
g = factorial(a)
g1 = factorial(a-2)
c = g/(2*g1)
v = set()
v1 = 0
for i in l:
v.add(i)
print(int(c - (a - len(v))))
| Title: The Best Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack deci... | ```python
a, b = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
def factorial(n):
if n == 0:
return 1
return factorial(n - 1) * n
g = factorial(a)
g1 = factorial(a-2)
c = g/(2*g1)
v = set()
v1 = 0
for i in l:
v.add(i)
print(int(c - (a - len(v))))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,657,746,729 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 409,600 | import re
s,ss = input(),""
for i in range(len(s)):
if len(re.findall(s[:i+1],s)) >= 3:
if len(s[:i+1]) > len(ss):
ss = s[:i+1]
print(ss if ss != "" else "Just a legend") | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
import re
s,ss = input(),""
for i in range(len(s)):
if len(re.findall(s[:i+1],s)) >= 3:
if len(s[:i+1]) > len(ss):
ss = s[:i+1]
print(ss if ss != "" else "Just a legend")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"o... | 1,667,910,361 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 31 | 0 |
n = int(input())
a = list(map(int,input().split()))
bln = True
for i in range(len(a)):
if a[i] == 1:
print(-1)
bln = False
if bln:
print(1) | Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cann... | ```python
n = int(input())
a = list(map(int,input().split()))
bln = True
for i in range(len(a)):
if a[i] == 1:
print(-1)
bln = False
if bln:
print(1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,698,353,035 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 216 | 1,740,800 | num_of_stat = int(input())
stat_pass = ["0"] * num_of_stat
max_pass = 0
max_pp = 0
for i in range(num_of_stat):
stat_pass[i] = input().split(" ")
for j in stat_pass:
a = max_pass - int(j[0]) + int(j[1])
max_pass = a
if max_pp<a:
max_pp = a
print(max_pp)
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
num_of_stat = int(input())
stat_pass = ["0"] * num_of_stat
max_pass = 0
max_pp = 0
for i in range(num_of_stat):
stat_pass[i] = input().split(" ")
for j in stat_pass:
a = max_pass - int(j[0]) + int(j[1])
max_pass = a
if max_pp<a:
max_pp = a
print(max_pp)
``... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,678,695,777 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | n, k = map(int, input().split())
req = 240 - k
ans = 0
i, j = 1, 240
while i < j:
mid = (i + j) // 2
if 5 * (mid * (mid + 1) / 2) <= req:
ans = max(mid, ans)
i = mid + 1
else:
j = mid
print(min(ans, n)) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
n, k = map(int, input().split())
req = 240 - k
ans = 0
i, j = 1, 240
while i < j:
mid = (i + j) // 2
if 5 * (mid * (mid + 1) / 2) <= req:
ans = max(mid, ans)
i = mid + 1
else:
j = mid
print(min(ans, n))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
549 | C | The Game Of Parity | PROGRAMMING | 2,200 | [
"games"
] | null | null | There are *n* cities in Westeros. The *i*-th city is inhabited by *a**i* people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly *k* cities l... | The first line contains two positive space-separated integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105) — the initial number of cities in Westeros and the number of cities at which the game ends.
The second line contains *n* space-separated positive integers *a**i* (1<=≤<=*a**i*<=≤<=106), which represent the populat... | Print string "Daenerys" (without the quotes), if Daenerys wins and "Stannis" (without the quotes), if Stannis wins. | [
"3 1\n1 2 1\n",
"3 1\n2 2 1\n",
"6 3\n5 20 12 7 14 101\n"
] | [
"Stannis\n",
"Daenerys\n",
"Stannis\n"
] | In the first sample Stannis will use his move to burn a city with two people and Daenerys will be forced to burn a city with one resident. The only survivor city will have one resident left, that is, the total sum is odd, and thus Stannis wins.
In the second sample, if Stannis burns a city with two people, Daenerys bu... | 2,000 | [
{
"input": "3 1\n1 2 1",
"output": "Stannis"
},
{
"input": "3 1\n2 2 1",
"output": "Daenerys"
},
{
"input": "6 3\n5 20 12 7 14 101",
"output": "Stannis"
},
{
"input": "6 3\n346 118 330 1403 5244 480",
"output": "Daenerys"
},
{
"input": "7 4\n11 3532 99 3512 12 8 2... | 1,433,597,608 | 2,008 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 124 | 15,974,400 | """
Codeforces Looksery Cup 2015 Problem C
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def main():
n,k = read()
t = (n-k)//2
a = read()
even, odd = 0, 0
for i in a:
if i % 2:
odd += 1
el... | Title: The Game Of Parity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Westeros. The *i*-th city is inhabited by *a**i* people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all ... | ```python
"""
Codeforces Looksery Cup 2015 Problem C
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def main():
n,k = read()
t = (n-k)//2
a = read()
even, odd = 0, 0
for i in a:
if i % 2:
odd += 1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
36 | B | Fractal | PROGRAMMING | 1,600 | [
"implementation"
] | B. Fractal | 2 | 64 | Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as *n*<=×<=*n* squares and paints some of them black. Then he takes a... | The first line contains integers *n* and *k* (2<=≤<=*n*<=≤<=3, 1<=≤<=*k*<=≤<=5), where *k* is the amount of steps of the algorithm. Each of the following *n* lines contains *n* symbols that determine the model. Symbol «.» stands for a white square, whereas «*» stands for a black one. It is guaranteed that the model has... | Output a matrix *n**k*<=×<=*n**k* which is what a picture should look like after *k* steps of the algorithm. | [
"2 3\n.*\n..\n",
"3 2\n.*.\n***\n.*.\n"
] | [
".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........\n",
".*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*.\n"
] | none | 1,000 | [
{
"input": "2 3\n.*\n..",
"output": ".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........"
},
{
"input": "3 2\n.*.\n***\n.*.",
"output": ".*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*."
},
{
"input": "2 1\n..\n.... | 1,654,241,215 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 102,400 | import sys
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
n,k=map(int,input().split())
s=[input()for i in '0'*n]
b=['*'*len(s[0])for i in '0'*n]
a='.'
for f in'0'*k:
r=[]
for i in a:
t=['']*len(s)
for c in i:
for j in range(len(s)): t[j]+=s[j]if c=='.'else b[j]
r+=t
a=r
pr... | Title: Fractal
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He tak... | ```python
import sys
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
n,k=map(int,input().split())
s=[input()for i in '0'*n]
b=['*'*len(s[0])for i in '0'*n]
a='.'
for f in'0'*k:
r=[]
for i in a:
t=['']*len(s)
for c in i:
for j in range(len(s)): t[j]+=s[j]if c=='.'else b[j]
r+=t... | 3.968237 | 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,459,415,086 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 14,643,200 | a,b = [int(i) for i in input().split()]
list = [int(i) for i in input().split()]
while b>0:
x,y = [int(i) for i in input().split()]
list1 = list[0:y]
if x == 2:
list1.sort(reverse=True)
else:
list1.sort()
list[0:y] = list1
b = b-1
list = [str(i) for i in list]
print('... | 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
a,b = [int(i) for i in input().split()]
list = [int(i) for i in input().split()]
while b>0:
x,y = [int(i) for i in input().split()]
list1 = list[0:y]
if x == 2:
list1.sort(reverse=True)
else:
list1.sort()
list[0:y] = list1
b = b-1
list = [str(i) for i in list... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,687,501,478 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | string = input()
def helper(ind, inputString, pattern):
if len(pattern) == 0:
return True
if ind == len(inputString):
return False
if inputString[ind] == pattern[0]:
pattern = pattern[1:]
return helper(ind+1, inputString, pattern)
else:
return helper(ind... | 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
string = input()
def helper(ind, inputString, pattern):
if len(pattern) == 0:
return True
if ind == len(inputString):
return False
if inputString[ind] == pattern[0]:
pattern = pattern[1:]
return helper(ind+1, inputString, pattern)
else:
return ... | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
606 | A | Magic Spheres | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible,... | The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number o... | If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". | [
"4 4 0\n2 1 2\n",
"5 6 1\n2 7 2\n",
"3 3 3\n2 2 2\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what... | 500 | [
{
"input": "4 4 0\n2 1 2",
"output": "Yes"
},
{
"input": "5 6 1\n2 7 2",
"output": "No"
},
{
"input": "3 3 3\n2 2 2",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 0",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 1",
"output": "No"
},
{
"input": "0 1 0\n0 0 0... | 1,660,467,752 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 77 | 0 | l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
spp = 0
spn = 0
spn = max(l2[0] - l1[0], 0) + max(l2[1] - l1[1], 0) + max(l2[2] - l1[2], 0)
spp = max((l1[0] - l2[0]) / 2, 0) + max((l1[1] - l2[1]) / 2, 0) + max((l1[2] - l2[2]) / 2, 0);
if spp >= spn:
print("YES")
else:
print("NO")
... | Title: Magic Spheres
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been see... | ```python
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
spp = 0
spn = 0
spn = max(l2[0] - l1[0], 0) + max(l2[1] - l1[1], 0) + max(l2[2] - l1[2], 0)
spp = max((l1[0] - l2[0]) / 2, 0) + max((l1[1] - l2[1]) / 2, 0) + max((l1[2] - l2[2]) / 2, 0);
if spp >= spn:
print("YES")
else:
prin... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,674,984,260 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n=int(input())
found=False
for i in range(n):
n2=input()
a=n2[0]
b=n2[2]
if a>b:
found=True
break
if found:
print("Happy Alex")
else:
print("Poor Alex")
| Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n=int(input())
found=False
for i in range(n):
n2=input()
a=n2[0]
b=n2[2]
if a>b:
found=True
break
if found:
print("Happy Alex")
else:
print("Poor Alex")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,695,299,768 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | y=int(input())
if y==1987:
print(2013)
else:
y+=1
print(y) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
y=int(input())
if y==1987:
print(2013)
else:
y+=1
print(y)
``` | 0 | 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,619,765,949 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 124 | 204,800 | n=int(input())
a=list(map(int,input().split()))
len=0
max=0
breakpoint=0
newMaxima=False
for i in range(n):
if i==0 or i==n-1:
len+=1
if i!=n-1 and a[i]>a[i+1]:
breakpoint=len
else:
if a[i-1]>=a[i] and a[i+1]>a[i]:
newMaxima=True
len+=1
... | 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
n=int(input())
a=list(map(int,input().split()))
len=0
max=0
breakpoint=0
newMaxima=False
for i in range(n):
if i==0 or i==n-1:
len+=1
if i!=n-1 and a[i]>a[i+1]:
breakpoint=len
else:
if a[i-1]>=a[i] and a[i+1]>a[i]:
newMaxima=True
le... | 3.968619 | MatrixStudio/Codeforces-Python-Submissions |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,549,086,374 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 |
a,b,c = map(int,input().split())
lst = False
idk = []
idk.append(a)
while b>a:
a += c
idk.append(a)
if b in idk:
lst = True
break
else:
lst = False
if lst:
print("YES")
exit()
print("NO") | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a,b,c = map(int,input().split())
lst = False
idk = []
idk.append(a)
while b>a:
a += c
idk.append(a)
if b in idk:
lst = True
break
else:
lst = False
if lst:
print("YES")
exit()
print("NO")
``` | 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,665,394,305 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 156 | 614,400 | t, a, b, p, q = map(int, input().split())
st = list(input())
dt = {}
x = a - p
if x > 0:
dt['W'] = x
else:
dt['E'] = abs(x)
y = b - q
if y > 0:
dt['S'] = y
else:
dt['N'] = abs(y)
ans = 0
#print(dt)
x = True
for i in dt:
for j in range(len(st)):
if i == st[j] and dt[i] != 0:
dt[i] -= 1
... | 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
t, a, b, p, q = map(int, input().split())
st = list(input())
dt = {}
x = a - p
if x > 0:
dt['W'] = x
else:
dt['E'] = abs(x)
y = b - q
if y > 0:
dt['S'] = y
else:
dt['N'] = abs(y)
ans = 0
#print(dt)
x = True
for i in dt:
for j in range(len(st)):
if i == st[j] and dt[i] != 0:
dt... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"out... | 1,564,769,154 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 109 | 0 | inpt = [int(i) for i in input().split()]
if inpt[0] > inpt[1]:
print("First")
else:
print("Second")
| Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba... | ```python
inpt = [int(i) for i in input().split()]
if inpt[0] > inpt[1]:
print("First")
else:
print("Second")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
189 | B | Counting Rhombi | PROGRAMMING | 1,300 | [
"brute force",
"math"
] | null | null | You have two positive integers *w* and *h*. Your task is to count the number of rhombi which have the following properties:
- Have positive area. - With vertices at integer points. - All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0,<=0), (*w*,<=0), (*w*,<=*... | The first line contains two integers *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=4000) — the rectangle's sizes. | Print a single number — the number of sought rhombi.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2 2\n",
"1 2\n"
] | [
"1\n",
"0\n"
] | In the first example there exists only one such rhombus. Its vertices are located at points (1, 0), (2, 1), (1, 2), (0, 1). | 1,000 | [
{
"input": "2 2",
"output": "1"
},
{
"input": "1 2",
"output": "0"
},
{
"input": "1 4000",
"output": "0"
},
{
"input": "4000 1",
"output": "0"
},
{
"input": "4000 4000",
"output": "16000000000000"
},
{
"input": "15 10",
"output": "1400"
},
{
... | 1,686,195,882 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 1,331,200 | w,h=map(int,input().split())
cur=w-1
ans=0
while cur>2:
ans+=cur
cur-=2
print(ans+cur) | Title: Counting Rhombi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two positive integers *w* and *h*. Your task is to count the number of rhombi which have the following properties:
- Have positive area. - With vertices at integer points. - All vertices of the rhombi are ... | ```python
w,h=map(int,input().split())
cur=w-1
ans=0
while cur>2:
ans+=cur
cur-=2
print(ans+cur)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 1,000 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,522,091,662 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 7,065,600 | import math
x=input()
x=x.split()
f=int(x[1])
s=int(x[2])
l=int(x[0])
#l=math.log2(l)
if f%2==1:
f+=1
if s%2==1:
s+=1
if f==s:
print(1)
else:
x=l/2
if f<=x and s>x:
print("Final!")
else:
for i in range(10):
if s<=x:
x=x/2
... | Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in th... | ```python
import math
x=input()
x=x.split()
f=int(x[1])
s=int(x[2])
l=int(x[0])
#l=math.log2(l)
if f%2==1:
f+=1
if s%2==1:
s+=1
if f==s:
print(1)
else:
x=l/2
if f<=x and s>x:
print("Final!")
else:
for i in range(10):
if s<=x:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,629,212,743 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 436 | 31,436,800 | import itertools
l = []
[l.append(int(x)) for x in input().split()]
[l.append(int(x)) for x in input().split()]
[l.append(int(x)) for x in input().split()]
g = list(range(1, 10))
lk = True
for c in list(itertools.permutations(g)):
if c[0] + c[1] != l[0]: continue
if c[2] + c[3] != l[1]: continue
if c[0] + c... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
import itertools
l = []
[l.append(int(x)) for x in input().split()]
[l.append(int(x)) for x in input().split()]
[l.append(int(x)) for x in input().split()]
g = list(range(1, 10))
lk = True
for c in list(itertools.permutations(g)):
if c[0] + c[1] != l[0]: continue
if c[2] + c[3] != l[1]: continue
i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Yaroslav has an array, consisting of (2·*n*<=-<=1) integers. In a single operation Yaroslav can change the sign of exactly *n* elements in the array. In other words, in one operation Yaroslav can select exactly *n* array elements, and multiply each of them by -1.
Yaroslav is now wondering: what maximum sum of array el... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains (2·*n*<=-<=1) integers — the array elements. The array elements do not exceed 1000 in their absolute value. | In a single line print the answer to the problem — the maximum sum that Yaroslav can get. | [
"2\n50 50 50\n",
"2\n-1 -100 -1\n"
] | [
"150\n",
"100\n"
] | In the first sample you do not need to change anything. The sum of elements equals 150.
In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100. | 0 | [
{
"input": "2\n50 50 50",
"output": "150"
},
{
"input": "2\n-1 -100 -1",
"output": "100"
},
{
"input": "3\n-959 -542 -669 -513 160",
"output": "2843"
},
{
"input": "4\n717 473 344 -51 -548 703 -869",
"output": "3603"
},
{
"input": "5\n270 -181 957 -509 -6 937 -175... | 1,375,435,694 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 92 | 0 | #!/bin/python
n = int(input())
a = list(map(int, input().split()))
c = 0
for cc in a:
if cc < 0:
c += 1
if 0 in a:
print(sum(abs(x) for x in a))
elif n % 2 == 0 and c % 2 == 1:
print(sum(abs(x) for x in a) - 2*min(map(abs, a)))
else:
print(sum(abs(x) for x in a))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array, consisting of (2·*n*<=-<=1) integers. In a single operation Yaroslav can change the sign of exactly *n* elements in the array. In other words, in one operation Yaroslav can select exactly *n* array elements,... | ```python
#!/bin/python
n = int(input())
a = list(map(int, input().split()))
c = 0
for cc in a:
if cc < 0:
c += 1
if 0 in a:
print(sum(abs(x) for x in a))
elif n % 2 == 0 and c % 2 == 1:
print(sum(abs(x) for x in a) - 2*min(map(abs, a)))
else:
print(sum(abs(x) for x in a))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
343 | A | Rational Resistance | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we wil... | The single input line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists. | Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier. | [
"1 1\n",
"3 2\n",
"199 200\n"
] | [
"1\n",
"3\n",
"200\n"
] | In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5305da389756aab6... | 500 | [
{
"input": "1 1",
"output": "1"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "199 200",
"output": "200"
},
{
"input": "1 1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "21 8",
"output": "7... | 1,666,428,646 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | n,m=map(int, input().split())
def ss(x,y):
if x==1:
return y
return x//y+ss(y,x%y)
print(ss(n,m)) | Title: Rational Resistance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R... | ```python
n,m=map(int, input().split())
def ss(x,y):
if x==1:
return y
return x//y+ss(y,x%y)
print(ss(n,m))
``` | 3 | 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,622,205,724 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 62 | 0 | def f(r,c):
if r==1 or c==1:
return 1
return f(r-1,c) + f(r,c-1)
n=int(input())
print(f(n,n)) | 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
def f(r,c):
if r==1 or c==1:
return 1
return f(r-1,c) + f(r,c-1)
n=int(input())
print(f(n,n))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,532,065,442 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 124 | 0 | n = int(input())
a = set(input().split())
ans = len(a)
if "0" in a: ans-=1
print(ans)
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n = int(input())
a = set(input().split())
ans = len(a)
if "0" in a: ans-=1
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,595,869,510 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 109 | 6,963,200 | def solve():
n = int(input())
mystr = input()
count = 0
if len(mystr) > 26:
print(-1)
return
for i in range(len(mystr)):
if mystr[i] in mystr[:i]:
continue
if (mystr[i] in mystr[i + 1:]):
count += mystr[i + 1:].count(mystr[i])
... | Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
def solve():
n = int(input())
mystr = input()
count = 0
if len(mystr) > 26:
print(-1)
return
for i in range(len(mystr)):
if mystr[i] in mystr[:i]:
continue
if (mystr[i] in mystr[i + 1:]):
count += mystr[i + 1:].count(mystr[... | 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,695,643,304 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 436 | 11,366,400 | n=int(input())
s=0
while n>9:
n=sum(map(int,list(str(n))))
s+=1
print(s) | 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())
s=0
while n>9:
n=sum(map(int,list(str(n))))
s+=1
print(s)
``` | 3.870547 | MatrixStudio/Codeforces-Python-Submissions |
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descr... | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.co... | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\n... | 1,641,332,921 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 202 | 1,945,600 |
import string
def main_function():
n, m = [int(i) for i in input().split(" ")]
s = list(input())
a = string.ascii_lowercase
hash_changes = [[] for i in range(123)]
for i in range(m):
a, b = [i for i in input().split(" ")]
if not a == b:
if len(hash_chan... | Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand ... | ```python
import string
def main_function():
n, m = [int(i) for i in input().split(" ")]
s = list(input())
a = string.ascii_lowercase
hash_changes = [[] for i in range(123)]
for i in range(m):
a, b = [i for i in input().split(" ")]
if not a == b:
if len... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,699,702,399 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,m=map(int,input().split())
l=list(map(int,input().split()))
l=list(map(lambda x:x//m,l))
print(n-(l[::-1].index(max(l)))) | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
n,m=map(int,input().split())
l=list(map(int,input().split()))
l=list(map(lambda x:x//m,l))
print(n-(l[::-1].index(max(l))))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,643,516,023 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n = int(input())
for i in range(n):
d = ""
for j in range(1, n):
d += str(n*i+j) + " "
d += str(n*n - n*i - j + 1) + " "
print(d)
| Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n = int(input())
for i in range(n):
d = ""
for j in range(1, n):
d += str(n*i+j) + " "
d += str(n*n - n*i - j + 1) + " "
print(d)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,591,126,592 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 280 | 0 | #Cupboards
#Problem Link : http://codeforces.com/problemset/problem/248/A
n = int(input())
leftOne , rightOne = 0 , 0
for _ in range(n):
x , y = map(int , input().split())
leftOne += x
rightOne += y
print(n - leftOne if leftOne > n // 2 else leftOne + n - rightOne if rightOne > n // 2 else rightOne)
| Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
#Cupboards
#Problem Link : http://codeforces.com/problemset/problem/248/A
n = int(input())
leftOne , rightOne = 0 , 0
for _ in range(n):
x , y = map(int , input().split())
leftOne += x
rightOne += y
print(n - leftOne if leftOne > n // 2 else leftOne + n - rightOne if rightOne > n // 2 else right... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
946 | D | Timetable | PROGRAMMING | 1,800 | [
"dp"
] | null | null | Ivan is a student at Berland State University (BSU). There are *n* days in Berland week, and each of these days Ivan might have some classes at the university.
There are *m* working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during *i*... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=≤<=500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then *n* lines follow, *i*-th line containing a binary string of *m* charact... | Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than *k* lessons. | [
"2 5 1\n01001\n10110\n",
"2 5 0\n01001\n10110\n"
] | [
"5\n",
"8\n"
] | In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | 0 | [
{
"input": "2 5 1\n01001\n10110",
"output": "5"
},
{
"input": "2 5 0\n01001\n10110",
"output": "8"
},
{
"input": "3 4 0\n0000\n0000\n0000",
"output": "0"
},
{
"input": "3 4 12\n1111\n1111\n1111",
"output": "0"
},
{
"input": "3 4 6\n1111\n1111\n1111",
"output":... | 1,671,724,121 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 614,400 | # if you win, you live. you cannot win unless you fight.
import sys
from sys import stdin, setrecursionlimit
# fd=open("cses.txt")
# sys.stdin=fd
input = stdin.readline
import heapq
rd = lambda: map(lambda s: int(s), input().strip().split())
rdone = lambda: map(lambda s: int(s) - 1, input().strip().split())
ri = lamb... | Title: Timetable
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan is a student at Berland State University (BSU). There are *n* days in Berland week, and each of these days Ivan might have some classes at the university.
There are *m* working hours during each Berland day, and each le... | ```python
# if you win, you live. you cannot win unless you fight.
import sys
from sys import stdin, setrecursionlimit
# fd=open("cses.txt")
# sys.stdin=fd
input = stdin.readline
import heapq
rd = lambda: map(lambda s: int(s), input().strip().split())
rdone = lambda: map(lambda s: int(s) - 1, input().strip().split())... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
8 | B | Obsession with Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ... | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | 0 | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"... | 1,542,800,122 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 218 | 0 | a = []
for i in range(10):
a.append([0] * 10)
curx = 5
cury = 5
way = input()
a[curx][cury] = 1
for i in way:
if i == 'L':
curx -= 1
if i == 'U':
cury += 1
if i == 'R':
curx += 1
if i == 'D':
cury -= 1
if a[curx][cury] == 1:
... | Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path fr... | ```python
a = []
for i in range(10):
a.append([0] * 10)
curx = 5
cury = 5
way = input()
a[curx][cury] = 1
for i in way:
if i == 'L':
curx -= 1
if i == 'U':
cury += 1
if i == 'R':
curx += 1
if i == 'D':
cury -= 1
if a[curx][cury]... | 0 | MatrixStudio/Codeforces-Python-Submissions |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,663,387,358 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n,m=map(int,input().split())
num=[(int(x) for x in input().split())for i in range(n)]
x=0
for i in range(m):
if i in num:
x+=1
print(['NO','YES'][x!=m]) | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n,m=map(int,input().split())
num=[(int(x) for x in input().split())for i in range(n)]
x=0
for i in range(m):
if i in num:
x+=1
print(['NO','YES'][x!=m])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,639,275,939 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 122 | 0 | s=input()
countup=len([i for i in s if i.isupper()])
countlo=len([i for i in s if i.islower()])
if countup>countlo :
print(s.upper())
else:
print(s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
countup=len([i for i in s if i.isupper()])
countlo=len([i for i in s if i.islower()])
if countup>countlo :
print(s.upper())
else:
print(s.lower())
``` | 3.9695 | MatrixStudio/Codeforces-Python-Submissions |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,524,865,116 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 93 | 7,065,600 | v = input().split()
n = int(v[0])
k = int(v[1])
M = int(v[2])
D = int(v[3])
ans = -100000000000000000000000000000000000
for times in range(1, D + 1):
den = (times - 1) * k + 1
x = min(n // den, M)
ans = max(ans, times * x)
print(ans) | Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
v = input().split()
n = int(v[0])
k = int(v[1])
M = int(v[2])
D = int(v[3])
ans = -100000000000000000000000000000000000
for times in range(1, D + 1):
den = (times - 1) * k + 1
x = min(n // den, M)
ans = max(ans, times * x)
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
396 | C | On Changing Tree | PROGRAMMING | 0 | [
"data structures",
"graphs",
"trees"
] | null | null | You are given a rooted tree consisting of *n* vertices numbered from 1 to *n*. The root of the tree is a vertex number 1.
Initially all vertices contain number 0. Then come *q* queries, each query has one of the two types:
- The format of the query: 1 *v* *x* *k*. In response to the query, you need to add to the num... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — 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* is the number of the vertex that is the parent of vertex *i* in the tree.
The third line contains integer *q* (1<=... | For each query of the second type print on a single line the number written in the vertex from the query. Print the number modulo 1000000007 (109<=+<=7). | [
"3\n1 1\n3\n1 1 2 1\n2 1\n2 2\n"
] | [
"2\n1\n"
] | You can read about a rooted tree here: http://en.wikipedia.org/wiki/Tree_(graph_theory). | 1,500 | [
{
"input": "3\n1 1\n3\n1 1 2 1\n2 1\n2 2",
"output": "2\n1"
},
{
"input": "10\n1 2 3 4 4 3 3 6 7\n10\n1 6 13 98\n1 7 17 66\n1 5 32 39\n1 1 9 5\n1 7 27 11\n1 1 24 79\n1 5 87 86\n2 2\n1 5 9 38\n2 5",
"output": "999999956\n999999832"
},
{
"input": "1\n\n1\n2 1",
"output": "0"
}
] | 1,698,721,743 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 223,232,000 | import sys
import random
input = sys.stdin.readline
rd = random.randint(10 ** 9, 2 * 10 ** 9)
class FenwickTree:
def __init__(self, n):
self.n = n + 1
self.bit = [[0] * (self.n) for _ in range(2)]
def add_sub(self, p, i, x):
while i < self.n:
self.bit[p][i] ... | Title: On Changing Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree consisting of *n* vertices numbered from 1 to *n*. The root of the tree is a vertex number 1.
Initially all vertices contain number 0. Then come *q* queries, each query has one of the two t... | ```python
import sys
import random
input = sys.stdin.readline
rd = random.randint(10 ** 9, 2 * 10 ** 9)
class FenwickTree:
def __init__(self, n):
self.n = n + 1
self.bit = [[0] * (self.n) for _ in range(2)]
def add_sub(self, p, i, x):
while i < self.n:
self.... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,682,731,406 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 61 | 0 | n,m = map(int,input().split())
x = list(map(lambda q:int(q), input().split(" ")))
c=0
for i in range(n):
if x[i]%m==0:
a=x[i]//m
else:
a=x[i]//m+1
if c<=a:
c=a
ans=i
print(ans+1)
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
n,m = map(int,input().split())
x = list(map(lambda q:int(q), input().split(" ")))
c=0
for i in range(n):
if x[i]%m==0:
a=x[i]//m
else:
a=x[i]//m+1
if c<=a:
c=a
ans=i
print(ans+1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
359 | A | Table | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are... | The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50).
Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* e... | Print a single number — the minimum number of operations Simon needs to carry out his idea. | [
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n"
] | [
"4\n",
"2\n"
] | In the first sample, the sequence of operations can be like this:
- For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to c... | 500 | [
{
"input": "3 3\n0 0 0\n0 1 0\n0 0 0",
"output": "4"
},
{
"input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0",
"output": "2"
},
{
"input": "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0... | 1,624,895,574 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 77 | 102,400 | from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf
from bisect import bisect_right, bisect_left
n, m = map(int, input().split())
end = False
for _ in range(n):
s = input()
if s[-1] == "1" or s[0] == ... | Title: Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on t... | ```python
from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf
from bisect import bisect_right, bisect_left
n, m = map(int, input().split())
end = False
for _ in range(n):
s = input()
if s[-1] == "1" o... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
142 | D | Help Shrek and Donkey 2 | PROGRAMMING | 2,600 | [
"games"
] | null | null | Having learned (not without some help from the Codeforces participants) to play the card game from the previous round optimally, Shrek and Donkey (as you may remember, they too live now in the Kingdom of Far Far Away) have decided to quit the boring card games and play with toy soldiers.
The rules of the game are as f... | The first line contains space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=100). Then *n* lines contain *m* characters each. These characters belong to the set {"-", "G", "R"}, denoting, respectively, a battlefield's free cell, a cell occupied by Shrek's soldiers and a cell occupied by Donkey's soldie... | Print "First" (without the quotes) if Shrek wins in the given Toy Soldier game. If Donkey wins, print "Second" (without the quotes). If the game continues forever, print "Draw" (also without the quotes). | [
"2 3 1\nR-G\nRG-\n",
"3 3 2\nG-R\nR-G\nG-R\n",
"2 3 1\n-R-\n-G-\n",
"2 5 2\n-G-R-\n-R-G-\n"
] | [
"First\n",
"Second\n",
"Draw\n",
"First\n"
] | none | 2,000 | [
{
"input": "2 3 1\nR-G\nRG-",
"output": "First"
},
{
"input": "3 3 2\nG-R\nR-G\nG-R",
"output": "Second"
},
{
"input": "2 3 1\n-R-\n-G-",
"output": "Draw"
},
{
"input": "2 5 2\n-G-R-\n-R-G-",
"output": "First"
},
{
"input": "3 3 1\nG-R\nR-G\nG-R",
"output": "F... | 1,690,504,710 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1690504710.3901584")# 1690504710.3901782 | Title: Help Shrek and Donkey 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Having learned (not without some help from the Codeforces participants) to play the card game from the previous round optimally, Shrek and Donkey (as you may remember, they too live now in the Kingdom of Far Far... | ```python
print("_RANDOM_GUESS_1690504710.3901584")# 1690504710.3901782
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,693,844,456 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n = int(input())
denominations = [100, 20, 10, 5, 1]
count = 0
for i in denominations:
c += n // i
n %= i
print(c)
| Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
n = int(input())
denominations = [100, 20, 10, 5, 1]
count = 0
for i in denominations:
c += n // i
n %= i
print(c)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,630,573,710 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 20,172,800 | n,a,b=map(int,input().split())
l=1
r=a+b
while r-l>1:
x=(l+r)//2
if int(a/x)+int(b/x)>=n:
l=x
else:
r=x
print(l) | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
n,a,b=map(int,input().split())
l=1
r=a+b
while r-l>1:
x=(l+r)//2
if int(a/x)+int(b/x)>=n:
l=x
else:
r=x
print(l)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,592,263,999 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | l,r,x,y,k = map(int,input().split())
def charo(l,r,x,y,k):
for i in range(l,r+1):
for loop in range(x,y+1):
if i/loop == k:
return "YES"
return "NO"
print(charo(l,r,x,y,k)) | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
l,r,x,y,k = map(int,input().split())
def charo(l,r,x,y,k):
for i in range(l,r+1):
for loop in range(x,y+1):
if i/loop == k:
return "YES"
return "NO"
print(charo(l,r,x,y,k))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,662,825,038 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n=int(input())
a=1
t=0
while a<=n:
if a==n:
t=1
a=a*(a+1)
if t==0:
print('NO')
else:
print('YES') | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
n=int(input())
a=1
t=0
while a<=n:
if a==n:
t=1
a=a*(a+1)
if t==0:
print('NO')
else:
print('YES')
``` | -1 | 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,694,983,419 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a = input()
hello = 'hello'
list_word = [i for i in a if i in hello]
final_word = ''
#Check if the letter exists
#Then the loop must start from there
for i in hello:
index = 0
for j in list_word[index:]:
if j == i:
final_word = final_word + i
index = list_word.in... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a = input()
hello = 'hello'
list_word = [i for i in a if i in hello]
final_word = ''
#Check if the letter exists
#Then the loop must start from there
for i in hello:
index = 0
for j in list_word[index:]:
if j == i:
final_word = final_word + i
index = li... | 0 | 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,698,845,111 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 109 | 2,867,200 | from sys import stdin, stdout
from functools import reduce
import math
def main():
i=int(stdin.readline().strip())
rem=i%4
e='b' if rem==1 else 'bb' if rem==2 else 'bba' if rem==3 else ''
s='bbaa'*(i//4)+e
return s
stdout.write(str(main()))
| 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
from sys import stdin, stdout
from functools import reduce
import math
def main():
i=int(stdin.readline().strip())
rem=i%4
e='b' if rem==1 else 'bb' if rem==2 else 'bba' if rem==3 else ''
s='bbaa'*(i//4)+e
return s
stdout.write(str(main()))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,504,020,326 | 1,226 | Python 3 | CHALLENGED | CHALLENGES | 13 | 62 | 0 | import math
l, r, x, y, k = map(int, input().split())
if not int(r/x) >= k >= math.ceil(l/y):
print("NO")
else:
print("YES") | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
import math
l, r, x, y, k = map(int, input().split())
if not int(r/x) >= k >= math.ceil(l/y):
print("NO")
else:
print("YES")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,631,889,446 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 20,172,800 | a=input().replace(" ","")
# print(a)
zc=a.count('0')
fc=a.count('5')
if zc!=0:
rem=fc%9
print('5'*(fc-rem)+'0'*zc)
else:
print(-1) | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
a=input().replace(" ","")
# print(a)
zc=a.count('0')
fc=a.count('5')
if zc!=0:
rem=fc%9
print('5'*(fc-rem)+'0'*zc)
else:
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,684,244,265 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 154 | 10,854,400 | n=int(input())
lst=list(map(int,input().rstrip().split()))
d={50:0,25:0,100:0}
ans="YES"
for i in lst:
if i==25:
d[i]+=1
elif i==50:
if d[25]>=1:
d[25]-=1
d[50]+=1
else:
ans="NO"
break
else:
if (d[50]>=1 and d[25]... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
n=int(input())
lst=list(map(int,input().rstrip().split()))
d={50:0,25:0,100:0}
ans="YES"
for i in lst:
if i==25:
d[i]+=1
elif i==50:
if d[25]>=1:
d[25]-=1
d[50]+=1
else:
ans="NO"
break
else:
if (d[50]>=1... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,617,071,268 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 307,200 | a,b=map(int,input().split(" "))
m=min(a,b)
n=max(a,b)
c=0
for i in range(1,m+1):
num=i%5
if num==0:
num=5
init=abs(5-num)
ans=(abs(n-init))//5
if num!=5:
ans+=1
c+=ans
print(c)
| Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
a,b=map(int,input().split(" "))
m=min(a,b)
n=max(a,b)
c=0
for i in range(1,m+1):
num=i%5
if num==0:
num=5
init=abs(5-num)
ans=(abs(n-init))//5
if num!=5:
ans+=1
c+=ans
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,560,071,171 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | s=str(input())
small=0
large=0
for i in s:
if(i.islower()):
small += 1
elif(i.isupper()):
large += 1
if small >= large:
print(s.lower())
elif small < large:
print(s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=str(input())
small=0
large=0
for i in s:
if(i.islower()):
small += 1
elif(i.isupper()):
large += 1
if small >= large:
print(s.lower())
elif small < large:
print(s.upper())
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,651,938,453 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | T = int(input())
color = set()
for i in range(T):
S = input()
color.add(S)
print(len(color))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
T = int(input())
color = set()
for i in range(T):
S = input()
color.add(S)
print(len(color))
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T... | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<... | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "5287... | 1,679,199,511 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | def main():
n , p1 , p2 , p3 , t1 , t2 = map(int, input().split())
sum = 0
for i in range(n):
l, r = map(int, input().split())
if i > 0:
d = l - r0 - t1
if d > 0 and d >= t2:
sum += t2 * p2
#print (sum)
elif d > 0:
... | Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f... | ```python
def main():
n , p1 , p2 , p3 , t1 , t2 = map(int, input().split())
sum = 0
for i in range(n):
l, r = map(int, input().split())
if i > 0:
d = l - r0 - t1
if d > 0 and d >= t2:
sum += t2 * p2
#print (sum)
elif d > 0:... | 0 | MatrixStudio/Codeforces-Python-Submissions |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,675,703,967 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | n=int(input())
s=list(input())
m=list(set(s))
p=""
flag=0
for i in m:
a=s.count(i)
if n==1:
p="".join(s)
break
if a%n!=0:
flag=1
break
else:
k=int(a//n)
p=p+i*k
if flag!=1:
p=p*n
print(p)
else:
print('-1') | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
n=int(input())
s=list(input())
m=list(set(s))
p=""
flag=0
for i in m:
a=s.count(i)
if n==1:
p="".join(s)
break
if a%n!=0:
flag=1
break
else:
k=int(a//n)
p=p+i*k
if flag!=1:
p=p*n
print(p)
else:
print('-... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
48 | A | Rock-paper-scissors | PROGRAMMING | 900 | [
"implementation",
"schedules"
] | A. Rock-paper-scissors | 2 | 256 | Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio... | The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. | Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". | [
"rock\nrock\nrock\n",
"paper\nrock\nrock\n",
"scissors\nrock\nrock\n",
"scissors\npaper\nrock\n"
] | [
"?\n",
"F\n",
"?\n",
"?\n"
] | none | 0 | [
{
"input": "rock\nrock\nrock",
"output": "?"
},
{
"input": "paper\nrock\nrock",
"output": "F"
},
{
"input": "scissors\nrock\nrock",
"output": "?"
},
{
"input": "scissors\npaper\nrock",
"output": "?"
},
{
"input": "paper\npaper\nrock",
"output": "?"
},
{
... | 1,398,207,183 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | f, m, s = input(), input(), input()
wins = {'rock': {'rock': False, 'scissors': True, 'paper': False}, 'scissors': {'rock': False, 'scissors': False, 'paper': True}, 'paper': {'rock': True, 'scissors': False, 'paper': False}}
if (wins[f][m] and wins[f][s]):
print 'F'
elif (wins[m][f] and wins[m][s]):
p... | Title: Rock-paper-scissors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ... | ```python
f, m, s = input(), input(), input()
wins = {'rock': {'rock': False, 'scissors': True, 'paper': False}, 'scissors': {'rock': False, 'scissors': False, 'paper': True}, 'paper': {'rock': True, 'scissors': False, 'paper': False}}
if (wins[f][m] and wins[f][s]):
print 'F'
elif (wins[m][f] and wins[m][s... | -1 | MatrixStudio/Codeforces-Python-Submissions |
127 | B | Canvas Frames | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | [
"5\n2 4 3 2 3\n",
"13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n",
"4\n3 3 3 5\n"
] | [
"1",
"3",
"0"
] | none | 1,000 | [
{
"input": "5\n2 4 3 2 3",
"output": "1"
},
{
"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9",
"output": "3"
},
{
"input": "4\n3 3 3 5",
"output": "0"
},
{
"input": "2\n3 5",
"output": "0"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "14\... | 1,658,266,711 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 93 | 62 | 0 | n=int(input())
length=list(map(int,input().split()))
freq=[0]*(max(length)+1)
s=0
total=0
for i in range(len(length)):
freq[length[i]]+=1
for i in range(len(freq)):
if freq[i]%2!=0:
freq[i]-=1
s=sum(freq)
total=s//4
print(total)
| Title: Canvas Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin w... | ```python
n=int(input())
length=list(map(int,input().split()))
freq=[0]*(max(length)+1)
s=0
total=0
for i in range(len(length)):
freq[length[i]]+=1
for i in range(len(freq)):
if freq[i]%2!=0:
freq[i]-=1
s=sum(freq)
total=s//4
print(total)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,613,402,955 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 685 | 12,902,400 | n = int(input())
cits = list(map(int, input().split()))
sol = []
for i in range(n):
mx = max(abs(cits[i] - cits[0]), abs(cits[i] - cits[-1]))
if i == 0:
mn = abs(cits[i] - cits[i + 1])
elif i == n - 1:
mn = abs(cits[i] - cits[ i - 1])
else:
mn = min(abs(cits[i] - ci... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n = int(input())
cits = list(map(int, input().split()))
sol = []
for i in range(n):
mx = max(abs(cits[i] - cits[0]), abs(cits[i] - cits[-1]))
if i == 0:
mn = abs(cits[i] - cits[i + 1])
elif i == n - 1:
mn = abs(cits[i] - cits[ i - 1])
else:
mn = min(abs(ci... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,563,182,011 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 218 | 0 | import math as m
a, b, c = map(int, input().split())
v= m.sqrt(a*b*c)
print(int(4*(v/a+v/b+v/c))) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math as m
a, b, c = map(int, input().split())
v= m.sqrt(a*b*c)
print(int(4*(v/a+v/b+v/c)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,682,077,836 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(n):
if p[i] <= 5 - k:
ans += 1
print(ans // 3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(n):
if p[i] <= 5 - k:
ans += 1
print(ans // 3)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,646,632,285 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 46 | 0 | m,n=map(int,input().split())
part=int(m/n);
pleft=m%n;
print(int((part*(part-1)*(n)/2)+((part)*(pleft)))," ",int((m-n+1)*(m-n)/2)) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
m,n=map(int,input().split())
part=int(m/n);
pleft=m%n;
print(int((part*(part-1)*(n)/2)+((part)*(pleft)))," ",int((m-n+1)*(m-n)/2))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid show... | The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov... | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
... | 1,685,711,875 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | a = list(map(int,input().split()))
b = min(a[0],a[1])
if b%2 == 0:
print("Malvika")
else:
print("Akshat") | Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid... | ```python
a = list(map(int,input().split()))
b = min(a[0],a[1])
if b%2 == 0:
print("Malvika")
else:
print("Akshat")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,605,822,169 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 296 | 16,793,600 | n = int(input())
x = sorted(map(int, input().split()))
d = [x[i] - x[i-1] for i in range(1, n)]
a = min(d)
print(a, d.count(a))
| Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
n = int(input())
x = sorted(map(int, input().split()))
d = [x[i] - x[i-1] for i in range(1, n)]
a = min(d)
print(a, d.count(a))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,689,064,775 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | def clc():
n = int(input())
res = 0
for mask in range(1,1025):
number = mask
mul = 1
y = 0
while number:
y = y+ mul*(number&1)
mul*=10
number=number//2
if y<=n:
res+=1
print(res)
ret... | Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
def clc():
n = int(input())
res = 0
for mask in range(1,1025):
number = mask
mul = 1
y = 0
while number:
y = y+ mul*(number&1)
mul*=10
number=number//2
if y<=n:
res+=1
print(res)
... | 3.954 | MatrixStudio/Codeforces-Python-Submissions |
765 | C | Table Tennis Game 2 | PROGRAMMING | 1,200 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* poi... | The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | 1,250 | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "... | 1,660,955,149 | 2,147,483,647 | PyPy 3 | OK | TESTS | 279 | 93 | 0 | def solve(p,s1,s2):
ans=s1//p+s2//p
if s1%p!=0 and s2//p==0:
return -1
elif s1//p==0 and s2%p!=0:
return -1
return ans
p,s1,s2=map(int,input().split())
print(solve(p,s1,s2))
| Title: Table Tennis Game 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scor... | ```python
def solve(p,s1,s2):
ans=s1//p+s2//p
if s1%p!=0 and s2//p==0:
return -1
elif s1//p==0 and s2%p!=0:
return -1
return ans
p,s1,s2=map(int,input().split())
print(solve(p,s1,s2))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
507 | C | Guess Your Way Out! | PROGRAMMING | 1,700 | [
"implementation",
"math",
"trees"
] | null | null | Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the leaf nodes from the left t... | Input consists of two integers *h*,<=*n* (1<=≤<=*h*<=≤<=50, 1<=≤<=*n*<=≤<=2*h*). | Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm. | [
"1 2\n",
"2 3\n",
"3 6\n",
"10 1024\n"
] | [
"2",
"5",
"10",
"2046"
] | A perfect binary tree of height *h* is a binary tree consisting of *h* + 1 levels. Level 0 consists of a single node called root, level *h* consists of 2<sup class="upper-index">*h*</sup> nodes called leaves. Each node that is not a leaf has exactly two children, left and right one.
Following picture illustrates the ... | 1,500 | [
{
"input": "1 2",
"output": "2"
},
{
"input": "2 3",
"output": "5"
},
{
"input": "3 6",
"output": "10"
},
{
"input": "10 1024",
"output": "2046"
},
{
"input": "10 577",
"output": "1345"
},
{
"input": "11 550",
"output": "408"
},
{
"input": ... | 1,683,571,349 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | h, n = map(int, input().split())
s, k = h, 2
n += (1 << h) - 1
for i in range(h):
if (n & k) ^ ((n << 1) & k) == 0: s += k - 1
k <<= 1
print(s) | Title: Guess Your Way Out!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree ... | ```python
h, n = map(int, input().split())
s, k = h, 2
n += (1 << h) - 1
for i in range(h):
if (n & k) ^ ((n << 1) & k) == 0: s += k - 1
k <<= 1
print(s)
``` | 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,521,361,955 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 78 | 7,065,600 | n = int(input())
a = input().split(" ")
c = 1
e = 0
sum = 0
ext = 0
for i in range(n):
a[i] = int(a[i])
if(n>=3):
while(c < n-1):
sum = a[c-1]+a[c+1]-a[c]
Max = max(a[c-1],a[c],a[c+1])
Min = min(a[c-1],a[c],a[c+1])
if(sum < Min or sum > Max):
e = e + 1
c = c + 1
print(e... | 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())
a = input().split(" ")
c = 1
e = 0
sum = 0
ext = 0
for i in range(n):
a[i] = int(a[i])
if(n>=3):
while(c < n-1):
sum = a[c-1]+a[c+1]-a[c]
Max = max(a[c-1],a[c],a[c+1])
Min = min(a[c-1],a[c],a[c+1])
if(sum < Min or sum > Max):
e = e + 1
c = c + ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis.
Petya decided to compress tables. He is given a table *a* consisting of *n* rows and *... | The first line of the input contains two integers *n* and *m* (, the number of rows and the number of columns of the table respectively.
Each of the following *n* rows contain *m* integers *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109) that are the values in the table. | Output the compressed table in form of *n* lines each containing *m* integers.
If there exist several answers such that the maximum number in the compressed table is minimum possible, you are allowed to output any of them. | [
"2 2\n1 2\n3 4\n",
"4 3\n20 10 30\n50 40 30\n50 60 70\n90 80 70\n"
] | [
"1 2\n2 3\n",
"2 1 3\n5 4 3\n5 6 7\n9 8 7\n"
] | In the first sample test, despite the fact *a*<sub class="lower-index">1, 2</sub> ≠ *a*<sub class="lower-index">21</sub>, they are not located in the same row or column so they may become equal after the compression. | 0 | [] | 1,603,653,181 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 108 | 307,200 | M, N = map(int, input().split())
maxtrix = []
for _ in range(M):
matrix.append(list(map(int, input().split())))
rank = {i: 0 for i in range(-N, M)}
def find(x):
if uf[x] != x:
uf[x] = find(uf[x])
return uf[x]
dic = collections.defaultdict(list)
ans = [[0] * N for _ in range(M)]
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name di... | ```python
M, N = map(int, input().split())
maxtrix = []
for _ in range(M):
matrix.append(list(map(int, input().split())))
rank = {i: 0 for i in range(-N, M)}
def find(x):
if uf[x] != x:
uf[x] = find(uf[x])
return uf[x]
dic = collections.defaultdict(list)
ans = [[0] * N for _ in r... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
196 | B | Infinite Maze | PROGRAMMING | 2,000 | [
"dfs and similar",
"graphs"
] | null | null | We've got a rectangular *n*<=×<=*m*-cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on this plane cell (*x*,<=*y*) is a wall if and only if cell is a wall.
In this problem is a remainde... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1500) — the height and the width of the maze that the boy used to cyclically tile the plane.
Each of the next *n* lines contains *m* characters — the description of the labyrinth. Each character is either a "#", that marks a wall, a ... | Print "Yes" (without the quotes), if the little boy can walk infinitely far from the starting point. Otherwise, print "No" (without the quotes). | [
"5 4\n##.#\n##S#\n#..#\n#.##\n#..#\n",
"5 4\n##.#\n##S#\n#..#\n..#.\n#.##\n"
] | [
"Yes\n",
"No\n"
] | In the first sample the little boy can go up for infinitely long as there is a "clear path" that goes vertically. He just needs to repeat the following steps infinitely: up, up, left, up, up, right, up.
In the second sample the vertical path is blocked. The path to the left doesn't work, too — the next "copy" of the m... | 1,000 | [] | 1,540,557,716 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 |
n, m = [int(x) for x in input().split(" ")]
data = []
was = {}
walls = {}
start = 0, 0
for row in range(n):
tmp = [0] * m
for col, e in enumerate(input()):
if e == 'S':
start = row, col
if e == '#':
tmp[col] = -1
data.append(tmp)
def dfs(row, col):
if -1 ... | Title: Infinite Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got a rectangular *n*<=×<=*m*-cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on th... | ```python
n, m = [int(x) for x in input().split(" ")]
data = []
was = {}
walls = {}
start = 0, 0
for row in range(n):
tmp = [0] * m
for col, e in enumerate(input()):
if e == 'S':
start = row, col
if e == '#':
tmp[col] = -1
data.append(tmp)
def dfs(row, col):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the p... | The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"i... | 1,665,056,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | s=input()
l=[]
for i in range(0,len(s),2):
l.append(s[i])
if l[0:len(l)//2] == (l[len(l)//2:]):
print("First")
else:
print("Second") | Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The... | ```python
s=input()
l=[]
for i in range(0,len(s),2):
l.append(s[i])
if l[0:len(l)//2] == (l[len(l)//2:]):
print("First")
else:
print("Second")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,609,424,395 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 10,342,400 | n = int(input())
arr = list(map(int, input().split()))
cnt = 1
i=1
while i<n:
if arr[i]>=arr[i-1]:
cnt+=1
else:
break
i+=1
flag=True
if i==n:
flag=True
elif arr[i]>arr[0]:
flag=False
else:
while i<n-1:
if arr[i]>arr[i+1]:
flag=False
... | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
n = int(input())
arr = list(map(int, input().split()))
cnt = 1
i=1
while i<n:
if arr[i]>=arr[i-1]:
cnt+=1
else:
break
i+=1
flag=True
if i==n:
flag=True
elif arr[i]>arr[0]:
flag=False
else:
while i<n-1:
if arr[i]>arr[i+1]:
flag=False... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
60 | A | Where Are My Flakes? | PROGRAMMING | 1,300 | [
"implementation",
"two pointers"
] | A. Where Are My Flakes? | 2 | 256 | One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are numbered from 1 to *n* from the left to the right. The roommate left hints like "Hidden to the left o... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*m*<=≤<=1000) which represent the number of boxes and the number of hints correspondingly. Next *m* lines contain hints like "To the left of *i*" and "To the right of *i*", where *i* is integer (1<=≤<=*i*<=≤<=*n*). The hints may coincide. | The answer should contain exactly one integer — the number of boxes that should necessarily be checked or "-1" if the hints are contradictory. | [
"2 1\nTo the left of 2\n",
"3 2\nTo the right of 1\nTo the right of 2\n",
"3 1\nTo the left of 3\n",
"3 2\nTo the left of 2\nTo the right of 1\n"
] | [
"1\n",
"1\n",
"2\n",
"-1\n"
] | none | 500 | [
{
"input": "2 1\nTo the left of 2",
"output": "1"
},
{
"input": "3 2\nTo the right of 1\nTo the right of 2",
"output": "1"
},
{
"input": "3 1\nTo the left of 3",
"output": "2"
},
{
"input": "3 2\nTo the left of 2\nTo the right of 1",
"output": "-1"
},
{
"input": "... | 1,463,058,100 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 124 | 5,120,000 | n,m = map(int,input().split())
kanan = 0
kiri = n+1
for i in range(m):
hint = str(input()).upper()
rl = hint[7]
if rl == 'R':
temp = int(hint[16:])
if temp>kanan:
kanan = temp
else :
temp = int(hint[15:])
if temp<kiri:
kiri = temp
cek... | Title: Where Are My Flakes?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are... | ```python
n,m = map(int,input().split())
kanan = 0
kiri = n+1
for i in range(m):
hint = str(input()).upper()
rl = hint[7]
if rl == 'R':
temp = int(hint[16:])
if temp>kanan:
kanan = temp
else :
temp = int(hint[15:])
if temp<kiri:
kiri =... | 3.959463 | 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,610,952,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a = int(input())
b = [int(x) for x in input().split()]
index = []
li =0
mn = min(b)
for i in range(a):
if b[i]==mn:
index.append(i-li)
li = i
print(min(index))
# [1, 23, 32, 54, 56, 58, 71, 73, 79, 101, 110, 143, 153, 162, 163, 185, 188, 201, 223, 241]
# [1, 22, 9, 22, 2, 2, 13, 2, 6,... | 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
a = int(input())
b = [int(x) for x in input().split()]
index = []
li =0
mn = min(b)
for i in range(a):
if b[i]==mn:
index.append(i-li)
li = i
print(min(index))
# [1, 23, 32, 54, 56, 58, 71, 73, 79, 101, 110, 143, 153, 162, 163, 185, 188, 201, 223, 241]
# [1, 22, 9, 22, 2, 2,... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "08... | 1,629,115,757 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 186 | 20,172,800 | #My last problem in Riverside
n = int(input())
s = input()
b = "-".join(s[i:i+2]for i in range(0, n, 2))
if n % 2 == 1:
b = b[:-2] + b[-1:]
print(b) | Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
#My last problem in Riverside
n = int(input())
s = input()
b = "-".join(s[i:i+2]for i in range(0, n, 2))
if n % 2 == 1:
b = b[:-2] + b[-1:]
print(b)
``` | 3.915925 | MatrixStudio/Codeforces-Python-Submissions |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,662,043,912 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,m=map(int,input().split())
count=n+(n//2)
print(count) | Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
n,m=map(int,input().split())
count=n+(n//2)
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
933 | A | A Twisty Movement | PROGRAMMING | 1,800 | [
"dp"
] | null | null | A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence.
The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*). | Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. | [
"4\n1 2 1 2\n",
"10\n1 1 2 2 2 1 1 2 2 1\n"
] | [
"4\n",
"9\n"
] | In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4.
In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. | 500 | [
{
"input": "4\n1 2 1 2",
"output": "4"
},
{
"input": "10\n1 1 2 2 2 1 1 2 2 1",
"output": "9"
},
{
"input": "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 ... | 1,520,267,444 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 61 | 5,734,400 | n = int(input())
a = list(map(int, input().split()))
l = 0
d = [0 for i in range(4)]
it = 0
mx = 1
if a[0] == 1:
d[0] = 1
else:
d[1] = 1
it += 1
for i in range(1, n):
if a[i] != a[i - 1]:
it += 1
if it == 4:
l = i
d[0] = d[3]
d[1] = d[2] = d[3] = 0
... | Title: A Twisty Movement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A perform... | ```python
n = int(input())
a = list(map(int, input().split()))
l = 0
d = [0 for i in range(4)]
it = 0
mx = 1
if a[0] == 1:
d[0] = 1
else:
d[1] = 1
it += 1
for i in range(1, n):
if a[i] != a[i - 1]:
it += 1
if it == 4:
l = i
d[0] = d[3]
d[1] = d[2] =... | -1 | 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,462,202,743 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 4,608,000 | w = str(input())
x = ""
crw = "hello"
i = 0
for ch in w:
if ch == crw[i]:
x += ch
i += 1
if x == "hello":
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
w = str(input())
x = ""
crw = "hello"
i = 0
for ch in w:
if ch == crw[i]:
x += ch
i += 1
if x == "hello":
print("YES")
else:
print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 ... | 1,685,515,425 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | """
A. Dreamoon and Stairs: implementation, math
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output
Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move.
Dreamoon wants the number of moves to be a multiple of an integer m.
... | Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb ... | ```python
"""
A. Dreamoon and Stairs: implementation, math
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output
Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move.
Dreamoon wants the number of moves to be a multiple of an i... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,697,823,931 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 0 | a = int(input()[2])
b = input().split()
c = [int(x) for x in b]
w = 0
for e in c:
if e > a:
w +=2
else:
w+=1
print(w)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
a = int(input()[2])
b = input().split()
c = [int(x) for x in b]
w = 0
for e in c:
if e > a:
w +=2
else:
w+=1
print(w)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=<<=*y**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *x**j... | The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer *k* (1<=≤<=*k*<=≤<=105). | Print the string Anna and Maria need — the *k*-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than *k*, print a string saying "No such line." (without the quotes). | [
"aa\n2\n",
"abc\n5\n",
"abab\n7\n"
] | [
"a\n",
"bc\n",
"b\n"
] | In the second sample before string "bc" follow strings "a", "ab", "abc", "b". | 0 | [
{
"input": "aa\n2",
"output": "a"
},
{
"input": "abc\n5",
"output": "bc"
},
{
"input": "abab\n7",
"output": "b"
},
{
"input": "codeforces\n1",
"output": "c"
},
{
"input": "cccc\n8",
"output": "ccc"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n27",
"o... | 1,671,503,815 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 15,052,800 | from queue import PriorityQueue
string = input()
kth_smallest = int(input())
length = len(string)
if kth_smallest > length * (length + 1) / 2:
print("No such line.")
quit()
char_indices = [(string[i], i) for i in range(length)]
pq = PriorityQueue()
for char_index in char_indices:
pq.put(char_index)
while... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min... | ```python
from queue import PriorityQueue
string = input()
kth_smallest = int(input())
length = len(string)
if kth_smallest > length * (length + 1) / 2:
print("No such line.")
quit()
char_indices = [(string[i], i) for i in range(length)]
pq = PriorityQueue()
for char_index in char_indices:
pq.put(char_ind... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
400 | A | Inna and Choose Options | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The ... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line b... | [
"4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n"
] | [
"3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n"
] | none | 500 | [
{
"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO",
"output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"
},
{
"input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX",
"output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1"
},
{
"input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\n... | 1,694,324,991 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 108 | 2,355,200 | t = int(input())
for l in range(t):
s = input()
l = []
for i in range(1, 13):
if 12 % i == 0:
for j in range(12 // i):
c = ""
for k in range(i):
c = c + s[(k * (12 // i)) + j]
if c == "X" * i:
l.append(f"{i}x{12 // i}")
print(len(l), " ".join(list(map... | Title: Inna and Choose Options
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game.... | ```python
t = int(input())
for l in range(t):
s = input()
l = []
for i in range(1, 13):
if 12 % i == 0:
for j in range(12 // i):
c = ""
for k in range(i):
c = c + s[(k * (12 // i)) + j]
if c == "X" * i:
l.append(f"{i}x{12 // i}")
print(len(l), " ".joi... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-... | 1,595,899,084 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 186 | 6,963,200 | x,y=map(int,input().split())
if x>0 and y>0:
c=x+y
x1=0
y1=c
x2=c
y2=0
elif x<0 and y>0:
c=y-x
x1=-c
y1=0
x2=0
y2=c
elif x<0 and y<0:
c=-y-x
x1=-c
y1=0
x2=0
y2=-c
else:
c=x-y
x1=0
y1=-c
x2=c
y2=0
print(f"{x1} {y1} {... | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ... | ```python
x,y=map(int,input().split())
if x>0 and y>0:
c=x+y
x1=0
y1=c
x2=c
y2=0
elif x<0 and y>0:
c=y-x
x1=-c
y1=0
x2=0
y2=c
elif x<0 and y<0:
c=-y-x
x1=-c
y1=0
x2=0
y2=-c
else:
c=x-y
x1=0
y1=-c
x2=c
y2=0
print(f"{... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,656,649,999 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | # import sys
# sys.stdin = open("25A.in", "r")
n = int(input())
nums = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
num = nums[i]
if num % 2 == 0:
# print(num)
# print(i)
# print()
even.append([num, i])
else:
# print(num)... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
# import sys
# sys.stdin = open("25A.in", "r")
n = int(input())
nums = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
num = nums[i]
if num % 2 == 0:
# print(num)
# print(i)
# print()
even.append([num, i])
else:
# ... | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,432,882,799 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 154 | 0 | ins=input().split()
n, x, y=int(ins[0]), int(ins[1]), int(ins[2])
l, r=0, 100000000000000
while l<r:
c=(l+r)//2
if ((c+x)/n)*100>=y: r=c
else: l=c+1
print(l)
| Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
ins=input().split()
n, x, y=int(ins[0]), int(ins[1]), int(ins[2])
l, r=0, 100000000000000
while l<r:
c=(l+r)//2
if ((c+x)/n)*100>=y: r=c
else: l=c+1
print(l)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
185 | A | Plant | PROGRAMMING | 1,300 | [
"math"
] | null | null | Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7). | [
"1\n",
"2\n"
] | [
"3\n",
"10\n"
] | The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. | 500 | [
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "10"
},
{
"input": "385599124",
"output": "493875375"
},
{
"input": "989464295",
"output": "31966163"
},
{
"input": "376367012",
"output": "523204186"
},
{
"input": "529357306",
"output": "... | 1,616,263,920 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 8 | 312 | 5,324,800 | def F(a, b, c):
if b == 0:
return 1
elif b == 1:
return a % c
elif b % 2 == 0:
m = F(a, b // 2, c)
return (m * m) % c
else:
m = F(a, b // 2, c)
return (((m * m) % c) * a) % c
n = int(input())
x = F(2, 2 * n - 1, 1000000007)
y = F(2, n - 1, ... | Title: Plant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will poi... | ```python
def F(a, b, c):
if b == 0:
return 1
elif b == 1:
return a % c
elif b % 2 == 0:
m = F(a, b // 2, c)
return (m * m) % c
else:
m = F(a, b // 2, c)
return (((m * m) % c) * a) % c
n = int(input())
x = F(2, 2 * n - 1, 1000000007)
y = F(... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,685,091,010 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a = input().split(" ")
n = int(a[0])
m = int(a[1])
b = input().split(" ")
for i in range(m):
b[i] = int(b[i])
ar = sorted(b)
print(ar)
output = 1001 #(4 ≤ fi ≤ 1000)
for i in range(m-n+1):
output = min(output, (ar[i+n-1]-ar[i]))# tìm khoảng cách bé nhất
print(output) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
a = input().split(" ")
n = int(a[0])
m = int(a[1])
b = input().split(" ")
for i in range(m):
b[i] = int(b[i])
ar = sorted(b)
print(ar)
output = 1001 #(4 ≤ fi ≤ 1000)
for i in range(m-n+1):
output = min(output, (ar[i+n-1]-ar[i]))# tìm khoảng cách bé nhất
print(output)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
... | 1,518,323,698 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 14,028,800 | from sys import stdin
def read():
line = stdin.readline();
if line == "":
exit();
return line;
def main():
while True:
read();
a = list( map( int, read().split() ) );
x = min( a );
for y in a:
if (y%x) > 0:
x = -1
break;
print( x );
main();
| Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that ... | ```python
from sys import stdin
def read():
line = stdin.readline();
if line == "":
exit();
return line;
def main():
while True:
read();
a = list( map( int, read().split() ) );
x = min( a );
for y in a:
if (y%x) > 0:
x = -1
break;
print( x );
main();
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,697,466,942 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 5,120,000 | n = int(input())
b = input()
v = 1
for i in range(n-1):
a = input()
if a[0] == b[1]:
v+=1
b = a
print(v) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input())
b = input()
v = 1
for i in range(n-1):
a = input()
if a[0] == b[1]:
v+=1
b = a
print(v)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,686,009,338 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ --... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
#####... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,667,058,101 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | inp = int(input())
names = set()
for i in range(inp):
if i in names:
print("YES")
else:
print("NO")
names.add(i)
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
inp = int(input())
names = set()
for i in range(inp):
if i in names:
print("YES")
else:
print("NO")
names.add(i)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,592,198,499 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | n = int(input())
numFreq = np.zeros(n+1, dtype=int)
num = list(map(int, input().split()))
cnt = 0
for i in range(len(num)):
if numFreq[num[i]] == 0:
cnt += 1
numFreq[num[i]] += 1
print(n - cnt) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n = int(input())
numFreq = np.zeros(n+1, dtype=int)
num = list(map(int, input().split()))
cnt = 0
for i in range(len(num)):
if numFreq[num[i]] == 0:
cnt += 1
numFreq[num[i]] += 1
print(n - cnt)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,681,468,648 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 204,800 | def function_oring (arr , l , r) :
mx = None
summ = 0
for i in arr [l : r]:
summ |= i
if mx is None or mx < summ :
mx = summ
return mx
n = int(input())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
mxor1 , mxor2 = None , None
oring1 ,... | Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
def function_oring (arr , l , r) :
mx = None
summ = 0
for i in arr [l : r]:
summ |= i
if mx is None or mx < summ :
mx = summ
return mx
n = int(input())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
mxor1 , mxor2 = None , None... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
576 | C | Points on Plane | PROGRAMMING | 2,100 | [
"constructive algorithms",
"divide and conquer",
"geometry",
"greedy",
"sortings"
] | null | null | On a plane are *n* points (*x**i*, *y**i*) with integer coordinates between 0 and 106. The distance between the two points with numbers *a* and *b* is said to be the following value: (the distance calculated by such formula is called Manhattan distance).
We call a hamiltonian path to be some permutation *p**i* of num... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106).
The *i*<=+<=1-th line contains the coordinates of the *i*-th point: *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=106).
It is guaranteed that no two points coincide. | Print the permutation of numbers *p**i* from 1 to *n* — the sought Hamiltonian path. The permutation must meet the inequality .
If there are multiple possible answers, print any of them.
It is guaranteed that the answer exists. | [
"5\n0 7\n8 10\n3 4\n5 0\n9 12\n"
] | [
"4 3 1 2 5 \n"
] | In the sample test the total distance is:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c772e61c616e1c27114e3facb9e6db6c5cf93b82.png" style="max-width: 100.0%;max-height: 100.0%;"/>
(|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 ... | 1,250 | [] | 1,699,221,863 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 124,518,400 | from sys import stdin,stdout
input = stdin.readline
def main():
#t = int(input())
t = 1
for z in range(t):
n = int(input())
#a,b,c = map(int,input().split())
#ai = list(map(int,input().split()))
pis = [list(map(int,input().split()))+[i+1] for i in range(n)]
... | Title: Points on Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On a plane are *n* points (*x**i*, *y**i*) with integer coordinates between 0 and 106. The distance between the two points with numbers *a* and *b* is said to be the following value: (the distance calculated by such fo... | ```python
from sys import stdin,stdout
input = stdin.readline
def main():
#t = int(input())
t = 1
for z in range(t):
n = int(input())
#a,b,c = map(int,input().split())
#ai = list(map(int,input().split()))
pis = [list(map(int,input().split()))+[i+1] for i in range(n... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,632,598,086 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 6,758,400 |
if __name__ == '__main__':
the_string=input()
left_bra=the_string.count("(")
right_bra=the_string.count(")")
result=min(right_bra,left_bra)
if(right_bra==left_bra):print(result+1)
else:
print(result*2)
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
if __name__ == '__main__':
the_string=input()
left_bra=the_string.count("(")
right_bra=the_string.count(")")
result=min(right_bra,left_bra)
if(right_bra==left_bra):print(result+1)
else:
print(result*2)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,613,359,450 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 409,600 | a=str(input())
import collections
s=collections.Counter(a)
b='nineteen'
ans=float("inf")
for i in b:
ans=min(ans,s[i])
print(ans) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
a=str(input())
import collections
s=collections.Counter(a)
b='nineteen'
ans=float("inf")
for i in b:
ans=min(ans,s[i])
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,597,794,525 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 93 | 0 | read = lambda: list(map(int, input().split()))
d1, d2, d3 = read()
min = min(2 * d1 + 2 * d2, d1 + d2 + d3, 2 * d1 + 2 * d3, 2 * d2 + 2 * d3)
print(min) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
read = lambda: list(map(int, input().split()))
d1, d2, d3 = read()
min = min(2 * d1 + 2 * d2, d1 + d2 + d3, 2 * d1 + 2 * d3, 2 * d2 + 2 * d3)
print(min)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.