contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
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 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,639,083,720 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 93 | 0 | import sys
def main():
inp = [[int(j) for j in i.split()] for i in sys.stdin.read().strip().split('\n')]
w = [[1,1,1,],[1,1,1,],[1,1,1,]]
for i in range(3):
for j in range(3):
n = inp[i][j]
if n%2:
w[i][j] = int(not w[i][j])
if i < 2... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
import sys
def main():
inp = [[int(j) for j in i.split()] for i in sys.stdin.read().strip().split('\n')]
w = [[1,1,1,],[1,1,1,],[1,1,1,]]
for i in range(3):
for j in range(3):
n = inp[i][j]
if n%2:
w[i][j] = int(not w[i][j])
... | 3 | |
1,003 | D | Coins and Queries | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).
Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the... | The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers o... | Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1. | [
"5 4\n2 4 8 2 4\n8\n5\n14\n10\n"
] | [
"1\n-1\n3\n2\n"
] | none | 0 | [
{
"input": "5 4\n2 4 8 2 4\n8\n5\n14\n10",
"output": "1\n-1\n3\n2"
},
{
"input": "3 3\n1 1 1\n1\n2\n3",
"output": "1\n2\n3"
},
{
"input": "4 1\n2 4 16 32\n14",
"output": "-1"
},
{
"input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16",
"output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\... | 1,635,144,368 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 8,192,000 | from collections import defaultdict as df
from math import *
from collections import Counter
def solve():
n, q = map(int, input().split())
ll = list(map(int, input().split()))
mp = Counter(ll)
ll = list(set(ll))
n = len(ll)
ll.sort()
for i in range(q):
x = int(input())
cnt = 0
f... | Title: Coins and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).
Polycarp wants to know answer... | ```python
from collections import defaultdict as df
from math import *
from collections import Counter
def solve():
n, q = map(int, input().split())
ll = list(map(int, input().split()))
mp = Counter(ll)
ll = list(set(ll))
n = len(ll)
ll.sort()
for i in range(q):
x = int(input())
cnt ... | 0 | |
347 | A | Difference Row | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000). | Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. | [
"5\n100 -100 50 0 -50\n"
] | [
"100 -50 0 50 -100 \n"
] | In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.
Sequence *x*<sub class="lower-inde... | 500 | [
{
"input": "5\n100 -100 50 0 -50",
"output": "100 -50 0 50 -100 "
},
{
"input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282",
"output": "963 -795 -367 -282 -49 -26 0 764 948 -939 "
},
{
"input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 ... | 1,427,292,204 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n = int(input())
m = list(map(int, input().split()))
m.sort()
m[m.index(max(m))], m[0] = m[0], m[m.index(max(m))]
m[m.index(min(m))], m[n-1] = m[n-1], m[m.index(min(m))]
print(m)
| Title: Difference Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote ... | ```python
n = int(input())
m = list(map(int, input().split()))
m.sort()
m[m.index(max(m))], m[0] = m[0], m[m.index(max(m))]
m[m.index(min(m))], m[n-1] = m[n-1], m[m.index(min(m))]
print(m)
``` | 0 | |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,630,365,121 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 93 | 20,172,800 | a,b,c,d = map(int,input().split())
print((a/b) / (1-(((d-c)/d) * ((b-a)/b)))) | Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a,b,c,d = map(int,input().split())
print((a/b) / (1-(((d-c)/d) * ((b-a)/b))))
``` | 3 | |
1,003 | F | Abbreviation | PROGRAMMING | 2,200 | [
"dp",
"hashing",
"strings"
] | null | null | You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words co... | The first line of the input contains one integer $n$ ($1 \le n \le 300$) — the number of words in the text.
The next line contains $n$ space-separated words of the text $w_1, w_2, \dots, w_n$. Each word consists only of lowercase Latin letters.
It is guaranteed that the length of text does not exceed $10^5$. | Print one integer — the minimum length of the text after at most one abbreviation. | [
"6\nto be or not to be\n",
"10\na ab a a b ab a a b c\n",
"6\naa bb aa aa bb bb\n"
] | [
"12\n",
"13\n",
"11\n"
] | In the first example you can obtain the text "TB or not TB".
In the second example you can obtain the text "a AAAB AAAB c".
In the third example you can obtain the text "AB aa AB bb". | 0 | [
{
"input": "6\nto be or not to be",
"output": "12"
},
{
"input": "10\na ab a a b ab a a b c",
"output": "13"
},
{
"input": "6\naa bb aa aa bb bb",
"output": "11"
},
{
"input": "45\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t... | 1,693,229,181 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 92 | 2,150,400 | # https://codeforces.com/contest/1003
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n = int(input())
s = input()
w = s.split()
max_savings = 0
for i in range(n - 1):
for j in range(i + 1, n):
if w[i] == w[j]:
k = 1
l = len(w[i])
while i + k < j ... | Title: Abbreviation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length... | ```python
# https://codeforces.com/contest/1003
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n = int(input())
s = input()
w = s.split()
max_savings = 0
for i in range(n - 1):
for j in range(i + 1, n):
if w[i] == w[j]:
k = 1
l = len(w[i])
while ... | 0 | |
454 | A | Little Pony and Crystal Mine | PROGRAMMING | 800 | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot... | The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | 500 | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**... | 1,587,132,263 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | a=int(input())
x=y=g=gg=int(1)
ss=q=int(0)
b=w=str("")
while x<=a:
b=b+"*"
w=w+"D"
x=x+1
s=t=int((a-1)/2)
r=a-2*t
print(s)
while y<=a:
c=str("")
c=b[0:s]
g=g+1
if g<=t+1:
s=s-1
else:
s=s+1
o=w[0:r]
print(c+o+c)
gg=gg+1
if gg<=int((a+1... | Title: Little Pony and Crystal Mine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You ... | ```python
a=int(input())
x=y=g=gg=int(1)
ss=q=int(0)
b=w=str("")
while x<=a:
b=b+"*"
w=w+"D"
x=x+1
s=t=int((a-1)/2)
r=a-2*t
print(s)
while y<=a:
c=str("")
c=b[0:s]
g=g+1
if g<=t+1:
s=s-1
else:
s=s+1
o=w[0:r]
print(c+o+c)
gg=gg+1
if gg... | 0 | |
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,621,570,030 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 154 | 512,000 | '''
R E X
Date - 20th May 2021
@author:
CodeForces -> kunalverma19
CodeChef -> kunalverma_19
AtCoder -> TLKunalVermaRX
'''
import sys
import re
import math
from collections import Counter
MOD = 1000000007
inp = lambda :map(int,input().split(' '))
ninp = lambda :int(input())
# sys.stdin=open("input.txt","r... | 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
'''
R E X
Date - 20th May 2021
@author:
CodeForces -> kunalverma19
CodeChef -> kunalverma_19
AtCoder -> TLKunalVermaRX
'''
import sys
import re
import math
from collections import Counter
MOD = 1000000007
inp = lambda :map(int,input().split(' '))
ninp = lambda :int(input())
# sys.stdin=open("inp... | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,667,330,186 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | n = list(map(int,input().split()))
flag = False
if len(n) == 2:
for i in n:
if i<=100 and i>=1:
flag = True
if flag == True:
print(min(n), (max(n) - min(n)) // 2)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
n = list(map(int,input().split()))
flag = False
if len(n) == 2:
for i in n:
if i<=100 and i>=1:
flag = True
if flag == True:
print(min(n), (max(n) - min(n)) // 2)
``` | 3 | |
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<... | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t... | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5... | 1,688,775,190 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 1,526 | 6,860,800 | s = input()
n = len(s)
m = int(input())
a = []
for i in range(n-1):
if s[i] == s[i+1]:
a.append(1)
else:
a.append(0)
p = [0]
for i in range(n-1):
p.append(p[-1] + a[i])
for _ in range(m):
l, r = map(int, input().split())
print(p[r-1] - p[l-1]) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ... | ```python
s = input()
n = len(s)
m = int(input())
a = []
for i in range(n-1):
if s[i] == s[i+1]:
a.append(1)
else:
a.append(0)
p = [0]
for i in range(n-1):
p.append(p[-1] + a[i])
for _ in range(m):
l, r = map(int, input().split())
print(p[r-1] - p[l-1])
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*.
A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), all integers there are distinct.
There is only one thing Petya likes more than p... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* space-separated integers *q*1,<=*q*2,<=...,<=*q**n* (1<=≤<=*q**i*<=≤<=*n*) — the permutation that Petya's got as a present. The third line contains Masha's permutation *s*, in the similar format.
It is guaranteed t... | If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes). | [
"4 1\n2 3 4 1\n1 2 3 4\n",
"4 1\n4 3 1 2\n3 4 2 1\n",
"4 3\n4 3 1 2\n3 4 2 1\n",
"4 2\n4 3 1 2\n2 1 4 3\n",
"4 1\n4 3 1 2\n2 1 4 3\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n"
] | In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before *k* moves were performed.
In the second sample the described situation is possible... | 0 | [
{
"input": "4 1\n2 3 4 1\n1 2 3 4",
"output": "NO"
},
{
"input": "4 1\n4 3 1 2\n3 4 2 1",
"output": "YES"
},
{
"input": "4 3\n4 3 1 2\n3 4 2 1",
"output": "YES"
},
{
"input": "4 2\n4 3 1 2\n2 1 4 3",
"output": "YES"
},
{
"input": "4 1\n4 3 1 2\n2 1 4 3",
"outp... | 1,689,595,340 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1689595320.2849913")# 1689595340.2883313 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*.
A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤... | ```python
print("_RANDOM_GUESS_1689595320.2849913")# 1689595340.2883313
``` | 0 | |
346 | A | Alice and Bob | PROGRAMMING | 1,600 | [
"games",
"math",
"number theory"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | 500 | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
... | 1,589,896,550 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 20 | 2,058 | 268,390,400 | from math import gcd
from sys import stdin
def main():
n = int(stdin.readline())
ar = list(map(int, stdin.readline().split()))
d = gcd(ar[0], ar[1])
for i in range(2, n):
d = gcd(ar[i], d)
ans = []
me = max(ar)
ci = 1
while d * ci <= me:
ans.append(d * ci)... | Title: Alice and Bob
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following ... | ```python
from math import gcd
from sys import stdin
def main():
n = int(stdin.readline())
ar = list(map(int, stdin.readline().split()))
d = gcd(ar[0], ar[1])
for i in range(2, n):
d = gcd(ar[i], d)
ans = []
me = max(ar)
ci = 1
while d * ci <= me:
ans.appe... | 0 | |
681 | B | Economy Game | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. | Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). | [
"1359257\n",
"17851817\n"
] | [
"YES",
"NO"
] | In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | 1,000 | [
{
"input": "1359257",
"output": "YES"
},
{
"input": "17851817",
"output": "NO"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "17851818",
"output": "YES"
},
{
"input": "438734347",
"output": "YES"
},
{
"input": "43873430",
"output": "YES... | 1,589,095,221 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 280 | 64,614,400 | n = int(input())
a = 1234567
b = 123456
c = 1234
s = set([i*a+j*b+k*c for i in range(100) for j in range(100) for k in range(100)])
if n in s:
print("YES")
else:
print("NO")
| Title: Economy Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.... | ```python
n = int(input())
a = 1234567
b = 123456
c = 1234
s = set([i*a+j*b+k*c for i in range(100) for j in range(100) for k in range(100)])
if n in s:
print("YES")
else:
print("NO")
``` | 0 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,698,846,676 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | y=1
m,n=map(int,input().split())
if m==n:
print(1)
elif m>n:
print(0)
else:
while(m<n):
m=m+3*y
n=n+2*y
y+=1
print(y) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
y=1
m,n=map(int,input().split())
if m==n:
print(1)
elif m>n:
print(0)
else:
while(m<n):
m=m+3*y
n=n+2*y
y+=1
print(y)
``` | 0 | |
198 | A | About Bacteria | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginning of the first experiment there is a single bacterium in the test tub... | The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly. | Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube. | [
"3 1 3 5\n",
"1 4 4 7\n",
"2 2 4 100\n"
] | [
"2",
"3",
"0"
] | none | 500 | [
{
"input": "3 1 3 5",
"output": "2"
},
{
"input": "1 4 4 7",
"output": "3"
},
{
"input": "2 2 4 100",
"output": "0"
},
{
"input": "1 2 3 100",
"output": "0"
},
{
"input": "10 10 10 123456",
"output": "6"
},
{
"input": "847 374 283 485756",
"output"... | 1,672,030,136 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 1,536,000 | def ss(k,x,b,n):
if k==1:
return x+n*b
z = pow(k,n)*x+b*(pow(k,n)-1)//(k-1)+b
return z
k,b,n,t = map(int,input().split())
z = ss(k,1,b,n)
if t==1:
print(n)
else:
z1 = t
count = 0
while count<=n:
if z1>=z:
print(count)
break
... | Title: About Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the s... | ```python
def ss(k,x,b,n):
if k==1:
return x+n*b
z = pow(k,n)*x+b*(pow(k,n)-1)//(k-1)+b
return z
k,b,n,t = map(int,input().split())
z = ss(k,1,b,n)
if t==1:
print(n)
else:
z1 = t
count = 0
while count<=n:
if z1>=z:
print(count)
br... | 0 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,696,402,460 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | n=int(input())
if n%4==0 or n%7==0 or n%47==0 or n%74==0:
print("YES")
else:
string=str(n)
check=True
for s in string:
if s=='4' or s=='7':
check=True
else:
print("NO")
check=False
break
if check==True:
print("YES"... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n=int(input())
if n%4==0 or n%7==0 or n%47==0 or n%74==0:
print("YES")
else:
string=str(n)
check=True
for s in string:
if s=='4' or s=='7':
check=True
else:
print("NO")
check=False
break
if check==True:
p... | 3 | |
993 | A | Two Squares | PROGRAMMING | 1,600 | [
"geometry",
"implementation"
] | null | null | You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the ... | The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the ... | Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower). | [
"0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n",
"0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n",
"6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples: | 500 | [
{
"input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1",
"output": "YES"
},
{
"input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1",
"output": "NO"
},
{
"input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7",
"output": "YES"
},
{
"input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8",
"output": "YES"
},
... | 1,639,532,188 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 124 | 171 | 2,764,800 | def outp(v1,v2):
a1,a2=v1
b1,b2=v2
det = a1*b2-a2*b1
return 'M' if det==0 else ('L' if det>0 else 'R')
def check(p,PS):
sides = {'M':0,'L':0,'R':0}
for i in range(4):
v1 = [PS[i+1][0]-PS[i][0],PS[i+1][1]-PS[i][1]]
v2 = [p[0]-PS[i][0],p[1]-PS[i][1]]
sides[outp(v1,v2)] += 1
return n... | Title: Two Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered t... | ```python
def outp(v1,v2):
a1,a2=v1
b1,b2=v2
det = a1*b2-a2*b1
return 'M' if det==0 else ('L' if det>0 else 'R')
def check(p,PS):
sides = {'M':0,'L':0,'R':0}
for i in range(4):
v1 = [PS[i+1][0]-PS[i][0],PS[i+1][1]-PS[i][1]]
v2 = [p[0]-PS[i][0],p[1]-PS[i][1]]
sides[outp(v1,v2)] += 1
... | 3 | |
660 | A | Co-prime Array | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values shoul... | [
"3\n2 7 28\n"
] | [
"1\n2 7 9 28\n"
] | none | 0 | [
{
"input": "3\n2 7 28",
"output": "1\n2 7 1 28"
},
{
"input": "1\n1",
"output": "0\n1"
},
{
"input": "1\n548",
"output": "0\n548"
},
{
"input": "1\n963837006",
"output": "0\n963837006"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0\n1 1 1 1 1 1 1 1 1 1"... | 1,572,933,017 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 140 | 0 | import math
n = int(input())
a = list(map(int,input().split()))
i = 0
cot= 0
for i in range (1, n):
delit = 1
vsedel1 = []
vsedel2 = []
while delit <= math.sqrt(a[i-1]):
if (a[i-1]) % delit == 0:
vsedel1.append(delit)
if (a[i-1])//delit != math.sqrt((a[i-1])):... | Title: Co-prime Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
A... | ```python
import math
n = int(input())
a = list(map(int,input().split()))
i = 0
cot= 0
for i in range (1, n):
delit = 1
vsedel1 = []
vsedel2 = []
while delit <= math.sqrt(a[i-1]):
if (a[i-1]) % delit == 0:
vsedel1.append(delit)
if (a[i-1])//delit != math.sqrt(... | 0 | |
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards wi... | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20... | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output"... | 1,585,623,888 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 139 | 409,600 | def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())
def L(): return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
a=L()
suma=sum(a)
cnt=Counter(a)
ans=suma
for i in cnt:
... | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers... | ```python
def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())
def L(): return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
a=L()
suma=sum(a)
cnt=Counter(a)
ans=suma
for i in... | 3 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,644,936,468 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 46 | 0 | k = int(input())
if k>18:
print(-1)
else:
eight = k//2
nine = k%2
s = ""
for i in range(eight):
s+='8'
for i in range(nine):
s+='9'
print(s) | Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
k = int(input())
if k>18:
print(-1)
else:
eight = k//2
nine = k%2
s = ""
for i in range(eight):
s+='8'
for i in range(nine):
s+='9'
print(s)
``` | 0 | |
409 | D | Big Data | PROGRAMMING | 1,700 | [
"*special"
] | null | null | Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts:
- ... | The input will contain a single integer between 1 and 16. | Output a single integer. | [
"1\n",
"7\n"
] | [
"1\n",
"0\n"
] | none | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "0"
},
{
"input": "13",
"output": "1"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "16",
"output": "0"
},
{
"input": "11",
"output": "0"
},
... | 1,652,880,892 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 4,300,800 | input()
print(1) | Title: Big Data
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift ... | ```python
input()
print(1)
``` | 0 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,698,591,900 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=input()
ans=0
t=True
for i in n:
if t:
t=False
if i=='9':
ans=(ans*10)+int(i)
else:
ans=(ans*10)+min(int(i),9-int(i))
ans=(ans*10)+min(int(i),9-int(i))
print(ans) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
n=input()
ans=0
t=True
for i in n:
if t:
t=False
if i=='9':
ans=(ans*10)+int(i)
else:
ans=(ans*10)+min(int(i),9-int(i))
ans=(ans*10)+min(int(i),9-int(i))
print(ans)
``` | 0 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,672,199,271 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 409,600 | import fractions
y, w = input().split()
c1 = int(y) - 1
c2 = int(w) - 1
d = 0
if y or w == 1:
print(0)
elif y >= w:
d = c1 / 6
print(fractions.Fraction(d).limit_denominator())
elif y <= w:
d = c2 / 6
print(fractions.Fraction(d).limit_denominator())
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
import fractions
y, w = input().split()
c1 = int(y) - 1
c2 = int(w) - 1
d = 0
if y or w == 1:
print(0)
elif y >= w:
d = c1 / 6
print(fractions.Fraction(d).limit_denominator())
elif y <= w:
d = c2 / 6
print(fractions.Fraction(d).limit_denominator())
``` | 0 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,674,648,108 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | import math
n=int(input())
m=int(input())
a=int(input())
b=math.ceil(n/a)*math.ceil(m/a)
print(b) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
n=int(input())
m=int(input())
a=int(input())
b=math.ceil(n/a)*math.ceil(m/a)
print(b)
``` | -1 |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,599,024,787 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 108 | 0 | import math
def prime(n):
test=0
for i in range(2,math.ceil(n**0.5)+1):
if n%i==0:
test=1
break
if test:
return False
return True
n=int(input())
if n==1:
print(3)
else:
i=1
x=n*i+1
while prime(x):
i+=1
x... | Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
import math
def prime(n):
test=0
for i in range(2,math.ceil(n**0.5)+1):
if n%i==0:
test=1
break
if test:
return False
return True
n=int(input())
if n==1:
print(3)
else:
i=1
x=n*i+1
while prime(x):
i+=1
... | 0 | |
74 | A | Room Leader | PROGRAMMING | 1,000 | [
"implementation"
] | A. Room Leader | 2 | 256 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five prob... | The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number o... | Print on the single line the handle of the room leader. | [
"5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n"
] | [
"tourist"
] | The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist. | 500 | [
{
"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0",
"output": "tourist"
},
{
"input": "1\nA 0 0 200 0 0 0 0",
"output": "A"
},
{
"input": "2\n12345678901234567890 1 0... | 1,627,365,715 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 124 | 6,758,400 | n = int(input())
m = 0
name = ""
for i in range(n):
handle, *t = input().split()
plus, minus, *score = map(int, t)
totalScore = sum(score) + 100 * plus + 50 * minus
if totalScore > m:
m = totalScore
name = handle
print(name)
| Title: Room Leader
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains e... | ```python
n = int(input())
m = 0
name = ""
for i in range(n):
handle, *t = input().split()
plus, minus, *score = map(int, t)
totalScore = sum(score) + 100 * plus + 50 * minus
if totalScore > m:
m = totalScore
name = handle
print(name)
``` | 0 |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,695,102,299 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | expression = input("Enter your expression: "33)
numbers = [int(num) for num in expression.split('+')]
numbers.sort()
print('+'.join(map(str, numbers)))
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
expression = input("Enter your expression: "33)
numbers = [int(num) for num in expression.split('+')]
numbers.sort()
print('+'.join(map(str, numbers)))
``` | -1 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,692,626,688 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 92 | 2,150,400 | n=input()
s=""
for j in n:
if j == 'Q' or j == "A":
s+=j
c=1
count=0
l=[]
for i in range(len(s)-1):
if s[i] == 'Q' and s[i+1] == 'A':
for j in range(i+1, len(s)):
if s[j] =='Q':
l.append(str(i)+str(i+1)+str(j))
if s[i] == 'Q':
for j in range(i+1, len(s)):
... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
n=input()
s=""
for j in n:
if j == 'Q' or j == "A":
s+=j
c=1
count=0
l=[]
for i in range(len(s)-1):
if s[i] == 'Q' and s[i+1] == 'A':
for j in range(i+1, len(s)):
if s[j] =='Q':
l.append(str(i)+str(i+1)+str(j))
if s[i] == 'Q':
for j in range(i+1,... | -1 | |
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,586,607,976 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 216 | 0 | w=input()
u=0
l=0
for c in w:
uni=ord(c)
if uni>= 65 and uni<= 90:
u+=1
else:
l+=1
if u>l:
print(w.upper())
else:
print(w.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
w=input()
u=0
l=0
for c in w:
uni=ord(c)
if uni>= 65 and uni<= 90:
u+=1
else:
l+=1
if u>l:
print(w.upper())
else:
print(w.lower())
``` | 3.946 |
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w... | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ... | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input"... | 1,689,395,849 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | MAXN = 55
n, m = map(int, input().split())
s = [input() for _ in range(n)]
minrow = MAXN
maxrow = -1
mincolumn = MAXN
maxcolumn = -1
for i in range(n):
for j in range(m):
if s[i][j] == '.':
continue
minrow = min(minrow, i)
mincolumn = min(mincolumn, j)
... | Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe... | ```python
MAXN = 55
n, m = map(int, input().split())
s = [input() for _ in range(n)]
minrow = MAXN
maxrow = -1
mincolumn = MAXN
maxcolumn = -1
for i in range(n):
for j in range(m):
if s[i][j] == '.':
continue
minrow = min(minrow, i)
mincolumn = min(mincolumn, j)... | 3.969 |
158 | B | Taxi | PROGRAMMING | 1,100 | [
"*special",
"greedy",
"implementation"
] | null | null | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers.... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group. | Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus. | [
"5\n1 2 4 3 3\n",
"8\n2 3 4 4 2 1 3 1\n"
] | [
"4\n",
"5\n"
] | In the first test we can sort the children into four cars like this:
- the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly).
There a... | 1,000 | [
{
"input": "5\n1 2 4 3 3",
"output": "4"
},
{
"input": "8\n2 3 4 4 2 1 3 1",
"output": "5"
},
{
"input": "5\n4 4 4 4 4",
"output": "5"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "4\n3 ... | 1,696,526,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | passen = list()
t = int(input())
mylist = list(map(int,input().strip().split()))
comp = list()
def comps(n):
i = 0
print
while i < len(n):
r = len(n)
while 4 in n:
l = n.index(4)
passen.append(4)
n[l] = 0
c = 4 - n[i... | Title: Taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpu... | ```python
passen = list()
t = int(input())
mylist = list(map(int,input().strip().split()))
comp = list()
def comps(n):
i = 0
print
while i < len(n):
r = len(n)
while 4 in n:
l = n.index(4)
passen.append(4)
n[l] = 0
c... | 0 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,677,604,817 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s = input()
count = 1
for i in range(len(s)):
if i < len(s) - 1:
if s[i] == s[i+ ]:
count = count + 1
if count == 7:
result = "yes"
break
else:
count = 0
else:
result = "No"
print(result) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
s = input()
count = 1
for i in range(len(s)):
if i < len(s) - 1:
if s[i] == s[i+ ]:
count = count + 1
if count == 7:
result = "yes"
break
else:
count = 0
else:
result = "No"
print(result)
``` | -1 |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,481,992,866 | 366 | Python 3 | OK | TESTS | 28 | 62 | 4,608,000 | s = list(input())
words = []
words.append("".join(s))
for a in range(len(s)):
s.insert(0, s[-1])
s.pop(-1)
words.append("".join(s))
print(len(set(words)))
| Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
s = list(input())
words = []
words.append("".join(s))
for a in range(len(s)):
s.insert(0, s[-1])
s.pop(-1)
words.append("".join(s))
print(len(set(words)))
``` | 3 | |
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f... | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the numbe... | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se... | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output... | 1,577,257,231 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 171 | 8,806,400 | n = [int(x) for x in input().split()]
num = int(input())
acc = [int(x) for x in input().split()]
count = 0
for i in acc:
if(n[1]<i and n[2]>i):
count+=1
print(count) | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and... | ```python
n = [int(x) for x in input().split()]
num = int(input())
acc = [int(x) for x in input().split()]
count = 0
for i in acc:
if(n[1]<i and n[2]>i):
count+=1
print(count)
``` | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,699,493,817 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n = int(input()) # Read the number of lines to follow
matrix = []
res = 0
for _ in range(n):
# For each line, read the line, split by spaces, and convert each to an integer
row = list(map(int, input().split()))
if (sum(row) >= 2):
res += 1
print(res)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input()) # Read the number of lines to follow
matrix = []
res = 0
for _ in range(n):
# For each line, read the line, split by spaces, and convert each to an integer
row = list(map(int, input().split()))
if (sum(row) >= 2):
res += 1
print(res)
``` | 3 | |
769 | A | Year of University Entrance | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups f... | The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed tha... | Print the year of Igor's university entrance. | [
"3\n2014 2016 2015\n",
"1\n2050\n"
] | [
"2015\n",
"2050\n"
] | In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance. | 500 | [
{
"input": "3\n2014 2016 2015",
"output": "2015"
},
{
"input": "1\n2050",
"output": "2050"
},
{
"input": "1\n2010",
"output": "2010"
},
{
"input": "1\n2011",
"output": "2011"
},
{
"input": "3\n2010 2011 2012",
"output": "2011"
},
{
"input": "3\n2049 20... | 1,488,644,909 | 16,109 | Python 3 | OK | TESTS | 45 | 62 | 4,608,000 | n = input()
my_str = input()
my_list = my_str.split(' ')
print(sorted(my_list)[len(my_list) // 2]) | Title: Year of University Entrance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of correspond... | ```python
n = input()
my_str = input()
my_list = my_str.split(' ')
print(sorted(my_list)[len(my_list) // 2])
``` | 3 | |
271 | B | Prime Matrix | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"math",
"number theory"
] | null | null | You've got an *n*<=×<=*m* matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times.
You are really curious about prime numbers. Let us remind you ... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=500) — the number of rows and columns in the matrix, correspondingly.
Each of the following *n* lines contains *m* integers — the initial matrix. All matrix elements are positive integers. All numbers in the initial matrix do not exceed 105.
The numb... | Print a single integer — the minimum number of moves needed to get a prime matrix from the one you've got. If you've got a prime matrix, print 0. | [
"3 3\n1 2 3\n5 6 1\n4 4 1\n",
"2 3\n4 8 8\n9 2 9\n",
"2 2\n1 3\n4 2\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample you need to increase number 1 in cell (1, 1). Thus, the first row will consist of prime numbers: 2, 2, 3.
In the second sample you need to increase number 8 in cell (1, 2) three times. Thus, the second column will consist of prime numbers: 11, 2.
In the third sample you don't have to do anything a... | 1,000 | [
{
"input": "3 3\n1 2 3\n5 6 1\n4 4 1",
"output": "1"
},
{
"input": "2 3\n4 8 8\n9 2 9",
"output": "3"
},
{
"input": "2 2\n1 3\n4 2",
"output": "0"
},
{
"input": "1 1\n14",
"output": "3"
},
{
"input": "5 3\n2 14 8\n8 8 2\n8 10 10\n1 2 1\n100 100 8",
"output": "... | 1,698,166,839 | 39 | Python 3 | OK | TESTS | 42 | 280 | 4,505,600 | import sys
distancia_prima = [0] * (10**5 + 4)
def precompute_prime_distance():
is_prime = [True] * (10**5 + 10)
is_prime[0] = is_prime[1] = False
for i in range(2, 10**5 + 4):
if is_prime[i]:
for multiplo in range(2 * i, 10**5 + 4, i):
is_prime[multiplo] = Fa... | Title: Prime Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be incre... | ```python
import sys
distancia_prima = [0] * (10**5 + 4)
def precompute_prime_distance():
is_prime = [True] * (10**5 + 10)
is_prime[0] = is_prime[1] = False
for i in range(2, 10**5 + 4):
if is_prime[i]:
for multiplo in range(2 * i, 10**5 + 4, i):
is_prime[mult... | 3 | |
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted... | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how th... | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output"... | 1,668,413,353 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 77 | 2,867,200 | n = int(input())
s = input()
import sys
for i in range(n-1):
if s[i] != "?" and s[i] == s[i+1]:
print("No")
sys.exit(0)
for i in range(n):
if s[i] == "?":
if i == 0 and i == n-1:
print("Yes")
sys.exit(0)
if s[i+1] == "?":
print("... | Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one... | ```python
n = int(input())
s = input()
import sys
for i in range(n-1):
if s[i] != "?" and s[i] == s[i+1]:
print("No")
sys.exit(0)
for i in range(n):
if s[i] == "?":
if i == 0 and i == n-1:
print("Yes")
sys.exit(0)
if s[i+1] == "?":
... | -1 | |
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that... | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so t... | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
... | 1,595,259,022 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 6,656,000 | from math import *
t=int(input())
a=list(map(int,input().split()))
p=round(sum(a)/t)
'''p=str(p)
z=p[2]
z=int(z)'''
if p==5:
print(0)
else:
'''b=[]
count=0
for i in range(0,len(a)):
if a[i]!=5:
b.append(a[i])
else:
count+=1'''
a.sort()
... | Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming t... | ```python
from math import *
t=int(input())
a=list(map(int,input().split()))
p=round(sum(a)/t)
'''p=str(p)
z=p[2]
z=int(z)'''
if p==5:
print(0)
else:
'''b=[]
count=0
for i in range(0,len(a)):
if a[i]!=5:
b.append(a[i])
else:
count+=1'''
a.... | 0 | |
748 | A | Santa Claus and a Place in a Class | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 500 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,498,989,499 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 62 | 5,529,600 | n, m, k = map(int, input().split())
for i in range(1, n + 1):
if k % 2 == 0:
j = k // 2 - m * (i - 1)
if 1 <= j and j <= m:
print("{} {} R".format(i, j))
exit()
else:
j = (k + 1) // 2 - m * (i - 1)
if 1 <= j and j <= m:
print("{} {} L".format(... | Title: Santa Claus and a Place in a Class
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work... | ```python
n, m, k = map(int, input().split())
for i in range(1, n + 1):
if k % 2 == 0:
j = k // 2 - m * (i - 1)
if 1 <= j and j <= m:
print("{} {} R".format(i, j))
exit()
else:
j = (k + 1) // 2 - m * (i - 1)
if 1 <= j and j <= m:
print("{} {} ... | 3 | |
416 | D | Population Size | PROGRAMMING | 2,400 | [
"greedy",
"implementation",
"math"
] | null | null | Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.
Polycarpus believes that if... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of elements in the sequence. The second line contains integer values *a*1,<=*a*2,<=...,<=*a**n* separated by a space (1<=≤<=*a**i*<=≤<=109 or *a**i*<==<=<=-<=1). | Print the minimum number of arithmetic progressions that you need to write one after another to get sequence *a*. The positions marked as -1 in *a* can be represented by any positive integers. | [
"9\n8 6 4 2 1 4 7 10 2\n",
"9\n-1 6 -1 2 -1 4 7 -1 2\n",
"5\n-1 -1 -1 -1 -1\n",
"7\n-1 -1 4 5 1 2 3\n"
] | [
"3\n",
"3\n",
"1\n",
"2\n"
] | none | 2,000 | [
{
"input": "9\n8 6 4 2 1 4 7 10 2",
"output": "3"
},
{
"input": "9\n-1 6 -1 2 -1 4 7 -1 2",
"output": "3"
},
{
"input": "5\n-1 -1 -1 -1 -1",
"output": "1"
},
{
"input": "7\n-1 -1 4 5 1 2 3",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input... | 1,632,388,958 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 6,656,000 | print("2"); | Title: Population Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an... | ```python
print("2");
``` | 0 | |
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of hi... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be... | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before... | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342... | 1,580,730,610 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 217 | 2,150,400 | num = int(input())
sol=0
for i in range(num):
list = [x for x in input().split(" ")]
if list[1]>=2400 and list[2]>list[1]:
sol=1
if sol==1:
print("YES")
else:
print("NO") | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ... | ```python
num = int(input())
sol=0
for i in range(num):
list = [x for x in input().split(" ")]
if list[1]>=2400 and list[2]>list[1]:
sol=1
if sol==1:
print("YES")
else:
print("NO")
``` | -1 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,688,713,573 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 1,123 | 9,113,600 | n=int(input())
sides=0
d={'Tetrahedron':4,'Cube':6,'Octahedron':8,'Dodecahedron':12,'Icosahedron':20}
for _ in range(n):
s=input()
sides+=d[s]
print(sides) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
n=int(input())
sides=0
d={'Tetrahedron':4,'Cube':6,'Octahedron':8,'Dodecahedron':12,'Icosahedron':20}
for _ in range(n):
s=input()
sides+=d[s]
print(sides)
``` | 3 | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,655,576,092 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
a = list(map(int ,input() .split()))
a = sorted(a)
print(sum(a) * 3 - a[0])
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n = int(input())
a = list(map(int ,input() .split()))
a = sorted(a)
print(sum(a) * 3 - a[0])
``` | 0 | |
198 | B | Jumping on Walls | PROGRAMMING | 1,400 | [
"shortest paths"
] | null | null | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. ... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105) — the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall — a string with the length of *n* characters. The *i*-th character represents the state of the *i*-th wall are... | Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). | [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n"
] | [
"YES\n",
"NO\n"
] | In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon. | 1,000 | [
{
"input": "7 3\n---X--X\n-X--XX-",
"output": "YES"
},
{
"input": "6 2\n--X-X-\nX--XX-",
"output": "NO"
},
{
"input": "10 1\n-X-X-X-X-X\nX-X-X-X-X-",
"output": "YES"
},
{
"input": "5 4\n-X---\n----X",
"output": "NO"
},
{
"input": "6 2\n--X--X\nXX-X-X",
"output... | 1,550,227,906 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 1,090 | 268,390,400 | n,k = map(int,input().split())
l = input()
r = input()
data = [0, ' '+l,' '+r]
dist = [[1000000]*100005 for _ in range(n)]
visited = [[False]*100005 for _ in range(n)]
dist[1][1]=0
visited[1][1]=True
qx,qy = [1],[1]
while qy:
x,y = qx.pop(),qy.pop()
if dist[x][y]>=y:
continue
if x==1:
... | Title: Jumping on Walls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these w... | ```python
n,k = map(int,input().split())
l = input()
r = input()
data = [0, ' '+l,' '+r]
dist = [[1000000]*100005 for _ in range(n)]
visited = [[False]*100005 for _ in range(n)]
dist[1][1]=0
visited[1][1]=True
qx,qy = [1],[1]
while qy:
x,y = qx.pop(),qy.pop()
if dist[x][y]>=y:
continue
... | 0 | |
717 | C | Potions Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of tasks. The next *n* lines contain exactly one integer number *a**i* (1<=≤<=*a**i*<=≤<=100<=000) — both the difficulty of the initial task and the laziness of the *i*-th students. | Print the minimum total time to finish all tasks modulo 10<=007. | [
"2\n1\n3\n"
] | [
"6\n"
] | In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. | 0 | [
{
"input": "2\n1\n3",
"output": "6"
}
] | 1,566,893,636 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 265 | 2,969,600 | n = int(input())
s = sorted([int(input()) for i in range(n)])
#print(s)
a = 0
q = 10007
for i in range(n//2):
a += ((s[i]*s[n-1-i]*2)%q)
if n%2==1:
a += ((s[n//2]**2)%q)
print(a%q) | Title: Potions Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun ... | ```python
n = int(input())
s = sorted([int(input()) for i in range(n)])
#print(s)
a = 0
q = 10007
for i in range(n//2):
a += ((s[i]*s[n-1-i]*2)%q)
if n%2==1:
a += ((s[n//2]**2)%q)
print(a%q)
``` | 3 | |
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,695,110,323 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | lst = []
for i in range(int(input())):
a,b = map(int, input().split())
if i == 0:
lst.append((a+b))
else:
lst.append(((lst[-1]-a)+b))
print(max(lst))
| 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
lst = []
for i in range(int(input())):
a,b = map(int, input().split())
if i == 0:
lst.append((a+b))
else:
lst.append(((lst[-1]-a)+b))
print(max(lst))
``` | 3 | |
682 | B | Alyona and Mex | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | [
"5\n1 3 3 3 6\n",
"2\n2 1\n"
] | [
"5\n",
"3\n"
] | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | 1,000 | [
{
"input": "5\n1 3 3 3 6",
"output": "5"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "1\n1000000000",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"... | 1,554,754,725 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 139 | 512,000 | # Author Kmoussai
import sys
import math
import random
if len(sys.argv) >= 2:
if sys.argv[1] == 'LOCAL':
sys.stdin = open('input.in', 'r')
n = int(input())
l = map(int, input().split())
l = sorted(l)
mex = l[-1] - 1
if mex == 0:
mex = 1
for i in l:
if i == mex:
mex += ... | Title: Alyona and Mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is small... | ```python
# Author Kmoussai
import sys
import math
import random
if len(sys.argv) >= 2:
if sys.argv[1] == 'LOCAL':
sys.stdin = open('input.in', 'r')
n = int(input())
l = map(int, input().split())
l = sorted(l)
mex = l[-1] - 1
if mex == 0:
mex = 1
for i in l:
if i == mex:
... | 0 | |
125 | A | Measuring Lengths in Baden | PROGRAMMING | 1,400 | [
"math"
] | null | null | Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The ... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=10000). | Print two non-negative space-separated integers *a* and *b*, where *a* is the numbers of feet and *b* is the number of inches. | [
"42\n",
"5\n"
] | [
"1 2\n",
"0 2\n"
] | none | 1,000 | [
{
"input": "42",
"output": "1 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "24",
"output": "0 8"
},
{
"input": "1",
"output": "0 0"
},
{
"input": "2",
"output": "0 1"
},
{
"input": "3",
"output": "0 1"
},
{
"input": "4",
"output"... | 1,647,856,171 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 92 | 0 | n=(int(input())+1)//3;print(n//12,n%12) | Title: Measuring Lengths in Baden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equa... | ```python
n=(int(input())+1)//3;print(n//12,n%12)
``` | 3 | |
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,663,607,116 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 46 | 0 | import math
n, m = map(int, input().split())
max_val = (n-m+1)*(n-m)/2
if(n%m==0):
x=n/m
min_val=((x*(x-1))/2)*m
else:
a=(n/m)
x = math.floor(a)
min_val=((x*(x-1))/2)*(m-(n%m))+ ((((x+1)*x)/2)*(n%m))
print(int(min_val), int(max_val))
| 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
import math
n, m = map(int, input().split())
max_val = (n-m+1)*(n-m)/2
if(n%m==0):
x=n/m
min_val=((x*(x-1))/2)*m
else:
a=(n/m)
x = math.floor(a)
min_val=((x*(x-1))/2)*(m-(n%m))+ ((((x+1)*x)/2)*(n%m))
print(int(min_val), int(max_val))
``` | 0 | |
558 | B | Amr and The Large Array | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. | Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them. | [
"5\n1 1 2 2 1\n",
"5\n1 2 2 3 1\n",
"6\n1 2 2 1 1 2\n"
] | [
"1 5",
"2 3",
"1 5"
] | A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | 1,000 | [
{
"input": "5\n1 1 2 2 1",
"output": "1 5"
},
{
"input": "5\n1 2 2 3 1",
"output": "2 3"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "1 5"
},
{
"input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1",
"output": "2 7"
},
{
"input": "10\n1 2 3 4 5 5 1 2 3 4",
"output... | 1,671,988,143 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 155 | 30,515,200 | from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
def IA(): return list(map(int, inp().split()))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F(): return float(inp())
def S(): return inp()
from collections ... | Title: Amr and The Large Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to... | ```python
from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
def IA(): return list(map(int, inp().split()))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F(): return float(inp())
def S(): return inp()
from co... | 3 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,652,791,675 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 5,632,000 | s1=input()
s2=input()
l1=int(len(s1))
l2=int(len(s2))
l10=int(l1)
l20=int(l2)
i=0
i=int(i)
temp=0
temp=int(temp)
f=0
f=int(f)
if l1>l2:
s1=s1[l1-l2:l1]
temp=temp+l1-l2
elif l1<l2:
s2=s2[l2-l1:l2]
temp=temp+l2-l1
l1=int(len(s1))
l2=int(len(s2))
while(i<l1 and i<l2):
if s1[i:l1]==s2[i:l2]:
tem... | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s1=input()
s2=input()
l1=int(len(s1))
l2=int(len(s2))
l10=int(l1)
l20=int(l2)
i=0
i=int(i)
temp=0
temp=int(temp)
f=0
f=int(f)
if l1>l2:
s1=s1[l1-l2:l1]
temp=temp+l1-l2
elif l1<l2:
s2=s2[l2-l1:l2]
temp=temp+l2-l1
l1=int(len(s1))
l2=int(len(s2))
while(i<l1 and i<l2):
if s1[i:l1]==s2[i:l2]:
... | 0 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,691,272,558 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 2,355,200 | def yzd_solution(a, b, c, d):
str = [char for char in input()]
calories = 0
for char in str:
calories += a if char == '1' else b if char == '2' else c if char == '3' else d
print(calories)
a, b, c, d = map(int, input().split())
yzd_solution(a, b, c, d) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
def yzd_solution(a, b, c, d):
str = [char for char in input()]
calories = 0
for char in str:
calories += a if char == '1' else b if char == '2' else c if char == '3' else d
print(calories)
a, b, c, d = map(int, input().split())
yzd_solution(a, b, c, d)
``` | 3 | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,689,576,111 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | import sys
from math import gcd
input=sys.stdin.readline
n,m,d=map(int,input().split())
g=0
s=[]
for i in range(n):
a=list(map(int,input().split()))
if(i==0):
g=a[0]
for j in a:
s.append(j)
g=gcd(g,j)
if(max(d,g)%min(d,g)==0 and g!=1):
s.sort()
c=0
if(len(... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
import sys
from math import gcd
input=sys.stdin.readline
n,m,d=map(int,input().split())
g=0
s=[]
for i in range(n):
a=list(map(int,input().split()))
if(i==0):
g=a[0]
for j in a:
s.append(j)
g=gcd(g,j)
if(max(d,g)%min(d,g)==0 and g!=1):
s.sort()
c=0
... | 0 | |
499 | A | Watching a movie | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie... | The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button.
The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains tw... | Output a single number — the answer to the problem. | [
"2 3\n5 6\n10 12\n",
"1 1\n1 100000\n"
] | [
"6\n",
"100000\n"
] | In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch th... | 500 | [
{
"input": "2 3\n5 6\n10 12",
"output": "6"
},
{
"input": "1 1\n1 100000",
"output": "100000"
},
{
"input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728",
"output": "53974"
},
{
"input": "1... | 1,626,456,315 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 108 | 20,172,800 | n, x = map(int,input().split())
t=0
lw=0
for i in range(n):
l, r = map(int,input().split())
t+= (l-lw-1)%x
t+= r-l+1
lw=r
print(t) | Title: Watching a movie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the pl... | ```python
n, x = map(int,input().split())
t=0
lw=0
for i in range(n):
l, r = map(int,input().split())
t+= (l-lw-1)%x
t+= r-l+1
lw=r
print(t)
``` | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,593,157,488 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 310 | 20,172,800 | 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()))
n=inp()
sx,sy,sz=0,0,0
for _ in range(n):
x,y,z=invr()
sx+=x;sy+y;sz+=z
if sx==0 and sy==0 and ... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
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()))
n=inp()
sx,sy,sz=0,0,0
for _ in range(n):
x,y,z=invr()
sx+=x;sy+y;sz+=z
if sx==0 and ... | 3.884925 |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,699,028,310 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 78 | 0 | n=int(input())
c=0
for i in range(n):
a1,b1=input().split()
a=int(a1)
b=int(b1)
if b-a>=2:
c+=1
else:
continue
print(c) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
n=int(input())
c=0
for i in range(n):
a1,b1=input().split()
a=int(a1)
b=int(b1)
if b-a>=2:
c+=1
else:
continue
print(c)
``` | 3 | |
952 | A | Quirky Quantifiers | PROGRAMMING | 800 | [
"math"
] | null | null | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1. | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999). | Output 0 or 1. | [
"13\n",
"927\n",
"48\n"
] | [
"1\n",
"1\n",
"0\n"
] | none | 0 | [
{
"input": "13",
"output": "1"
},
{
"input": "927",
"output": "1"
},
{
"input": "48",
"output": "0"
},
{
"input": "10",
"output": "0"
},
{
"input": "999",
"output": "1"
},
{
"input": "142",
"output": "0"
},
{
"input": "309",
"output": "... | 1,585,581,588 | 2,147,483,647 | PyPy 3 | OK | TESTS | 15 | 139 | 0 | n=int(input());print(n%2) | Title: Quirky Quantifiers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1.
Input Specification:
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output Specification:
Output 0 or 1.
Demo Input:
['1... | ```python
n=int(input());print(n%2)
``` | 3 | |
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,667,104,231 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | x,y,z = list(map(int, input().split()))
a = pow((x*y)/z,1/2)
b = pow((x*z)/y,1/2)
c = pow((y*z)/x,1/2)
ans = 4*(a+b+c)
print(int(ans)) | 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
x,y,z = list(map(int, input().split()))
a = pow((x*y)/z,1/2)
b = pow((x*z)/y,1/2)
c = pow((y*z)/x,1/2)
ans = 4*(a+b+c)
print(int(ans))
``` | 3 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,691,079,181 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n,k=map(int,input().split())
l=list(map(int,input().split()))
sum=int(0)
if k==1:
print(l.index(min(l)))
exit()
for i in range(k):
sum+=l[i]
minsum=sum
ind=int(0)
for i in range(1,n-k+1):
sum=sum-l[i]+l[k+i-1]
if sum>minsum:
continue
else:
minsum=sum
ind=i... | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
sum=int(0)
if k==1:
print(l.index(min(l)))
exit()
for i in range(k):
sum+=l[i]
minsum=sum
ind=int(0)
for i in range(1,n-k+1):
sum=sum-l[i]+l[k+i-1]
if sum>minsum:
continue
else:
minsum=sum
... | 0 | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,618,483,601 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 62 | 0 |
import sys
def get_single_int ():
return int (sys.stdin.readline ().strip ())
def get_string ():
return sys.stdin.readline ().strip ()
def get_ints ():
return map (int, sys.stdin.readline ().strip ().split ())
def get_list ():
return list (map (int, sys.stdin.readline ().strip ().split ()))
... | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
import sys
def get_single_int ():
return int (sys.stdin.readline ().strip ())
def get_string ():
return sys.stdin.readline ().strip ()
def get_ints ():
return map (int, sys.stdin.readline ().strip ().split ())
def get_list ():
return list (map (int, sys.stdin.readline ().strip ().spl... | 3 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,613,374,686 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 93 | 1,331,200 | n = int(input())
s = input()
def decode(string):
s = list(string)
out = []
while len(s) != 0:
out.insert(len(out)//2, s[-1])
s.pop(-1)
return "".join(out)
print(decode(s)) | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n = int(input())
s = input()
def decode(string):
s = list(string)
out = []
while len(s) != 0:
out.insert(len(out)//2, s[-1])
s.pop(-1)
return "".join(out)
print(decode(s))
``` | 3 | |
4 | C | Registration System | PROGRAMMING | 1,300 | [
"data structures",
"hashing",
"implementation"
] | C. Registration system | 5 | 64 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | [
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] | [
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] | none | 0 | [
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
... | 1,689,438,021 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 1,372 | 1,228,800 | n = int(input())
d = {}
for i in range(n):
a = input()
if a not in d:
d[a] = 0
print('OK')
elif a in d:
d[a] += 1
print(a + str(d[a]))
# Sat Jul 15 2023 19:20:20 GMT+0300 (Moscow Standard Time)
| Title: Registration System
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to imple... | ```python
n = int(input())
d = {}
for i in range(n):
a = input()
if a not in d:
d[a] = 0
print('OK')
elif a in d:
d[a] += 1
print(a + str(d[a]))
# Sat Jul 15 2023 19:20:20 GMT+0300 (Moscow Standard Time)
``` | 3.853645 |
120 | B | Quiz League | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 ... | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | [
"5 5\n0 1 0 1 0\n",
"2 1\n1 1\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "5 5\n0 1 0 1 0",
"output": "2"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "3 2\n1 0 0",
"output": "1"
},
{
"input": "3 3\n0 1 0",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "6 3\n0 0 1 1 0 1",
"output":... | 1,568,704,291 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 140 | 0 | class CodeforcesTask120BSolution:
def __init__(self):
self.result = ''
self.n_k = []
self.questions = []
def read_input(self):
in_ = open("input.txt").read().split("\n")
self.n_k = [int(x) for x in in_[0].split(" ")]
self.questions = [int(x) for x in in_[1].split... | Title: Quiz League
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a quest... | ```python
class CodeforcesTask120BSolution:
def __init__(self):
self.result = ''
self.n_k = []
self.questions = []
def read_input(self):
in_ = open("input.txt").read().split("\n")
self.n_k = [int(x) for x in in_[0].split(" ")]
self.questions = [int(x) for x in in... | 3 | |
355 | A | Vasya and Digital Root | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<... | The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). | In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. | [
"4 4\n",
"5 1\n",
"1 0\n"
] | [
"5881\n",
"36172\n",
"0\n"
] | For the first test sample *dr*(5881) = *dr*(22) = 4.
For the second test sample *dr*(36172) = *dr*(19) = *dr*(10) = 1. | 500 | [
{
"input": "4 4",
"output": "5881"
},
{
"input": "5 1",
"output": "36172"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "8 7",
"output": "49722154"
},
{
"input": "487 0",
"output": "No solution"
},
{
"input": "1000 5",
"output": "854193955406789... | 1,562,327,554 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 109 | 0 | k,d = input().split()
k = int(k) -1
print("No solution") if(d == '0' and k) else print(d+'0'*k)
| Title: Vasya and Digital Root
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=... | ```python
k,d = input().split()
k = int(k) -1
print("No solution") if(d == '0' and k) else print(d+'0'*k)
``` | 3 | |
873 | A | Chores | PROGRAMMING | 800 | [
"implementation"
] | null | null | Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of ... | The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself.
The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to... | Print one number — minimum time Luba needs to do all *n* chores. | [
"4 2 2\n3 6 7 10\n",
"5 2 1\n100 100 100 100 100\n"
] | [
"13\n",
"302\n"
] | In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13.
In the second example Luba can choose any two chores to spend *x... | 0 | [
{
"input": "4 2 2\n3 6 7 10",
"output": "13"
},
{
"input": "5 2 1\n100 100 100 100 100",
"output": "302"
},
{
"input": "1 1 1\n100",
"output": "1"
},
{
"input": "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ... | 1,507,827,294 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | inp = lambda: map(int, input().split())
n,k,x = inp()
a = list(inp())
print(sum(a[: -k])+k*x) | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on s... | ```python
inp = lambda: map(int, input().split())
n,k,x = inp()
a = list(inp())
print(sum(a[: -k])+k*x)
``` | 3 | |
909 | C | Python Indentation | PROGRAMMING | 1,800 | [
"dp"
] | null | null | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An ex... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. | Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. | [
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] | [
"1\n",
"2\n"
] | In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one... | 1,500 | [
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns... | 1,514,807,603 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,632,000 |
n = int(input())
I = [0] * n
ii = 0
indent = 0
# creating the dp matrix
dp = []
for _ in range(n):
dp.append([0] * n)
p = []
for _ in range(n):
p.append(input())
dp[0][0] = 1
indent = 0
for i in range(1, n):
if p[i-1] == 'f':
indent = indent + 1
for j in range(1, indent+1):
dp[i][j] = dp[i-1][j-1]
el... | Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python... | ```python
n = int(input())
I = [0] * n
ii = 0
indent = 0
# creating the dp matrix
dp = []
for _ in range(n):
dp.append([0] * n)
p = []
for _ in range(n):
p.append(input())
dp[0][0] = 1
indent = 0
for i in range(1, n):
if p[i-1] == 'f':
indent = indent + 1
for j in range(1, indent+1):
dp[i][j] = dp[i-1... | 0 | |
831 | B | Keyboard Layouts | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i... | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.
The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.
The third line contains a non-empty string *s* consisting of lowercase a... | Print the text if the same keys were pressed in the second layout. | [
"qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017\n",
"mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7\n"
] | [
"HelloVKCup2017\n",
"7uduGUDUUDUgudu7\n"
] | none | 750 | [
{
"input": "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017",
"output": "HelloVKCup2017"
},
{
"input": "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7",
"output": "7uduGUDUUDUgudu7"
},
{
"input": "ayvguplhjsoiencbkxdrfwmqtz\nkhzvtbspcndier... | 1,689,921,672 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 46 | 0 | a, b, c = input(), input(), input()
a += a.upper()
b += b.upper()
t = str.maketrans(a, b)
print(c.translate(t)) | Title: Keyboard Layouts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are gi... | ```python
a, b, c = input(), input(), input()
a += a.upper()
b += b.upper()
t = str.maketrans(a, b)
print(c.translate(t))
``` | 3 | |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,620,360,106 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 48 | 108 | 21,913,600 |
s= input()
t=list(input())
h=''.join(t)
g=0
for j in range(len(t)-1,-1,-1):
a=ord(t[j])
b=ord('a')
for u in range(a-1,b-1,-1):
gg=t[:j]+[chr(u)]+t[j+1:]
if s<''.join(gg)<h:
print(''.join(gg))
g+=1
... | Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
s= input()
t=list(input())
h=''.join(t)
g=0
for j in range(len(t)-1,-1,-1):
a=ord(t[j])
b=ord('a')
for u in range(a-1,b-1,-1):
gg=t[:j]+[chr(u)]+t[j+1:]
if s<''.join(gg)<h:
print(''.join(gg))
... | 0 | |
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
... | 1,602,689,440 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 140 | 0 | n=int(input())
s=str(input())
l=[]
e=0
for i in range(0,len(s)):
if(s[i]=='B'):
e=e+1
else:
if(e>0):
l.append(e)
e=0
else:
pass
if(e>0):
l.append(e)
print(len(l))
print(*l) | Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the... | ```python
n=int(input())
s=str(input())
l=[]
e=0
for i in range(0,len(s)):
if(s[i]=='B'):
e=e+1
else:
if(e>0):
l.append(e)
e=0
else:
pass
if(e>0):
l.append(e)
print(len(l))
print(*l)
``` | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,699,077,825 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 31 | 0 | a, b = map(int, input().split())
minimum = min(a, b)
maximum = max(a, b)
mismatch = (maximum - minimum) // 2
print(minimum, mismatch) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a, b = map(int, input().split())
minimum = min(a, b)
maximum = max(a, b)
mismatch = (maximum - minimum) // 2
print(minimum, mismatch)
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,619,510,255 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 122 | 0 | rect = input().split()
x = rect[0]
y = rect[1]
area = int(x)*int(y)
print(str(area//2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
rect = input().split()
x = rect[0]
y = rect[1]
area = int(x)*int(y)
print(str(area//2))
``` | 3.9695 |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,677,752,641 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | s = input()
t = input()
a = 0
ptr = 0
while ptr<len(t):
if t[ptr]==s[a]:
a+=1
ptr+=1
print(a+1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s = input()
t = input()
a = 0
ptr = 0
while ptr<len(t):
if t[ptr]==s[a]:
a+=1
ptr+=1
print(a+1)
``` | 3 | |
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,609,530,211 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | s = input()
a1 = s.find("h")
a2 = s.find("e")
a3 = s.find("l")
a5 = s.find("o")
a4 = s[a3:a5].find("l")
if a1 < a2 < a3 < a5 and a4 >= 0:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
a1 = s.find("h")
a2 = s.find("e")
a3 = s.find("l")
a5 = s.find("o")
a4 = s[a3:a5].find("l")
if a1 < a2 < a3 < a5 and a4 >= 0:
print("YES")
else:
print("NO")
``` | 0 |
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,666,592,979 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 1,778 | 10,956,800 | s=input()
n=len(s)
z=[]
k=0
b=0
for i in range(n):
z.append(s[i])
b+=1
if b>=2:
if z[b-2]=='(' and z[b-1]==')':
z.pop(b-1)
z.pop(b-2)
k+=2
b-=2
print(k) | 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
s=input()
n=len(s)
z=[]
k=0
b=0
for i in range(n):
z.append(s[i])
b+=1
if b>=2:
if z[b-2]=='(' and z[b-1]==')':
z.pop(b-1)
z.pop(b-2)
k+=2
b-=2
print(k)
``` | 3.801791 |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,690,713,170 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | t1=input()
t2=input()
t3=input()
t4=t1+t2
if len(t3)!=len(t4):
print("NO")
return 0
else:
t4.sort()
t3.sort()
if t3==t4:
print("YES")
return 0
else:
print("NO")
return 0 | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
t1=input()
t2=input()
t3=input()
t4=t1+t2
if len(t3)!=len(t4):
print("NO")
return 0
else:
t4.sort()
t3.sort()
if t3==t4:
print("YES")
return 0
else:
print("NO")
return 0
``` | -1 | |
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other ... | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3... | 1,608,480,307 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 202 | 7,680,000 | n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
for i in range(n):
sum += x*a[i]
if(x>1):
x -= 1
print(sum)
| Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co... | ```python
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
for i in range(n):
sum += x*a[i]
if(x>1):
x -= 1
print(sum)
``` | 3 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,681,025,046 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 93 | 0 | import sys
##from math import log10, ceil, gcd, log2
##from bisect import bisect_left as bs
##from re import match, compile
##from collections import defaultdict
input = sys.stdin.readline
ii = lambda: int(input())
ist = lambda: input().strip()
iilist = lambda: list(map(int, input().split()))
INFINITY = 10... | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
import sys
##from math import log10, ceil, gcd, log2
##from bisect import bisect_left as bs
##from re import match, compile
##from collections import defaultdict
input = sys.stdin.readline
ii = lambda: int(input())
ist = lambda: input().strip()
iilist = lambda: list(map(int, input().split()))
INF... | 3 | |
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,587,554,705 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 307,200 | def s():
s=input()
num_upper=0
num_lower=0
for i in s:
if ord(i)<=90:
num_upper+=1
else:
num_lower+=1
if num_lower>=num_upper:
for i in range(len(s)):
if ord(s[i])<91:
s=s[0:i]+chr(ord(s[i])+32)+s[i+1:len(s)]
... | 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
def s():
s=input()
num_upper=0
num_lower=0
for i in s:
if ord(i)<=90:
num_upper+=1
else:
num_lower+=1
if num_lower>=num_upper:
for i in range(len(s)):
if ord(s[i])<91:
s=s[0:i]+chr(ord(s[i])+32)+s[i+1:l... | 3.944928 |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,639,735,642 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 62 | 0 | tc=int(input())
count1=0
count2=0
count3=0
count4=0
for i in range(tc):
t,x,y=list(map(int,input().split()))
if t==1:
count1+=x
count2+=10
else:
count3+=x
count4+=10
if count1>=(count2/2):
print('LIVE')
else:
print('DEAD')
if count3>=(count4/2):
... | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
tc=int(input())
count1=0
count2=0
count3=0
count4=0
for i in range(tc):
t,x,y=list(map(int,input().split()))
if t==1:
count1+=x
count2+=10
else:
count3+=x
count4+=10
if count1>=(count2/2):
print('LIVE')
else:
print('DEAD')
if count3>=(count4... | 3 | |
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,618,373,626 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | s = input()
u, l = 0, 0
for c in s:
if c.islower(): l+=1
else: u+=1
if u > l:
s = s.upper()
else:
s = s.lower()
print(s)
| 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()
u, l = 0, 0
for c in s:
if c.islower(): l+=1
else: u+=1
if u > l:
s = s.upper()
else:
s = s.lower()
print(s)
``` | 3.969 |
73 | A | The Elder Trolls IV: Oblivon | PROGRAMMING | 1,600 | [
"greedy",
"math"
] | A. The Elder Trolls IV: Oblivon | 2 | 256 | Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ... | The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109). | Output the only number — the answer for the problem.
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). | [
"2 2 2 3\n",
"2 2 2 1\n"
] | [
"8",
"2"
] | In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two. | 500 | [
{
"input": "2 2 2 3",
"output": "8"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 3 3",
"output": "6"
},
{
"input": "20 4 5 12",
"output": "120"
},
{
"input": "100 500 100500 1000000000",
"output":... | 1,691,075,189 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | x, y, z, k = map(int, input().split())
mx = x + y + z - 3
if k >= mx:
print(x * y * z)
else:
print(2 ** mx)
| Title: The Elder Trolls IV: Oblivon
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monste... | ```python
x, y, z, k = map(int, input().split())
mx = x + y + z - 3
if k >= mx:
print(x * y * z)
else:
print(2 ** mx)
``` | 0 |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,600,830,982 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 187 | 0 | a=int(input())
i=''
number=1
while len(i)<a:
i+=str(number)
number+=1
print(i[a-1])
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
a=int(input())
i=''
number=1
while len(i)<a:
i+=str(number)
number+=1
print(i[a-1])
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A two dimensional array is called a bracket array if each grid contains one of the two possible brackets — "(" or ")". A path through the two dimensional array cells is called monotonous if any two consecutive cells in the path are side-adjacent and each cell of the path is located below or to the right from the previo... | The first line contains integers *n*, *m* and *k* — the sizes of the array and the number of the sought correct bracket array (1<=≤<=*n*,<=*m*<=≤<=100, 1<=≤<=*k*<=≤<=1018). Then an array of priorities is given, *n* lines each containing *m* numbers, number *p**i*,<=*j* shows the priority of character *j* in line *i* (1... | Print the *k*-th two dimensional correct bracket array. | [
"1 2 1\n1 2\n",
"2 3 1\n1 2 3\n4 5 6\n",
"3 2 2\n3 6\n1 4\n2 5\n"
] | [
"()\n",
"(()\n())\n",
"()\n)(\n()\n"
] | In the first sample exists only one correct two-dimensional bracket array.
In the second and in the third samples two arrays exist.
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 «(())()», «(... | 0 | [] | 1,690,486,262 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1690486262.3801467")# 1690486262.3801653 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A two dimensional array is called a bracket array if each grid contains one of the two possible brackets — "(" or ")". A path through the two dimensional array cells is called monotonous if any two consecutive cells in the path ar... | ```python
print("_RANDOM_GUESS_1690486262.3801467")# 1690486262.3801653
``` | 0 | |
148 | B | Escape | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at *v**p* miles per hour, and the dragon flies at *v**d* miles per hour. The dragon will discover the escape after *t* hours and will chase the princess immediately. Looks like there's no chance to success, but the... | The input data contains integers *v**p*,<=*v**d*,<=*t*,<=*f* and *c*, one per line (1<=≤<=*v**p*,<=*v**d*<=≤<=100, 1<=≤<=*t*,<=*f*<=≤<=10, 1<=≤<=*c*<=≤<=1000). | Output the minimal number of bijous required for the escape to succeed. | [
"1\n2\n1\n1\n10\n",
"1\n2\n1\n1\n8\n"
] | [
"2\n",
"1\n"
] | In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return to the cave and fixing the treasury will take the dragon two more ... | 1,000 | [
{
"input": "1\n2\n1\n1\n10",
"output": "2"
},
{
"input": "1\n2\n1\n1\n8",
"output": "1"
},
{
"input": "5\n8\n1\n2\n100",
"output": "2"
},
{
"input": "2\n100\n10\n10\n739",
"output": "22"
},
{
"input": "17\n99\n2\n3\n293",
"output": "3"
},
{
"input": "5... | 1,682,159,950 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 122 | 0 | vp,vd,t,f,c=[int(input())for i in '12345']
r=0
while vp<vd:
z=(vp*t)/(vd-vp)
if z*vd>=c:break
t+=2*z+f;r+=1
print(r) | Title: Escape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at *v**p* miles per hour, and the dragon flies at *v**d* miles per hour. The dragon will discover the escape after *t* hou... | ```python
vp,vd,t,f,c=[int(input())for i in '12345']
r=0
while vp<vd:
z=(vp*t)/(vd-vp)
if z*vd>=c:break
t+=2*z+f;r+=1
print(r)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,618,810,109 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | abin=input()
bbin=input()
a=int(abin,2)
b=int(bbin,2)
s=bin(a+b)
print(s[2:]) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
abin=input()
bbin=input()
a=int(abin,2)
b=int(bbin,2)
s=bin(a+b)
print(s[2:])
``` | 0 |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,686,789,494 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a,b,n=map(int,input().split())
no=a * 10**n
for i in range(0,10):
if no%b==0:
print(no)
break
else:
no+=1 | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a,b,n=map(int,input().split())
no=a * 10**n
for i in range(0,10):
if no%b==0:
print(no)
break
else:
no+=1
``` | 0 | |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,611,824,795 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 140 | 7,270,400 | import math
n,k=map(int,input().split())
w=list(map(int,input().split()))
c=0
for i in range(n):
c+=(w[i]+k-1)//k
print((c+1)//2)
| Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
import math
n,k=map(int,input().split())
w=list(map(int,input().split()))
c=0
for i in range(n):
c+=(w[i]+k-1)//k
print((c+1)//2)
``` | 3 | |
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},... | 1,629,529,520 | 2,147,483,647 | PyPy 3 | OK | TESTS | 157 | 124 | 20,172,800 | from sys import stdin, stdout
nmbr = lambda: int(input())
lst = lambda: list(map(int, input().split()))
for _ in range(1):#nmbr()):
sa=sorted(input(), reverse=True)
na=len(sa)
sb=input()
nb=len(sb)
if nb>na:
print(''.join(sa))
continue
ans=''
while sa:
... | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allow... | ```python
from sys import stdin, stdout
nmbr = lambda: int(input())
lst = lambda: list(map(int, input().split()))
for _ in range(1):#nmbr()):
sa=sorted(input(), reverse=True)
na=len(sa)
sb=input()
nb=len(sb)
if nb>na:
print(''.join(sa))
continue
ans=''
while sa:... | 3 | |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question corr... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment... | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 2... | 1,681,482,902 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
l = list(map(int, input().split()))
i = 1
while i < n and l[i] >= l[i - 1]:
i += 1
j = i
while j < n and l[j] <= l[j - 1]:
j += 1
t = l[:i - 1] + l[i - 1:j][::-1] + l[j:]
l.sort()
if t == l:
print("yes")
print(i, j)
else:
print("no")
| Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your frie... | ```python
n = int(input())
l = list(map(int, input().split()))
i = 1
while i < n and l[i] >= l[i - 1]:
i += 1
j = i
while j < n and l[j] <= l[j - 1]:
j += 1
t = l[:i - 1] + l[i - 1:j][::-1] + l[j:]
l.sort()
if t == l:
print("yes")
print(i, j)
else:
print("no")
``` | -1 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,689,775,776 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | s1 = input().strip()
s2 = input().strip()
if len(s1) != len(s2):
print("NO")
else:
is_reverse = True
for i in range(len(s1)):
if s1[i] != s2[len(s2) - i - 1]:
is_reverse = False
break
if is_reverse:
print("YES")
else:
print... | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s1 = input().strip()
s2 = input().strip()
if len(s1) != len(s2):
print("NO")
else:
is_reverse = True
for i in range(len(s1)):
if s1[i] != s2[len(s2) - i - 1]:
is_reverse = False
break
if is_reverse:
print("YES")
else:
... | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And ye... | The first and the single line contains integers *y*1, *y*2, *y**w*, *x**b*, *y**b*, *r* (1<=≤<=*y*1,<=*y*2,<=*y**w*,<=*x**b*,<=*y**b*<=≤<=106; *y*1<=<<=*y*2<=<<=*y**w*; *y**b*<=+<=*r*<=<<=*y**w*; 2·*r*<=<<=*y*2<=-<=*y*1).
It is guaranteed that the ball is positioned correctly in the field, doesn't cross an... | If Robo-Wallace can't score a goal in the described manner, print "-1" (without the quotes). Otherwise, print a single number *x**w* — the abscissa of his point of aiming.
If there are multiple points of aiming, print the abscissa of any of them. When checking the correctness of the answer, all comparisons are made w... | [
"4 10 13 10 3 1\n",
"1 4 6 2 2 1\n",
"3 10 15 17 9 2\n"
] | [
"4.3750000000\n",
"-1\n",
"11.3333333333\n"
] | Note that in the first and third samples other correct values of abscissa *x*<sub class="lower-index">*w*</sub> are also possible. | 0 | [
{
"input": "4 10 13 10 3 1",
"output": "4.3750000000"
},
{
"input": "1 4 6 2 2 1",
"output": "-1"
},
{
"input": "3 10 15 17 9 2",
"output": "11.3333333333"
},
{
"input": "4 9 30 3 3 1",
"output": "-1"
},
{
"input": "4 9 13 2 3 1",
"output": "-1"
},
{
"... | 1,378,523,391 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | (y1, y2, yw, xb, yb, r) = map(int, input().split())
yt = yw*2-r*2-y2*0.5-y1*0.5
if yt / xb * r > 1e-8 + ((y2-y1)**2 - r**2)**0.5:
print(-1)
else:
print(xb*(yt-yw+r)/(yt-yb))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages ove... | ```python
(y1, y2, yw, xb, yb, r) = map(int, input().split())
yt = yw*2-r*2-y2*0.5-y1*0.5
if yt / xb * r > 1e-8 + ((y2-y1)**2 - r**2)**0.5:
print(-1)
else:
print(xb*(yt-yw+r)/(yt-yb))
``` | 0 | |
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and brin... | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to th... | 1,687,816,706 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 19 | 186 | 4,403,200 | # Enter your code here. Read input from STDIN. Print output to STDOUT
import math
if __name__ == '__main__':
lines = []
maxl = 0
while True:
try:
s=input()
if len(s) > maxl:
maxl = len(s)
lines.append(s)
except EOFError:
break
print("*"*(maxl+2))
left = True
even = maxl % 2 == 0
for line in... | Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You ... | ```python
# Enter your code here. Read input from STDIN. Print output to STDOUT
import math
if __name__ == '__main__':
lines = []
maxl = 0
while True:
try:
s=input()
if len(s) > maxl:
maxl = len(s)
lines.append(s)
except EOFError:
break
print("*"*(maxl+2))
left = True
even = maxl % 2 == 0
f... | 3.874194 |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,622,894,864 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | lst = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n = int(input("Enter n: "))
i = 0
if n <= 5:
print(lst[n-1])
else:
while n >= 5 * (2**i):
n -= 5 * (2**i)
i += 1
index = int((n - 1)/2**i)
print(lst[index]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
lst = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n = int(input("Enter n: "))
i = 0
if n <= 5:
print(lst[n-1])
else:
while n >= 5 * (2**i):
n -= 5 * (2**i)
i += 1
index = int((n - 1)/2**i)
print(lst[index])
``` | 0 |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,588,240,416 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 654 | 307,200 | n,d=map(int,input().split())
l=list(map(int,input().split()))
c=0
for i in range(n):
for j in range(i+1,n):
if(abs(l[j]-l[i])<=d):
c+=1
print(2*c) | Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n,d=map(int,input().split())
l=list(map(int,input().split()))
c=0
for i in range(n):
for j in range(i+1,n):
if(abs(l[j]-l[i])<=d):
c+=1
print(2*c)
``` | 3.835928 |
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,533,679,755 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | n , m = map(int,input().split())
def Alyona_Numbers(n,m):
if n%5 + m%5 > 5:return int(n*m/5)+1
else:return int(n*m/5)
print(Alyona_Numbers(n,m))
| 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
n , m = map(int,input().split())
def Alyona_Numbers(n,m):
if n%5 + m%5 > 5:return int(n*m/5)+1
else:return int(n*m/5)
print(Alyona_Numbers(n,m))
``` | 0 | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,596,733,684 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 6,963,200 | import sys
input = sys.stdin.readline
L = lambda:list(map(int,input().split()))
n,k = map(int,input().split()) # duration + time stay awake
t = L() #theorems
b = L() #behaviour asleep = 0
big = 0
extra = 0
for i in range(n):
if b[i] == 1:
extra += t[i]
for i in range(n-3... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
import sys
input = sys.stdin.readline
L = lambda:list(map(int,input().split()))
n,k = map(int,input().split()) # duration + time stay awake
t = L() #theorems
b = L() #behaviour asleep = 0
big = 0
extra = 0
for i in range(n):
if b[i] == 1:
extra += t[i]
for i in... | 0 | |
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor... | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim... | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: take... | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
... | 1,680,078,466 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n,top_floor = map(int , input().split())
data =["0"] * n
for i in range(n) :
data[i] = list(map(int,input().split()))
data = sorted(data ,reverse=True)
floor_seconds= 0
full_time = data[0][1] + floor_seconds
for idx , value in enumerate(data[1:]) :
if full_time >= value[1] :
floor_seconds... | Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo... | ```python
n,top_floor = map(int , input().split())
data =["0"] * n
for i in range(n) :
data[i] = list(map(int,input().split()))
data = sorted(data ,reverse=True)
floor_seconds= 0
full_time = data[0][1] + floor_seconds
for idx , value in enumerate(data[1:]) :
if full_time >= value[1] :
flo... | 0 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,587,285,292 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 500 | 1,228,800 | n, k = map(int,input().split())
if n<=500000000:
for i in range(500000000):
n=n+1
if(n%k==0):
print(n)
break
elif n>500000000:
for i in range(500000000,1000000000):
n=n+1
if(n%k==0):
print(n)
break
| Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
n, k = map(int,input().split())
if n<=500000000:
for i in range(500000000):
n=n+1
if(n%k==0):
print(n)
break
elif n>500000000:
for i in range(500000000,1000000000):
n=n+1
if(n%k==0):
print(n)
break
``` | 0 | |
90 | A | Cableway | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | A. Cableway | 2 | 256 | A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them ... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=100). It is guaranteed that *r*<=+<=*g*<=+<=*b*<=><=0, it means that the group consists of at least one student. | Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain. | [
"1 3 2\n",
"3 2 1\n"
] | [
"34",
"33"
] | Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the *r* group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the *g* group get on it; they get to the top at the moment of time 31.
At t... | 500 | [
{
"input": "1 3 2",
"output": "34"
},
{
"input": "3 2 1",
"output": "33"
},
{
"input": "3 5 2",
"output": "37"
},
{
"input": "10 10 10",
"output": "44"
},
{
"input": "29 7 24",
"output": "72"
},
{
"input": "28 94 13",
"output": "169"
},
{
"... | 1,478,963,992 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 154 | 0 | r, g, b = map(int, input().split())
t_r = 0 + 3 * ((r - 1) // 2)
t_g = 1 + 3 * ((g - 1) // 2)
t_b = 2 + 3 * ((b - 1) // 2)
print(30 + max(t_r, t_g, t_b)) | Title: Cableway
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cabl... | ```python
r, g, b = map(int, input().split())
t_r = 0 + 3 * ((r - 1) // 2)
t_g = 1 + 3 * ((g - 1) // 2)
t_b = 2 + 3 * ((b - 1) // 2)
print(30 + max(t_r, t_g, t_b))
``` | 3.9615 |
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,576,660,482 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | a = input()
s = input().split()
d = []
for i in s:
if i not in d:
d.append(i)
if '0' in d:
print(len(d) - 1)
else:
print(len(d)) | 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
a = input()
s = input().split()
d = []
for i in s:
if i not in d:
d.append(i)
if '0' in d:
print(len(d) - 1)
else:
print(len(d))
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.