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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤... | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sam... | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"inp... | 1,565,647,701 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 466 | 11,673,600 | kk=lambda:map(int, input().split())
ll=lambda:list(kk())
n,k=kk()
ls=ll()
s=set()
for i in range(n):
s.add(ls[i])
if len(s) == k:break
else:
print(-1,-1)
exit()
s.clear()
for j in range(i,-1,-1):
s.add(ls[j])
if len(s)==k:break
print(j+1, i+1) | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<... | ```python
kk=lambda:map(int, input().split())
ll=lambda:list(kk())
n,k=kk()
ls=ll()
s=set()
for i in range(n):
s.add(ls[i])
if len(s) == k:break
else:
print(-1,-1)
exit()
s.clear()
for j in range(i,-1,-1):
s.add(ls[j])
if len(s)==k:break
print(j+1, i+1)
``` | 3 | |
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,635,266,807 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 17,715,200 | n, d = map(int, input().split())
height = [int(y) for y in input().split()]
ans = 0
for i in range(0, n-1):
for j in range(i+1, n):
if abs(height[i] - height[j] <= d):
ans += 2
print(ans) | 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())
height = [int(y) for y in input().split()]
ans = 0
for i in range(0, n-1):
for j in range(i+1, n):
if abs(height[i] - height[j] <= d):
ans += 2
print(ans)
``` | 0 |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,686,137,846 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 46 | 1,638,400 | def get(a):
if a == 0:
return -1
else:
return a
def main():
n, a, b, c = list(map(int, input().split()))
dp = [0 for i in range(n+1)]
dp[min(a, b, c)] = 1
for i in range(min(a, b, c)+1, n+1):
dp[i] = max(get(dp[i - a]), get(dp[i-b]), get(dp[i-c])) + 1
print... | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
def get(a):
if a == 0:
return -1
else:
return a
def main():
n, a, b, c = list(map(int, input().split()))
dp = [0 for i in range(n+1)]
dp[min(a, b, c)] = 1
for i in range(min(a, b, c)+1, n+1):
dp[i] = max(get(dp[i - a]), get(dp[i-b]), get(dp[i-c])) + 1
... | 0 | |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,679,082,615 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 92 | 0 | n, k = map(int, input().split())
# start with all exams having a mark of 2
marks = [2] * n
total_marks = 2 * n
# increment the mark of an exam as long as doing so will not make the sum of marks greater than k
i = 0
while total_marks < k:
if marks[i] < 5:
marks[i] += 1
total_marks += 1
... | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
n, k = map(int, input().split())
# start with all exams having a mark of 2
marks = [2] * n
total_marks = 2 * n
# increment the mark of an exam as long as doing so will not make the sum of marks greater than k
i = 0
while total_marks < k:
if marks[i] < 5:
marks[i] += 1
total_ma... | 3 | |
893 | D | Credit Card | PROGRAMMING | 1,900 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Recenlty Luba got a credit card and started to use it. Let's consider *n* consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of *i*-th day a transaction *a**i* occurs. If *a**i*<=><=0, then *a**i* bourles are deposited to Luba's account. If *a**i*<=<<=0, then *a**i* bour... | The first line contains two integers *n*, *d* (1<=≤<=*n*<=≤<=105, 1<=≤<=*d*<=≤<=109) —the number of days and the money limitation.
The second line contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (<=-<=104<=≤<=*a**i*<=≤<=104), where *a**i* represents the transaction in *i*-th day. | Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money. | [
"5 10\n-1 5 0 -5 3\n",
"3 4\n-10 0 20\n",
"5 10\n-5 0 10 -11 0\n"
] | [
"0\n",
"-1\n",
"2\n"
] | none | 0 | [
{
"input": "5 10\n-1 5 0 -5 3",
"output": "0"
},
{
"input": "3 4\n-10 0 20",
"output": "-1"
},
{
"input": "5 10\n-5 0 10 -11 0",
"output": "2"
},
{
"input": "5 13756\n-2 -9 -10 0 10",
"output": "1"
},
{
"input": "20 23036\n-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 ... | 1,642,189,907 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 93 | 0 | import sys
input = sys.stdin.readline
n, d = map(int, input().split())
a = list(map(int, input().split()))
b = list(a)
for i in range(1, n):
b[i] += b[i - 1]
mb = [0] * n
mb[-1] = b[-1]
for i in range(n - 2, -1, -1):
mb[i] = max(mb[i + 1], b[i])
ans = 0
s = 0
for i in range(n):
b[i] += s
... | Title: Credit Card
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recenlty Luba got a credit card and started to use it. Let's consider *n* consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of *i*-th day a transaction *a**i* occurs. If *a**i*<=&... | ```python
import sys
input = sys.stdin.readline
n, d = map(int, input().split())
a = list(map(int, input().split()))
b = list(a)
for i in range(1, n):
b[i] += b[i - 1]
mb = [0] * n
mb[-1] = b[-1]
for i in range(n - 2, -1, -1):
mb[i] = max(mb[i + 1], b[i])
ans = 0
s = 0
for i in range(n):
b[i... | 0 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,558,435,576 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 109 | 307,200 | n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(8):
d[i]=0
for i in a:
d[i]+=1
if d[5] or d[7]:
print(-1)
exit()
if d[1]!=n//3:
print(-1)
exit()
n24=0
n36=0
n26=0
if d[2] and d[4]:
n24+=d[4]
d[2]-=d[4]
d[4]=0
if d[2]<0:
# print("Here2")
print(-1)
exit()
if d[2] and d[6]:
n26+=... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(8):
d[i]=0
for i in a:
d[i]+=1
if d[5] or d[7]:
print(-1)
exit()
if d[1]!=n//3:
print(-1)
exit()
n24=0
n36=0
n26=0
if d[2] and d[4]:
n24+=d[4]
d[2]-=d[4]
d[4]=0
if d[2]<0:
# print("Here2")
print(-1)
exit()
if d[2] and d[... | 0 | |
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are... | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15... | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n684... | 1,525,900,123 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 108 | 7,065,600 | import math
hh, mm = map(float, input().split())
H, D, C, N = map(float, input().split())
mm += hh*60
if mm >= 1200:
print((math.ceil(H / N)) * C * 0.8)
else:
print(min((math.ceil(H / N) * C), (math.ceil((H + D * (1200 - mm)) / N) * C * 0.8))) | Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without foo... | ```python
import math
hh, mm = map(float, input().split())
H, D, C, N = map(float, input().split())
mm += hh*60
if mm >= 1200:
print((math.ceil(H / N)) * C * 0.8)
else:
print(min((math.ceil(H / N) * C), (math.ceil((H + D * (1200 - mm)) / N) * C * 0.8)))
``` | 3 | |
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember... | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks... | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZT... | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNO... | 1,624,269,626 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 2,355,200 | from string import ascii_uppercase as alphabet
s = list(input())
ind = 0
while ind + 26 <= len(s):
need = list(alphabet)
cnt = 0
pos = []
for i in range(ind, ind + 26):
if s[i] == '?':
cnt += 1
pos.append(i)
else:
if s[i] in need:
... | Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In pa... | ```python
from string import ascii_uppercase as alphabet
s = list(input())
ind = 0
while ind + 26 <= len(s):
need = list(alphabet)
cnt = 0
pos = []
for i in range(ind, ind + 26):
if s[i] == '?':
cnt += 1
pos.append(i)
else:
if s[i] in need:... | 0 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,634,857,344 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 4,505,600 | n=int(input())
soldiers=list(map(int,input().split()))
lowestDiff=abs(soldiers[0]-soldiers[1])
stepper=0
for i in range(0,len(soldiers)):
if i == len(soldiers)-1:
if lowestDiff > abs(soldiers[i] - soldiers[0]):
stepper=len(soldiers)-1
elif lowestDiff > abs(soldiers[i]-soldiers[i+1]):... | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
n=int(input())
soldiers=list(map(int,input().split()))
lowestDiff=abs(soldiers[0]-soldiers[1])
stepper=0
for i in range(0,len(soldiers)):
if i == len(soldiers)-1:
if lowestDiff > abs(soldiers[i] - soldiers[0]):
stepper=len(soldiers)-1
elif lowestDiff > abs(soldiers[i]-soldi... | 3.968608 |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,635,179,135 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 77 | 19,148,800 | N=int(input())
cake=[ input() for x in range(N) ]
acc=0
for l in cake:
c=l.count('C')
acc += c*(c-1)//2
for col in range(N):
c=0
for l in range(N):
if cake[l][col] == 'C':
c+=1
acc += c*(c-1)//2
print(acc) | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
N=int(input())
cake=[ input() for x in range(N) ]
acc=0
for l in cake:
c=l.count('C')
acc += c*(c-1)//2
for col in range(N):
c=0
for l in range(N):
if cake[l][col] == 'C':
c+=1
acc += c*(c-1)//2
print(acc)
``` | 3 | |
1 | C | Ancient Berland Circus | PROGRAMMING | 2,100 | [
"geometry",
"math"
] | C. Ancient Berland Circus | 2 | 64 | Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a spec... | The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point. | Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100. | [
"0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n"
] | [
"1.00000000\n"
] | 0 | [
{
"input": "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000",
"output": "1.00000000"
},
{
"input": "71.756151 7.532275\n-48.634784 100.159986\n91.778633 158.107739",
"output": "9991.27897663"
},
{
"input": "18.716839 40.852752\n66.147248 -4.083161\n111.083161 43.347248",
"out... | 1,680,211,183 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | import sys
from math import acos, sqrt, pi
inp_points = sys.stdin.readlines()
all_coords = []
for point in inp_points:
all_coords += [float(x) for x in point.split()]
x1, y1, x2, y2, x3, y3 = all_coords
dx12, dx23, dy12, dy23 = x2 - x1, x2 - x3, y2 - y1, y2 - y3
xs, ys = x2 * x2 + y2 * y2 - x1 * x1 ... | Title: Ancient Berland Circus
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and t... | ```python
import sys
from math import acos, sqrt, pi
inp_points = sys.stdin.readlines()
all_coords = []
for point in inp_points:
all_coords += [float(x) for x in point.split()]
x1, y1, x2, y2, x3, y3 = all_coords
dx12, dx23, dy12, dy23 = x2 - x1, x2 - x3, y2 - y1, y2 - y3
xs, ys = x2 * x2 + y2 * y2 ... | 0 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,673,600,220 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | st = input()
i = 0
while i < len(st):
if st[i] == '.':
print(0, end="")
i += 1
elif st[i] == '-':
if st[i+1] == '.':
print(1, end='')
else:
print(2, end='')
i += 2 | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
st = input()
i = 0
while i < len(st):
if st[i] == '.':
print(0, end="")
i += 1
elif st[i] == '-':
if st[i+1] == '.':
print(1, end='')
else:
print(2, end='')
i += 2
``` | 3.977 |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,529,173,279 | 6,379 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 8 | 1,000 | 30,822,400 | from collections import OrderedDict
if __name__ == '__main__':
n, k = map(int, input().split(" "))
s = sorted(enumerate(map(int, input().split(" "))), key=lambda x: x[1], reverse=True)
coinsx = list(map(int, input().split(" ")))
c = sorted(enumerate(coinsx), key=lambda x: x[1], reverse=True)
mor... | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
from collections import OrderedDict
if __name__ == '__main__':
n, k = map(int, input().split(" "))
s = sorted(enumerate(map(int, input().split(" "))), key=lambda x: x[1], reverse=True)
coinsx = list(map(int, input().split(" ")))
c = sorted(enumerate(coinsx), key=lambda x: x[1], reverse=True... | 0 | |
596 | B | Wilbur and Array | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input.
The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). | Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. | [
"5\n1 2 3 4 5\n",
"4\n1 2 2 1\n"
] | [
"5",
"3"
] | In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.
In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1. | 1,000 | [
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 2 2 1",
"output": "3"
},
{
"input": "3\n1 2 4",
"output": "4"
},
{
"input": "6\n1 2 3 6 5 4",
"output": "8"
},
{
"input": "10\n2 1 4 3 6 5 8 7 10 9",
"output": "19"
},
{
"input": "7\n12 6 12 ... | 1,514,036,875 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 187 | 19,251,200 | n = int(input())
a = map(int, input().split())
s, p = 0, 0
for i in a:
s = s + abs(i - p)
p = i
print(s)
| Title: Wilbur and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+... | ```python
n = int(input())
a = map(int, input().split())
s, p = 0, 0
for i in a:
s = s + abs(i - p)
p = i
print(s)
``` | 3 | |
569 | A | Music | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite ... | The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105). | Print a single integer — the number of times the song will be restarted. | [
"5 2 2\n",
"5 4 7\n",
"6 2 3\n"
] | [
"2\n",
"1\n",
"1\n"
] | In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test,... | 500 | [
{
"input": "5 2 2",
"output": "2"
},
{
"input": "5 4 7",
"output": "1"
},
{
"input": "6 2 3",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "2 1 10000",
"output": "1"
},
{
"input": "12... | 1,439,225,559 | 1,359 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
n = int(input())
x = [int(i) for i in input().split()]
start = time.time()
print(x[1]-x[0], x[n-1]-x[0])
for i in range(1, n-1):
min_i = min(x[i] - x[i-1], x[i+1] - x[i])
max_i = max(x[i] - x[0], x[n-1] - x[i])
print(min_i, max_i)
print(x[... | Title: Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
n = int(input())
x = [int(i) for i in input().split()]
start = time.time()
print(x[1]-x[0], x[n-1]-x[0])
for i in range(1, n-1):
min_i = min(x[i] - x[i-1], x[i+1] - x[i])
max_i = max(x[i] - x[0], x[n-1] - x[i])
print(min_i, max_i)... | -1 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,642,782,089 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n=int(input())
s=input()
ans=[]
if(n%2==1):
ans.append(s[0])
for i in range(1,n):
if(i%2==0):
ans.append(s[i])
else:
ans.insert(0,s[i])
else:
ans.append(s[0])
for i in range(1,n):
if(i%2==1):
ans.append(s[i])
else:
... | 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()
ans=[]
if(n%2==1):
ans.append(s[0])
for i in range(1,n):
if(i%2==0):
ans.append(s[i])
else:
ans.insert(0,s[i])
else:
ans.append(s[0])
for i in range(1,n):
if(i%2==1):
ans.append(s[i])
el... | 3 | |
242 | C | King's Path | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contai... | If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one. | [
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n"
] | [
"4\n",
"6\n",
"-1\n"
] | none | 1,500 | [
{
"input": "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5",
"output": "4"
},
{
"input": "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10",
"output": "6"
},
{
"input": "1 1 2 10\n2\n1 1 3\n2 6 10",
"output": "-1"
},
{
"input": "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10... | 1,615,773,787 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 248 | 2,150,400 | def kingpath():
def adds(x, y, c):
s = (x, y)
if s in sgs and not s in his:
todo.append([x, y, c + 1])
his.add(s)
startx, starty, endx, endy = map(int, input().split()) # need to minus one
seg = int(input())
sgs = set()
for i in range(seg):
... | Title: King's Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with int... | ```python
def kingpath():
def adds(x, y, c):
s = (x, y)
if s in sgs and not s in his:
todo.append([x, y, c + 1])
his.add(s)
startx, starty, endx, endy = map(int, input().split()) # need to minus one
seg = int(input())
sgs = set()
for i in range(seg... | -1 | |
154 | B | Colliders | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.
In 2312 there was a startling discov... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of colliders and the number of requests, correspondingly.
Next *m* lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the *i*-th collider, or "- i" (without ... | Print *m* lines — the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes. | [
"10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3\n"
] | [
"Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on\n"
] | Note that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3". | 1,000 | [
{
"input": "10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3",
"output": "Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on"
},
{
"input": "7 5\n+ 7\n+ 6\n+ 4\n+ 3\n- 7",
"output": "Success\nSuccess\nConflict with 6\nConfli... | 1,621,668,843 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 22 | 2,000 | 10,752,000 | def check(t,a):
for i in range(2,len(a)):
if a[i]==1:
if gcd(t,i)!=1:
return i
return 0
def gcd(a,b):
ma=max(a,b)
mi=min(a,b)
while(ma%mi!=0):
tmp=mi
mi=ma%mi
ma=tmp
if mi==1:
return 1
return mi
l=list(map(in... | Title: Colliders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simul... | ```python
def check(t,a):
for i in range(2,len(a)):
if a[i]==1:
if gcd(t,i)!=1:
return i
return 0
def gcd(a,b):
ma=max(a,b)
mi=min(a,b)
while(ma%mi!=0):
tmp=mi
mi=ma%mi
ma=tmp
if mi==1:
return 1
return mi
l=l... | 0 | |
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,670,515,640 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 |
# n = int(input())
j = [int(i) for i in input().split(" ")]
# a, b = [int(i) for i in input().split(" ")]
m = min(j)
print(m, (sum(j) - 2 * m)//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 = int(input())
j = [int(i) for i in input().split(" ")]
# a, b = [int(i) for i in input().split(" ")]
m = min(j)
print(m, (sum(j) - 2 * m)//2)
``` | 3 | |
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag... | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denotin... | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the s... | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"inpu... | 1,642,067,571 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,f = map(int, input().split())
KL = []
for i in range(n):
KL.append(tuple(map(int, input().split())))
k,l = zip(*KL)
sales = []
uplift = []
for i in range(n):
k_ = k[i]
l_ = l[i]
if k_ >= l_:
sales.append(l_)
else:
sales.append(k_)
if 2*k_ >= l_:
... | Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an ass... | ```python
n,f = map(int, input().split())
KL = []
for i in range(n):
KL.append(tuple(map(int, input().split())))
k,l = zip(*KL)
sales = []
uplift = []
for i in range(n):
k_ = k[i]
l_ = l[i]
if k_ >= l_:
sales.append(l_)
else:
sales.append(k_)
if 2*k_... | 0 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,663,595,727 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | n= list(input())
ans =[]
for i in range(len(n)//10):
tmp = n[:10]
n= n[10:]
ans.append(tmp)
a2=[]
for i in ans:
a2.append(''.join(i))
ans=[]
for i in range(10):
ans.append(input())
s=''
for i in a2:
s+=str(ans.index(i))
print(s) | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
n= list(input())
ans =[]
for i in range(len(n)//10):
tmp = n[:10]
n= n[10:]
ans.append(tmp)
a2=[]
for i in ans:
a2.append(''.join(i))
ans=[]
for i in range(10):
ans.append(input())
s=''
for i in a2:
s+=str(ans.index(i))
print(s)
``` | 3.977 |
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original strin... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
... | 1,617,799,152 | 2,147,483,647 | PyPy 3 | OK | TESTS | 117 | 139 | 5,836,800 | n,k=map(int,input().split())
s=list(input())
aa=[0]*(n+1)
bb=[0]*(n+1)
res=1
a,b=0,0
for i in range(1,n+1):
if s[i-1]=="a":
a+=1
aa[a]=i
else:
b+=1
bb[b]=i
res=max(res,i-(aa[max(a-k,0)]))
res=max(res,i-(bb[max(b-k,0)]))
print(res) | Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ... | ```python
n,k=map(int,input().split())
s=list(input())
aa=[0]*(n+1)
bb=[0]*(n+1)
res=1
a,b=0,0
for i in range(1,n+1):
if s[i-1]=="a":
a+=1
aa[a]=i
else:
b+=1
bb[b]=i
res=max(res,i-(aa[max(a-k,0)]))
res=max(res,i-(bb[max(b-k,0)]))
print(res)
``` | 3 | |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,529,169,948 | 3,044 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 77 | 0 | read=lambda:map(int,input().split())
n,k=read()
p=list(read())
c=list(read())
t=[]
for i in range(n):
t.append((i,p[i],c[i]))
t.sort(key=lambda x:x[1])
#print(t)
ans=[0]*n
for i in range(n):
s=0
for j in range(max(0,i-k),i+1):
s+=t[j][2]
ans[t[i][0]]=s
print(*ans) | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
read=lambda:map(int,input().split())
n,k=read()
p=list(read())
c=list(read())
t=[]
for i in range(n):
t.append((i,p[i],c[i]))
t.sort(key=lambda x:x[1])
#print(t)
ans=[0]*n
for i in range(n):
s=0
for j in range(max(0,i-k),i+1):
s+=t[j][2]
ans[t[i][0]]=s
print(*ans)
``` | 0 | |
884 | B | Japanese Crosswords Strike Back | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<... | The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output":... | 1,509,114,429 | 1,328 | Python 3 | OK | TESTS | 66 | 77 | 7,372,800 | n, x = map(int, input().split())
s = sum(list(map(int, input().split())))
if s + n - 1 == x:
print("YES")
else:
print("NO")
| Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ... | ```python
n, x = map(int, input().split())
s = sum(list(map(int, input().split())))
if s + n - 1 == x:
print("YES")
else:
print("NO")
``` | 3 | |
879 | A | Borya's Diagnosis | PROGRAMMING | 900 | [
"implementation"
] | null | null | It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get t... | First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000). | Output a single integer — the minimum day at which Borya can visit the last doctor. | [
"3\n2 2\n1 2\n2 2\n",
"2\n10 1\n6 5\n"
] | [
"4\n",
"11\n"
] | In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11. | 500 | [
{
"input": "3\n2 2\n1 2\n2 2",
"output": "4"
},
{
"input": "2\n10 1\n6 5",
"output": "11"
},
{
"input": "3\n6 10\n3 3\n8 2",
"output": "10"
},
{
"input": "4\n4 8\n10 10\n4 2\n8 2",
"output": "14"
},
{
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8",
"output": "14"
},
... | 1,622,107,289 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n=int(input())
l=set({})
x=0
for _ in range(n):
s,d=map(int,input().split())
if x==0:i=s
elif x%d==0:i=(x//d-1)*d+s
else:i=(x//d)*d+s
while(1):
if i not in l and (x==0 or i>x):
l.add(i)
x=i
break
i+=d
print(x) | Title: Borya's Diagnosis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed o... | ```python
n=int(input())
l=set({})
x=0
for _ in range(n):
s,d=map(int,input().split())
if x==0:i=s
elif x%d==0:i=(x//d-1)*d+s
else:i=(x//d)*d+s
while(1):
if i not in l and (x==0 or i>x):
l.add(i)
x=i
break
i+=d
print(x)
``` | 0 | |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,694,218,255 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n = int(input())
s = input()
if 'p' in s and 'a' in s and 'n' in s and 'g' in s and 'r' and 'm' in s:
print("YES")
else:
print("NO")
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
n = int(input())
s = input()
if 'p' in s and 'a' in s and 'n' in s and 'g' in s and 'r' and 'm' in s:
print("YES")
else:
print("NO")
``` | 0 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,502,958,738 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 124 | 0 | code = input()
dic = {}
for i in range(10):
str = input()
dic[str] = i
while len(code) > 0 :
print(dic[code[0:10]], end='')
code = code[10:] | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
code = input()
dic = {}
for i in range(10):
str = input()
dic[str] = i
while len(code) > 0 :
print(dic[code[0:10]], end='')
code = code[10:]
``` | 3.969 |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,698,952,180 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | n,k=map(int,input().split())
l=list(map(int,input().split()))
c=0
if(l[0]<=0):
print("0")
else:
for i in range(n):
if(l[i]>=l[k-1]):
c+=1
print(c) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
c=0
if(l[0]<=0):
print("0")
else:
for i in range(n):
if(l[i]>=l[k-1]):
c+=1
print(c)
``` | 0 | |
373 | B | Making Sequences is Fun | PROGRAMMING | 1,600 | [
"binary search",
"implementation",
"math"
] | null | null | We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6.
You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the ... | The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109).
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | The first line should contain a single integer — the answer to the problem. | [
"9 1 1\n",
"77 7 7\n",
"114 5 14\n",
"1 1 2\n"
] | [
"9\n",
"7\n",
"6\n",
"0\n"
] | none | 1,000 | [
{
"input": "9 1 1",
"output": "9"
},
{
"input": "77 7 7",
"output": "7"
},
{
"input": "114 5 14",
"output": "6"
},
{
"input": "1 1 2",
"output": "0"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"i... | 1,386,944,134 | 934 | Python 3 | WRONG_ANSWER | PRETESTS | 11 | 62 | 0 | import math
w,m,k=map(int,input().split())
x=int("1"+("0"*len(str(m))))
h=x-m
n=len(str(m))
ans=w//(n*k)
if(ans>h):
ans=h
w-=h*n*k
while(w>0):
n+=1
x=w//(n*k)
if(x>=10**(n-1)*9):
ans+=10**(n-1)*9
w-=(n*k*10**(n-1)*9)
else:
ans+=x
... | Title: Making Sequences is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6.
You want to make a consecutive integer sequence sta... | ```python
import math
w,m,k=map(int,input().split())
x=int("1"+("0"*len(str(m))))
h=x-m
n=len(str(m))
ans=w//(n*k)
if(ans>h):
ans=h
w-=h*n*k
while(w>0):
n+=1
x=w//(n*k)
if(x>=10**(n-1)*9):
ans+=10**(n-1)*9
w-=(n*k*10**(n-1)*9)
else:
ans... | 0 | |
964 | A | Splits | PROGRAMMING | 800 | [
"math"
] | null | null | Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
Th... | The first line contains one integer $n$ ($1 \leq n \leq 10^9$). | Output one integer — the answer to the problem. | [
"7\n",
"8\n",
"9\n"
] | [
"4\n",
"5\n",
"5\n"
] | In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | 500 | [
{
"input": "7",
"output": "4"
},
{
"input": "8",
"output": "5"
},
{
"input": "9",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "286",
"output": "144"
},
{
"input": "48",
"output": "25"
},
{
"input": "941",
"output": "471... | 1,530,287,389 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | import math
n = int(input())
li = []
for i in range(1, n+1):
li.append(math.floor(n/i))
#print(li)
s = set(li)
if n % 2:
print(len(s))
else:
print(len(s)+1)
| Title: Splits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The foll... | ```python
import math
n = int(input())
li = []
for i in range(1, n+1):
li.append(math.floor(n/i))
#print(li)
s = set(li)
if n % 2:
print(len(s))
else:
print(len(s)+1)
``` | 0 | |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,628,235,350 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 6,758,400 | n = int(input())
array = list(map(int, input().split()))
array.sort()
if n == 1:
print(array[0] + 1)
else:
ans = 0
for i in range(n - 1):
if array[i + 1] != array[i] + 1:
ans = array[i] + 1
break
print(ans)
| Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
n = int(input())
array = list(map(int, input().split()))
array.sort()
if n == 1:
print(array[0] + 1)
else:
ans = 0
for i in range(n - 1):
if array[i + 1] != array[i] + 1:
ans = array[i] + 1
break
print(ans)
``` | 0 |
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of ... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": ... | 1,623,434,449 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n, m = map(int,input().split())
l = []
k = 0
for i in range(n):
l.append(len(input()))
c = len(input())
if len(set(l))==1:
print(1, ((m+5)*(n//m))+(n%m))
else:
for i in set(l):
if i<c:
k += l.count(i)
else:
break
print(c+1, ((m+5)*(n//m))+(n%m)) | Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords... | ```python
n, m = map(int,input().split())
l = []
k = 0
for i in range(n):
l.append(len(input()))
c = len(input())
if len(set(l))==1:
print(1, ((m+5)*(n//m))+(n%m))
else:
for i in set(l):
if i<c:
k += l.count(i)
else:
break
print(c+1, ((m+5)*(n//m))+(... | 0 | |
622 | C | Not Equal on a Segment | PROGRAMMING | 1,700 | [
"data structures",
"implementation"
] | null | null | You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*.
For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of elements in *a* and the number of queries.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=... | Print *m* lines. On the *i*-th line print integer *p**i* — the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number. | [
"6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n"
] | [
"2\n6\n-1\n4\n"
] | none | 0 | [
{
"input": "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2",
"output": "2\n6\n-1\n4"
},
{
"input": "1 1\n1\n1 1 1",
"output": "-1"
},
{
"input": "1 1\n2\n1 1 2",
"output": "-1"
},
{
"input": "1 1\n569888\n1 1 967368",
"output": "1"
},
{
"input": "10 10\n1 1 1 1 1 1 ... | 1,463,296,619 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 4,608,000 | n,m = [int(i) for i in input().split()]
a=[int(i) for i in input().split()]
for i in range(m):
k = 1
l,r,x = [int(i) for i in input().split()]
for j in a[l-1:r]:
#print(a[j])
if x !=a[j]:
k = 0
print(j+1)
break
if k:
print(-1)
| Title: Not Equal on a Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*.
For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so ... | ```python
n,m = [int(i) for i in input().split()]
a=[int(i) for i in input().split()]
for i in range(m):
k = 1
l,r,x = [int(i) for i in input().split()]
for j in a[l-1:r]:
#print(a[j])
if x !=a[j]:
k = 0
print(j+1)
break
if k:
print... | 0 | |
300 | C | Beautiful Numbers | PROGRAMMING | 1,800 | [
"brute force",
"combinatorics"
] | null | null | Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number.
For example, let's say that Vitaly's favourite dig... | The first line contains three integers: *a*, *b*, *n* (1<=≤<=*a*<=<<=*b*<=≤<=9,<=1<=≤<=*n*<=≤<=106). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"1 3 3\n",
"2 3 10\n"
] | [
"1\n",
"165\n"
] | none | 2,000 | [
{
"input": "1 3 3",
"output": "1"
},
{
"input": "2 3 10",
"output": "165"
},
{
"input": "6 8 14215",
"output": "651581472"
},
{
"input": "4 9 104671",
"output": "329390901"
},
{
"input": "6 7 78755",
"output": "0"
},
{
"input": "1 8 265",
"output":... | 1,645,044,587 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 2,000 | 24,576,000 | factorials = list()
factorials.append(1)
def modular_exponentiation(b,e,m):
binary = bin(e)[2:]
x = b
result = 1
for i in binary[::-1]:
if i =='1':
result *= x
result = result%m
x*=x
x=x%m
return result
def inverse(a):
return... | Title: Beautiful Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number ex... | ```python
factorials = list()
factorials.append(1)
def modular_exponentiation(b,e,m):
binary = bin(e)[2:]
x = b
result = 1
for i in binary[::-1]:
if i =='1':
result *= x
result = result%m
x*=x
x=x%m
return result
def inverse(a):
... | 0 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,690,262,505 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 11 | 77 | 0 | a,b=list(map(int,input().split(" ")))
print("YES") if a-b==0 or abs(a-b)==1 else print("NO") | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
a,b=list(map(int,input().split(" ")))
print("YES") if a-b==0 or abs(a-b)==1 else print("NO")
``` | 0 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,665,318,288 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | n=int(input())
c=0
for i in range(1,n//2+1):
if ((n-i)//i)*i==n-i:
c+=1
print(c)
| Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
n=int(input())
c=0
for i in range(1,n//2+1):
if ((n-i)//i)*i==n-i:
c+=1
print(c)
``` | 3 | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,688,379,866 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | a,b,c,d=map(int,input().split())
print(d) | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
a,b,c,d=map(int,input().split())
print(d)
``` | 0 | |
629 | B | Far Relative’s Problem | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends.
Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i... | Print the maximum number of people that may come to Famil Door's party. | [
"4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n",
"6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n"
] | [
"2\n",
"4\n"
] | In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. | 1,000 | [
{
"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128",
"output": "2"
},
{
"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200",
"output": "4"
},
{
"input": "1\nF 68 307",
"output": "0"
},
{
"input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\... | 1,458,544,792 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 202 | 5,120,000 | def get(n):
if n=="M" or n=="F":
return n
else:
return int(n)
n = int(input())
mylist=[[0]*367,[0]*367]
for i in range(n):
g,a,b = map(get,input().split())
if g=='M':
index=0
else:
index=1
for i in range(a,b+1):
mylist[index][i]+=1
mylist ... | Title: Far Relative’s Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, F... | ```python
def get(n):
if n=="M" or n=="F":
return n
else:
return int(n)
n = int(input())
mylist=[[0]*367,[0]*367]
for i in range(n):
g,a,b = map(get,input().split())
if g=='M':
index=0
else:
index=1
for i in range(a,b+1):
mylist[index][i]+=... | 3 | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,696,426,316 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | a = input()
s = list(str(i) for i in a)
len_s = len(s)
glas = ["A", "O", "Y", "E", "U", "I", "a", "o", "y", "e", "u", "i"]
s1 = ''
for i in range(len_s):
if s[i] in glas:
s1 = s1 + ''
else:
s1 = s1 + '.' + s[i]
print(s1)
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
a = input()
s = list(str(i) for i in a)
len_s = len(s)
glas = ["A", "O", "Y", "E", "U", "I", "a", "o", "y", "e", "u", "i"]
s1 = ''
for i in range(len_s):
if s[i] in glas:
s1 = s1 + ''
else:
s1 = s1 + '.' + s[i]
print(s1)
``` | 0 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,684,695,985 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 3,993,600 | def main():
hurt = []
punched = int(input())
shut = int(input())
trampled = int(input())
ran = int(input())
dragons = int(input())
for i in range(1, dragons + 1):
if i % punched == 0 or i % shut == 0 or i % trampled == 0 or i % ran == 0:
if i not in hurt:
... | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
def main():
hurt = []
punched = int(input())
shut = int(input())
trampled = int(input())
ran = int(input())
dragons = int(input())
for i in range(1, dragons + 1):
if i % punched == 0 or i % shut == 0 or i % trampled == 0 or i % ran == 0:
if i not in hurt:
... | 0 | |
557 | A | Ilya and Diplomas | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | null | null | Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly... | The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the fir... | In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first... | [
"6\n1 5\n2 6\n3 7\n",
"10\n1 2\n1 3\n1 5\n",
"6\n1 3\n2 2\n2 2\n"
] | [
"1 2 3 \n",
"2 3 5 \n",
"2 2 2 \n"
] | none | 500 | [
{
"input": "6\n1 5\n2 6\n3 7",
"output": "1 2 3 "
},
{
"input": "10\n1 2\n1 3\n1 5",
"output": "2 3 5 "
},
{
"input": "6\n1 3\n2 2\n2 2",
"output": "2 2 2 "
},
{
"input": "55\n1 1000000\n40 50\n10 200",
"output": "5 40 10 "
},
{
"input": "3\n1 1\n1 1\n1 1",
"o... | 1,443,412,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 409,600 | #!/usr/bin/python3
import itertools as ittls
from collections import Counter
import re
import math
def sqr(x):
return x*x
def inputarray(func=int):
return map(func, input().split())
# --------------------------------------
# --------------------------------------
N = int(input())
x1, y1 = inputarray()
x2... | Title: Ilya and Diplomas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the re... | ```python
#!/usr/bin/python3
import itertools as ittls
from collections import Counter
import re
import math
def sqr(x):
return x*x
def inputarray(func=int):
return map(func, input().split())
# --------------------------------------
# --------------------------------------
N = int(input())
x1, y1 = input... | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,676,110,196 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 3,174,400 | import sys
weight = sys.stdin.readlines().split("\n")
print(weight)
for word in weight[1:]:
if len(word) <= 10:
print(word)
elif len(word) > 10:
length = len(word) - 2
print(word[0] + str(length) + word[-1])
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
import sys
weight = sys.stdin.readlines().split("\n")
print(weight)
for word in weight[1:]:
if len(word) <= 10:
print(word)
elif len(word) > 10:
length = len(word) - 2
print(word[0] + str(length) + word[-1])
``` | -1 |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,694,516,725 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | num=input()
count=0
for i in num:
if(i=='4' or i=='7):
count+=1
if(count==4 or count==7):
print("YES")
else:
print("NO") | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
num=input()
count=0
for i in num:
if(i=='4' or i=='7):
count+=1
if(count==4 or count==7):
print("YES")
else:
print("NO")
``` | -1 |
321 | C | Ciel the Commander | PROGRAMMING | 2,100 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer",
"greedy",
"trees"
] | null | null | Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them.
Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Tree Land.
Each of the following *n*<=-<=1 lines contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*) — they mean that there will be an undirected road between *a* and *b*. Consider all the cities are numbered fro... | If there is a valid plane, output *n* space-separated characters in a line — *i*-th character is the rank of officer in the city with number *i*.
Otherwise output "Impossible!". | [
"4\n1 2\n1 3\n1 4\n",
"10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n"
] | [
"A B B B\n",
"D C B A D C B D C D\n"
] | In the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution. | 1,500 | [
{
"input": "4\n1 2\n1 3\n1 4",
"output": "A B B B"
},
{
"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10",
"output": "D C B A D C B D C D"
},
{
"input": "6\n1 2\n2 4\n4 5\n6 4\n3 2",
"output": "B A B B C C"
},
{
"input": "2\n2 1",
"output": "A B"
},
{
"i... | 1,605,318,734 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 278 | 307,200 | def solve():
from collections import deque
from sys import stdin
input = stdin.buffer.readline
n = int(input())
tree = [[] for _ in range(n)]
used = [False] * n
par = [None] * n
size = [1] * n
stack = deque([])
ord = []
for _ in range(n - 1):
u, v = ... | Title: Ciel the Commander
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them.
Fox Ciel needs to... | ```python
def solve():
from collections import deque
from sys import stdin
input = stdin.buffer.readline
n = int(input())
tree = [[] for _ in range(n)]
used = [False] * n
par = [None] * n
size = [1] * n
stack = deque([])
ord = []
for _ in range(n - 1):
... | 0 | |
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 1... | 1,660,458,375 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | import sys
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().split()]
ldp = [1 for i in range(n)]
rdp = [1 for i in range(n)]
for i in range(1, n):
if a[i] > a[i-1]:
ldp[i] = ldp[i-1]+1
for i in range(n-2, -1, -1):
if a[i] < a[i+1]:
rdp[i] = rdp[i+1]+1
mx = 2
for i in r... | Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the... | ```python
import sys
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().split()]
ldp = [1 for i in range(n)]
rdp = [1 for i in range(n)]
for i in range(1, n):
if a[i] > a[i-1]:
ldp[i] = ldp[i-1]+1
for i in range(n-2, -1, -1):
if a[i] < a[i+1]:
rdp[i] = rdp[i+1]+1
mx = 2
... | 0 | |
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,555,582,037 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 404 | 1,024,000 | import string
s = input()
up = sum(s.count(c) for c in string.ascii_uppercase)
lo = sum(s.count(c) for c in string.ascii_lowercase)
print(s.upper() if up > lo else s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
import string
s = input()
up = sum(s.count(c) for c in string.ascii_uppercase)
lo = sum(s.count(c) for c in string.ascii_lowercase)
print(s.upper() if up > lo else s.lower())
``` | 3.897093 |
259 | A | Little Elephant and Chess | PROGRAMMING | 1,000 | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d... | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black co... | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | 500 | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBW... | 1,576,182,876 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 248 | 0 | def str_inp(n):
return [input() for x in range(n)]
def check(x):
if x != 'WB' * 4 and x != 'BW' * 4:
exit(print('NO'))
return 'YES'
s = str_inp(8)
print(list(map(check, s))[0])
| Title: Little Elephant and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, e... | ```python
def str_inp(n):
return [input() for x in range(n)]
def check(x):
if x != 'WB' * 4 and x != 'BW' * 4:
exit(print('NO'))
return 'YES'
s = str_inp(8)
print(list(map(check, s))[0])
``` | 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,611,181,470 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | import sys
input = sys.stdin.readline()
contador = 0
values = input.split()
a = int(values[0])
b = int(values[1])
Tablero = a * b
while Tablero >= 2:
contador += 1
Tablero -= 2
print(contador) | 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
import sys
input = sys.stdin.readline()
contador = 0
values = input.split()
a = int(values[0])
b = int(values[1])
Tablero = a * b
while Tablero >= 2:
contador += 1
Tablero -= 2
print(contador)
``` | 3.969 |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,420,219,240 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 686 | 5,120,000 | def main():
n = int(input())
l, r = [], []
for _ in range(n):
a, b = map(int, input().split())
l.append(a)
r.append(b)
m = min(l), max(r)
for i, a in enumerate(zip(l, r)):
if a == m:
print(i + 1)
return
print(-1)
if __name__ == '__main__'... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
def main():
n = int(input())
l, r = [], []
for _ in range(n):
a, b = map(int, input().split())
l.append(a)
r.append(b)
m = min(l), max(r)
for i, a in enumerate(zip(l, r)):
if a == m:
print(i + 1)
return
print(-1)
if __name__ == ... | 3 | |
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,541,247,046 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 202 | 7,372,800 | n, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
res = 0
for i in a:
res += x * i
if x > 1:
x -= 1
print(res)
| 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 = sorted(a)
res = 0
for i in a:
res += x * i
if x > 1:
x -= 1
print(res)
``` | 3 | |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,567,319,323 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 34 | 2,000 | 6,963,200 |
def zalgo(s = '') -> list:
L = R = 0
n = len(s)
z = [0] * n
for i in range(n):
if i > R:
L = R = i
while R < n and s[R-L] == s[R]:
R += 1
z[i] = R - L
R -= 1
else:
k = i - L
if z[k] < R - i + 1:
... | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
def zalgo(s = '') -> list:
L = R = 0
n = len(s)
z = [0] * n
for i in range(n):
if i > R:
L = R = i
while R < n and s[R-L] == s[R]:
R += 1
z[i] = R - L
R -= 1
else:
k = i - L
if z[k] < R - i... | 0 | |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,538,240,511 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | A,B,C,N= [ int (x) for x in input().split( ) ]
d= A-C
e=B-C
if ( (N-(d+e+C )) > 0 ) :
print (N-(d+e+C ))
else:
print(-1) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
A,B,C,N= [ int (x) for x in input().split( ) ]
d= A-C
e=B-C
if ( (N-(d+e+C )) > 0 ) :
print (N-(d+e+C ))
else:
print(-1)
``` | 0 | |
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,609,345,056 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 248 | 0 | '''
The first line contains a positive integer n (1 ≤ n ≤ 100),
then follow n lines containing three integers each:the xi coordinate,
the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100)
'''
k = int(input())
res=0
for i in range(k):
x = list(map(int, input(... | 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
'''
The first line contains a positive integer n (1 ≤ n ≤ 100),
then follow n lines containing three integers each:the xi coordinate,
the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100)
'''
k = int(input())
res=0
for i in range(k):
x = list(map(i... | 0 |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,692,331,245 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | /// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl '\n'
#define PI acos(-1.0)
#define mod(a, b) (((a) % (b)) + (b)) % (b)
#define sz(v) (ll) v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#de... | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
/// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl '\n'
#define PI acos(-1.0)
#define mod(a, b) (((a) % (b)) + (b)) % (b)
#define sz(v) (ll) v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.ren... | -1 | |
622 | D | Optimal Number Permutation | PROGRAMMING | 1,900 | [
"constructive algorithms"
] | null | null | You have array *a* that contains all integers from 1 to *n* twice. You can arbitrary permute any numbers in *a*.
Let number *i* be in positions *x**i*,<=*y**i* (*x**i*<=<<=*y**i*) in the permuted array *a*. Let's define the value *d**i*<==<=*y**i*<=-<=*x**i* — the distance between the positions of the number *i*. P... | The only line contains integer *n* (1<=≤<=*n*<=≤<=5·105). | Print 2*n* integers — the permuted array *a* that minimizes the value of the sum *s*. | [
"2\n",
"1\n"
] | [
"1 1 2 2\n",
"1 1\n"
] | none | 0 | [
{
"input": "2",
"output": "1 1 2 2"
},
{
"input": "1",
"output": "1 1"
},
{
"input": "3",
"output": "1 3 1 2 2 3"
},
{
"input": "4",
"output": "1 3 3 1 2 4 2 4"
},
{
"input": "10",
"output": "1 3 5 7 9 9 7 5 3 1 2 4 6 8 10 8 6 4 2 10"
},
{
"input": "10... | 1,646,968,210 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 826 | 75,264,000 | n = int(input())
ans = [n] * (2 * n)
for i in range(1, n + 1):
x = i // 2 if i & 1 else n - 1 + i // 2
y = x + n - i
ans[x], ans[y] = i, i
print(*ans)
| Title: Optimal Number Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have array *a* that contains all integers from 1 to *n* twice. You can arbitrary permute any numbers in *a*.
Let number *i* be in positions *x**i*,<=*y**i* (*x**i*<=<<=*y**i*) in the permuted array *a... | ```python
n = int(input())
ans = [n] * (2 * n)
for i in range(1, n + 1):
x = i // 2 if i & 1 else n - 1 + i // 2
y = x + n - i
ans[x], ans[y] = i, i
print(*ans)
``` | 3 | |
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==... | The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). | Output a single integer — the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
... | 1,405,257,069 | 669 | Python 3 | OK | TESTS | 29 | 93 | 0 | p,n=map(int,input().split())
x=[0 for i in range(n)]
for i in range(n):
x[i]=int(input())
was=[0 for i in range(p)]
k=-1
for i in range(n):
if was[x[i]%p]:
k=i+1
break
else:
was[x[i]%p]=1
print(k) | Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere... | ```python
p,n=map(int,input().split())
x=[0 for i in range(n)]
for i in range(n):
x[i]=int(input())
was=[0 for i in range(p)]
k=-1
for i in range(n):
if was[x[i]%p]:
k=i+1
break
else:
was[x[i]%p]=1
print(k)
``` | 3 | |
89 | A | Robbery | PROGRAMMING | 1,800 | [
"greedy"
] | A. Robbery | 1 | 256 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has *n* cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to *n* from the left to the right.
Unfortunately, ... | The first line contains integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=104, 1<=≤<=*m*,<=*k*<=≤<=109). The next line contains *n* numbers. The *i*-th number is equal to the amount of diamonds in the *i*-th cell — it is an integer from 0 to 105. | Print a single number — the maximum number of diamonds Joe can steal. | [
"2 3 1\n2 3\n",
"3 2 2\n4 1 3\n"
] | [
"0",
"2"
] | In the second sample Joe can act like this:
The diamonds' initial positions are 4 1 3.
During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.
By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference... | 500 | [
{
"input": "2 3 1\n2 3",
"output": "0"
},
{
"input": "3 2 2\n4 1 3",
"output": "2"
},
{
"input": "5 10 10\n7 0 7 0 7",
"output": "7"
},
{
"input": "6 10 4\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "7 5 2\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "1... | 1,689,342,253 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689342253.685853")# 1689342253.68589 | Title: Robbery
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has *n* cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark t... | ```python
print("_RANDOM_GUESS_1689342253.685853")# 1689342253.68589
``` | 0 |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,694,653,489 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 436 | 14,848,000 | def find_worm_piles(n, piles, m, worms):
prefix_sum = [0] * (n + 1)
# 计算前缀和
for i in range(1, n + 1):
prefix_sum[i] = prefix_sum[i - 1] + piles[i - 1]
result = []
for j in range(m):
worm_label = worms[j]
# 二分查找虫子所在的堆
left, right = 1, n
while le... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
def find_worm_piles(n, piles, m, worms):
prefix_sum = [0] * (n + 1)
# 计算前缀和
for i in range(1, n + 1):
prefix_sum[i] = prefix_sum[i - 1] + piles[i - 1]
result = []
for j in range(m):
worm_label = worms[j]
# 二分查找虫子所在的堆
left, right = 1, n
... | 3 | |
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,683,267,750 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | lights = []
for x in range(3):
row = list(map(int, input().split()))
lights.append(row)
for x in range(3):
for y in range(3):
total = 0
total += lights[x][y]
if y != 0:
total += lights[x][y-1]
if y != 2:
total += lights[x][y+1]
if x... | 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
lights = []
for x in range(3):
row = list(map(int, input().split()))
lights.append(row)
for x in range(3):
for y in range(3):
total = 0
total += lights[x][y]
if y != 0:
total += lights[x][y-1]
if y != 2:
total += lights[x][y+1]
... | 3 | |
605 | A | Sorting Railway Cars | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and telepor... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train.
The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. | Print a single integer — the minimum number of actions needed to sort the railway cars. | [
"5\n4 1 2 5 3\n",
"4\n4 1 3 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train. | 500 | [
{
"input": "5\n4 1 2 5 3",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "6\n5 3 6 1 4 2",
"output": "4"
},
... | 1,658,821,824 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 233 | 13,414,400 | n = int(input())
nums = list(map(int, input().split()))
note_nums = sorted([(val, idx) for idx, val in enumerate(nums)])
tmp = [0] * n
for i in range(n):
tmp[note_nums[i][1]] = i
ans = [0] * (n + 1)
for val in tmp:
ans[val + 1] = ans[val] + 1
print(n - max(ans)) | Title: Sorting Railway Cars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the... | ```python
n = int(input())
nums = list(map(int, input().split()))
note_nums = sorted([(val, idx) for idx, val in enumerate(nums)])
tmp = [0] * n
for i in range(n):
tmp[note_nums[i][1]] = i
ans = [0] * (n + 1)
for val in tmp:
ans[val + 1] = ans[val] + 1
print(n - max(ans))
``` | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,611,576,814 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 93 | 0 | n,m=map(int,input().split())
a=b=c=0
for i in range(1,7):t=abs(n-i)-abs(m-i);a+=t<0;b+=t==0;c+=t>0
print(a,b,c) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
n,m=map(int,input().split())
a=b=c=0
for i in range(1,7):t=abs(n-i)-abs(m-i);a+=t<0;b+=t==0;c+=t>0
print(a,b,c)
``` | 3 | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,668,028,688 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | r=int(input())
k=str(input())
def cosita(r,k,re=r-1):
for i in range(r-1):
if k[(2*i)+1]==k[2*i].upper():
re-=1
else:
f=k.find(k[2*i].upper())
if f!=-1:
re-=1
k=k.replace(k[f],'0',1)
return re
print(cosita(r,k))
... | Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
r=int(input())
k=str(input())
def cosita(r,k,re=r-1):
for i in range(r-1):
if k[(2*i)+1]==k[2*i].upper():
re-=1
else:
f=k.find(k[2*i].upper())
if f!=-1:
re-=1
k=k.replace(k[f],'0',1)
return re
print(cosita(r,k))
... | 0 | |
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,669,381,069 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 0 | l=[]
l.append([0,0,0,0,0])
for _ in range(3):
l2=[]
l2.append(0)
l2.extend(list(map(int ,input().split())))
l2.append(0)
l.append(l2)
l.append([0,0,0,0,0])
for i in range(1,4):
for j in range(1,4):
if (l[i][j]+l[i][j-1]+l[i][j+1]+l[i+1][j]+l[i-1][j])%2:print(0,end='')
... | 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
l=[]
l.append([0,0,0,0,0])
for _ in range(3):
l2=[]
l2.append(0)
l2.extend(list(map(int ,input().split())))
l2.append(0)
l.append(l2)
l.append([0,0,0,0,0])
for i in range(1,4):
for j in range(1,4):
if (l[i][j]+l[i][j-1]+l[i][j+1]+l[i+1][j]+l[i-1][j])%2:print(0,end... | 3 | |
250 | B | Restoring IPv6 | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100).
Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | 1,000 | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000... | 1,606,906,690 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 310 | 0 | n = eval(input())
for i in range(n):
ans = ''
k =''
s = input().split(':')
c = 0
m = 0
for g in range(len(s)):
if s[g] != '':
c += 1
if c == 8:
for j in range(c):
s[j] = (4-len(s[j]))*'0' + s[j]
ans += s[j] +':'
else:
k = (8-c)*... | Title: Restoring IPv6
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. He... | ```python
n = eval(input())
for i in range(n):
ans = ''
k =''
s = input().split(':')
c = 0
m = 0
for g in range(len(s)):
if s[g] != '':
c += 1
if c == 8:
for j in range(c):
s[j] = (4-len(s[j]))*'0' + s[j]
ans += s[j] +':'
else:
... | 3 | |
583 | B | Robot's Task | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to colle... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. | Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information. | [
"3\n0 2 0\n",
"5\n4 2 3 0 1\n",
"7\n0 3 1 0 5 2 6\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to... | 1,000 | [
{
"input": "3\n0 2 0",
"output": "1"
},
{
"input": "5\n4 2 3 0 1",
"output": "3"
},
{
"input": "7\n0 3 1 0 5 2 6",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "0"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"out... | 1,443,891,810 | 1,110 | Python 3 | OK | TESTS | 56 | 374 | 0 | n = int(input())
a = [int(x) for x in input().split()]
k = 0
pov = 0
used = [False] * n
for i in range(n):
for j in range(n):
if used[j] == False and a[j] <= k:
used[j] = True
k += 1
r = 0
for j in range(n):
if used[j] == False:
r = 1
if ... | Title: Robot's Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The compu... | ```python
n = int(input())
a = [int(x) for x in input().split()]
k = 0
pov = 0
used = [False] * n
for i in range(n):
for j in range(n):
if used[j] == False and a[j] <= k:
used[j] = True
k += 1
r = 0
for j in range(n):
if used[j] == False:
r = ... | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,693,112,917 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n = input()
j = input().split(" ")
r = []
for i in range(len(j)):
k = j.index(f"{i+1}")
r.append(str(k+1))
print(" ".join(r))
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n = input()
j = input().split(" ")
r = []
for i in range(len(j)):
k = j.index(f"{i+1}")
r.append(str(k+1))
print(" ".join(r))
``` | 3 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,604,569,910 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 372 | 307,200 | s = int(input())
a = input().split()
b = []
for i in range(s):
b.append(int(a[i]))
c = set(b)
n = len(c)
q = 0
for i in c:
p = 0
for j in range(s):
if i == b[j]:
p += 1
if p > q:
q = p
print(q, n) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
s = int(input())
a = input().split()
b = []
for i in range(s):
b.append(int(a[i]))
c = set(b)
n = len(c)
q = 0
for i in c:
p = 0
for j in range(s):
if i == b[j]:
p += 1
if p > q:
q = p
print(q, n)
``` | 3.906428 |
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,675,446,462 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 4,505,600 | n = input()
t=n[0]
c = 1
flag = 0
for i in range(1,len(n)):
if t == n[i]:
c += 1
if c >= 7:
flag = 1
break
else:
c = 1
t=n[i]
if flag == 1:
print("YES")
else:
print("NO")
| 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
n = input()
t=n[0]
c = 1
flag = 0
for i in range(1,len(n)):
if t == n[i]:
c += 1
if c >= 7:
flag = 1
break
else:
c = 1
t=n[i]
if flag == 1:
print("YES")
else:
print("NO")
``` | 3.968608 |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,588,663,252 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 280 | 0 | n=int(input())
l=list(map(int,input().split()))
s=len(set(l))
print(n-s)
| Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n=int(input())
l=list(map(int,input().split()))
s=len(set(l))
print(n-s)
``` | 0 | |
975 | A | Aramic script | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$... | The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | 500 | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
... | 1,603,569,132 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 296 | 6,553,600 |
R = lambda:map(int,input().split())
n, = R()
a = input().split()
ans = set()
for i in a:
i = "".join(list(sorted(set(i))))
if i not in ans:
ans.add(i)
print(len(ans))
| Title: Aramic script
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the ... | ```python
R = lambda:map(int,input().split())
n, = R()
a = input().split()
ans = set()
for i in a:
i = "".join(list(sorted(set(i))))
if i not in ans:
ans.add(i)
print(len(ans))
``` | 3 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,600,458,478 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | n = int(input())
ans = 0
for i in range(2,n):
ans += (n%i)+1
print(str(ans)+"/"+str((n-2))) | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
n = int(input())
ans = 0
for i in range(2,n):
ans += (n%i)+1
print(str(ans)+"/"+str((n-2)))
``` | 0 |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,544,191,735 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 124 | 0 | w = list(map(int,input().split()))
l = w[0]
r =w[1]
a = w[2]
while a >1:
if (l==r) and a !=1:
l+=1
r+=1
a-=2
elif l>r:
r +=1
a -=1
elif r >l:
l+=1
a-=1
if a ==1:
if l>r:
r+=1
else:
l+=1
if l ==r:
print... | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
w = list(map(int,input().split()))
l = w[0]
r =w[1]
a = w[2]
while a >1:
if (l==r) and a !=1:
l+=1
r+=1
a-=2
elif l>r:
r +=1
a -=1
elif r >l:
l+=1
a-=1
if a ==1:
if l>r:
r+=1
else:
l+=1
if l ==r:
... | 3 | |
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s... | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is ... | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT... | 1,499,494,307 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 62 | 5,529,600 | def Count(string, number):
number //=4
lists = list(string)
a = number - lists.count('A')
c = number - lists.count('C')
g = number - lists.count('G')
t = number - lists.count('T')
return [a, c, g, t]
def Check(string, number):
if not (number % 4 == 0):
return False
list... | Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter... | ```python
def Count(string, number):
number //=4
lists = list(string)
a = number - lists.count('A')
c = number - lists.count('C')
g = number - lists.count('G')
t = number - lists.count('T')
return [a, c, g, t]
def Check(string, number):
if not (number % 4 == 0):
return False
... | 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,599,188,113 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 216 | 0 | st=input()
st=list(st)
upper=0
lower=0
for i in st:
if i.isupper():
upper+=1
else:
lower+=1
if upper > lower:
print(''.join(st).upper())
else:
print(''.join(st).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
st=input()
st=list(st)
upper=0
lower=0
for i in st:
if i.isupper():
upper+=1
else:
lower+=1
if upper > lower:
print(''.join(st).upper())
else:
print(''.join(st).lower())
``` | 3.946 |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,600,857,217 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | a=int(input())
[print((a//3)*2) if a%3==0 else print((a//3)*2+1)] | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
a=int(input())
[print((a//3)*2) if a%3==0 else print((a//3)*2+1)]
``` | 3 | |
120 | F | Spiders | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"trees"
] | null | null | One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower t... | The first input file line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of spiders. Next *n* lines contain the descriptions of each spider: integer *n**i* (2<=≤<=*n**i*<=≤<=100) — the number of beads, then *n**i*<=-<=1 pairs of numbers denoting the numbers of the beads connected by threads. The beads that m... | Print a single number — the length of the required construction. | [
"1\n3 1 2 2 3\n",
"2\n3 1 2 1 3\n4 1 2 2 3 2 4\n",
"2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5\n"
] | [
"2\n",
"4\n",
"7\n"
] | none | 0 | [
{
"input": "1\n3 1 2 2 3",
"output": "2"
},
{
"input": "2\n3 1 2 1 3\n4 1 2 2 3 2 4",
"output": "4"
},
{
"input": "2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5",
"output": "7"
},
{
"input": "3\n3 1 2 2 3\n5 2 5 5 3 3 4 5 1\n9 6 5 5 9 4 8 4 7 2 1 2 6 2 4 6 3",
"output":... | 1,640,047,930 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,252,800 | with open('input.txt', 'r') as file:
input_lines = [line.strip() for line in file]
n = int(input_lines[0])
def diam(tree):
k = len(tree)
visited = [False] * k
dist = [0] * k
que = [0]
while que:
q = que.pop(0)
visited[q] = True
for v in tree[q]:
... | Title: Spiders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue a... | ```python
with open('input.txt', 'r') as file:
input_lines = [line.strip() for line in file]
n = int(input_lines[0])
def diam(tree):
k = len(tree)
visited = [False] * k
dist = [0] * k
que = [0]
while que:
q = que.pop(0)
visited[q] = True
for v in tree[q... | -1 | |
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo... | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDL... | 1,593,436,202 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 78 | 6,963,200 | n=int(input())
arr=list(input())
m=0
u=1
d=-1
l=2
r=-2
count=0
temp=0
for i in arr:
#print(count)
if count==0:
#print("hii here i am zero")
m=max(m,temp)
if i=='U':
count+=1
temp+=1
elif i=='D':
count-=1
temp+=1
elif i=='L':
... | Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the ce... | ```python
n=int(input())
arr=list(input())
m=0
u=1
d=-1
l=2
r=-2
count=0
temp=0
for i in arr:
#print(count)
if count==0:
#print("hii here i am zero")
m=max(m,temp)
if i=='U':
count+=1
temp+=1
elif i=='D':
count-=1
temp+=1
elif i=='L'... | 0 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,587,073,487 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 204,800 | n=int(input())
t=[int(x) for x in input().split()]
count1=0
l=0
count2=0
s=0
for i in range (n):
if t[i]%2==0:
l=t[i]
count1 = count1 + 1
elif t[i]%2==1:
s=t[i]
count2 = count2 + 1
if count1 ==1:
print(t.index(l)+1)
if count2==1:
... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
n=int(input())
t=[int(x) for x in input().split()]
count1=0
l=0
count2=0
s=0
for i in range (n):
if t[i]%2==0:
l=t[i]
count1 = count1 + 1
elif t[i]%2==1:
s=t[i]
count2 = count2 + 1
if count1 ==1:
print(t.index(l)+1)
if c... | -1 |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,698,766,713 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | row, col = 0, 0
for i in range(5):
matrix_row = list(map(int, input().split()))
if 1 in matrix_row:
row, col = i, matrix_row.index(1)
moves = abs(row - 2) + abs(col - 2)
print(moves)
| Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
row, col = 0, 0
for i in range(5):
matrix_row = list(map(int, input().split()))
if 1 in matrix_row:
row, col = i, matrix_row.index(1)
moves = abs(row - 2) + abs(col - 2)
print(moves)
``` | 3 | |
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,589,371,255 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 20,172,800 | from math import gcd
n, m = map(int, input().split())
if n == 6 or m == 6:
print("0/1")
else:
print('{}/{}'.format(gcd(6-max(n,m), 6), 6 // (gcd(6-max(n,m), 6))))
| 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
from math import gcd
n, m = map(int, input().split())
if n == 6 or m == 6:
print("0/1")
else:
print('{}/{}'.format(gcd(6-max(n,m), 6), 6 // (gcd(6-max(n,m), 6))))
``` | 0 |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,586,942,678 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 280 | 0 | #codeforces problem set 18c
import sys
n = int(input())
nums = list(map(int, sys.stdin.readline().strip().split()))
sums = [nums[0]]
for i in range(1, n):
last = sums.pop()
sums.append(last)
sums.append(last+nums[i])
ways2cut = 0
if sums[n-1]%2 == 0:
findsum = sums[n-1]//2
n -= 1#as we do not wish to give the fu... | Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
#codeforces problem set 18c
import sys
n = int(input())
nums = list(map(int, sys.stdin.readline().strip().split()))
sums = [nums[0]]
for i in range(1, n):
last = sums.pop()
sums.append(last)
sums.append(last+nums[i])
ways2cut = 0
if sums[n-1]%2 == 0:
findsum = sums[n-1]//2
n -= 1#as we do not wish to g... | 0 |
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<... | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": ... | 1,647,693,000 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | from math import sqrt
r, d = map(int, input().split())
n = int(input())
s = 0
for i in range(n):
x, y, rs = map(int, input().split())
dcentro = sqrt(x*x + y*y)
dmenos = dcentro - rs
dmais = dcentro + rs
dmenos, dmais = min(dmenos, dmais), max(dmenos, dmais)
if dmenos >= d and dmais <= r:
... | Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center... | ```python
from math import sqrt
r, d = map(int, input().split())
n = int(input())
s = 0
for i in range(n):
x, y, rs = map(int, input().split())
dcentro = sqrt(x*x + y*y)
dmenos = dcentro - rs
dmais = dcentro + rs
dmenos, dmais = min(dmenos, dmais), max(dmenos, dmais)
if dmenos >= d and dmais... | 0 | |
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,684,241,236 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 62 | 0 | from math import *
a = input()
a = a.split(" ")
b = list(a)
for i in range(len(b)):
b[i] = int(b[i])
c = floor(b[0]/b[1])
d = c + 1
kmin = ((c*(c-1)) // 2)*(b[1]-(b[0]-c*b[1])) + ((d*(d-1)) // 2)*(b[0]-c*b[1])
print(kmin,end=" ")
e = b[0] - b[1] + 1
kmax = (e*(e-1)) // 2
print(kmax)
| 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
from math import *
a = input()
a = a.split(" ")
b = list(a)
for i in range(len(b)):
b[i] = int(b[i])
c = floor(b[0]/b[1])
d = c + 1
kmin = ((c*(c-1)) // 2)*(b[1]-(b[0]-c*b[1])) + ((d*(d-1)) // 2)*(b[0]-c*b[1])
print(kmin,end=" ")
e = b[0] - b[1] + 1
kmax = (e*(e-1)) // 2
print(kmax)
... | 3 | |
260 | B | Ancient Prophesy | PROGRAMMING | 1,600 | [
"brute force",
"implementation",
"strings"
] | null | null | A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha... | The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters. | In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique. | [
"777-444---21-12-2013-12-2013-12-2013---444-777\n"
] | [
"13-12-2013"
] | none | 1,000 | [
{
"input": "777-444---21-12-2013-12-2013-12-2013---444-777",
"output": "13-12-2013"
},
{
"input": "30-12-201429-15-208830-12-2014",
"output": "30-12-2014"
},
{
"input": "14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013",
"output": "... | 1,677,013,505 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 77 | 2,764,800 | import sys
input = sys.stdin.readline
from collections import Counter
d = Counter()
s = input()[:-1]
n = len(s)
q = {'01':31, '02':28, '03':31, '04':30, '05':31, '06':30, '07':31, '08':31, '09':30, '10':31, '11':30, '12':31}
for i in range(len(s)-7):
if s[i] == '-' and s[i+3:i+7] == '-201' and '-' not in ... | Title: Ancient Prophesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if th... | ```python
import sys
input = sys.stdin.readline
from collections import Counter
d = Counter()
s = input()[:-1]
n = len(s)
q = {'01':31, '02':28, '03':31, '04':30, '05':31, '06':30, '07':31, '08':31, '09':30, '10':31, '11':30, '12':31}
for i in range(len(s)-7):
if s[i] == '-' and s[i+3:i+7] == '-201' and '... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters. | Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n"
] | [
"a***b\n",
"***gmg***\n",
"*********\n"
] | The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | 0 | [
{
"input": "7\naogogob",
"output": "a***b"
},
{
"input": "13\nogogmgogogogo",
"output": "***gmg***"
},
{
"input": "9\nogoogoogo",
"output": "*********"
},
{
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz",
"output": "abcdef***ghijklmn***opqrstuvwxyz"
},
{
"input":... | 1,479,637,961 | 5,261 | Python 3 | OK | TESTS | 48 | 77 | 0 | n = int(input().strip());
s = input();
while s.find("ogo") != -1:
temp = s.find("ogo");
tempa = s[temp + 3:];
if s[temp + 3:temp +5] == "go":
s = s[0:temp];
s += "o";
s += tempa;
else:
s = s[0:temp];
s += "***";
s += tempa;
print(s);
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo i... | ```python
n = int(input().strip());
s = input();
while s.find("ogo") != -1:
temp = s.find("ogo");
tempa = s[temp + 3:];
if s[temp + 3:temp +5] == "go":
s = s[0:temp];
s += "o";
s += tempa;
else:
s = s[0:temp];
s += "***";
s += tempa;
print(s);... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109... | Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. | [
"3\n7 1 3\n1 2 1\n",
"4\n5 10 3 2\n2 3 2 4\n"
] | [
"2.000000000000\n",
"1.400000000000\n"
] | In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. | 0 | [
{
"input": "3\n7 1 3\n1 2 1",
"output": "2.000000000000"
},
{
"input": "4\n5 10 3 2\n2 3 2 4",
"output": "1.400000000000"
},
{
"input": "3\n1 1000000000 2\n1 2 1000000000",
"output": "333333332.999999999971"
},
{
"input": "2\n4 5\n10 8",
"output": "0.055555555556"
},
... | 1,597,615,326 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 249 | 11,776,000 | def check(z):
L= -float('inf')
R = float('inf')
for i in range(n):
L=max(L,x[i]-v[i]*z)
R=min(R,x[i]+v[i]*z)
if L<=R:
return True
else:
return False
n=int(input())
x=list(map(int,input().split()))
v=list(map(int,input().split()))
l=0
r=1e9
ans=-1.0
whi... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*... | ```python
def check(z):
L= -float('inf')
R = float('inf')
for i in range(n):
L=max(L,x[i]-v[i]*z)
R=min(R,x[i]+v[i]*z)
if L<=R:
return True
else:
return False
n=int(input())
x=list(map(int,input().split()))
v=list(map(int,input().split()))
l=0
r=1e9
ans... | 3 | |
328 | B | Sheldon and Ice Pieces | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number *t*. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to... | The first line contains integer *t* (1<=≤<=*t*<=≤<=10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9. | Print the required number of instances. | [
"42\n23454\n",
"169\n12118999\n"
] | [
"2\n",
"1\n"
] | This problem contains very weak pretests. | 500 | [
{
"input": "42\n23454",
"output": "2"
},
{
"input": "169\n12118999",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "7\n777",
"output": "3"
},
{
"input": "18\n8118",
"output": "2"
},
{
"input": "33\n33333333",
"output": "4"
},
... | 1,693,861,799 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 154 | 0 | # https://codeforces.com/problemset/problem/328/B
from collections import Counter
t = Counter(input().replace('6', '9').replace('2', '5'))
digits = Counter(input().replace('6', '9').replace('2', '5'))
print(min(digits[d] // cnt for d, cnt in t.items())) | Title: Sheldon and Ice Pieces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his fav... | ```python
# https://codeforces.com/problemset/problem/328/B
from collections import Counter
t = Counter(input().replace('6', '9').replace('2', '5'))
digits = Counter(input().replace('6', '9').replace('2', '5'))
print(min(digits[d] // cnt for d, cnt in t.items()))
``` | 3 | |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,695,362,568 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | n, t = input().split()
n, t = int(n), int(t)
k = input()
for j in range(t):
i = 0
while i < n - 1:
if k[i] + k[i + 1] == 'BG':
k = k[:i] + 'GB' + k[i + 2:]
i += 2
else:
i += 1
print(k)
| Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
n, t = input().split()
n, t = int(n), int(t)
k = input()
for j in range(t):
i = 0
while i < n - 1:
if k[i] + k[i + 1] == 'BG':
k = k[:i] + 'GB' + k[i + 2:]
i += 2
else:
i += 1
print(k)
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,691,904,405 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 83 | 124 | 0 | t = list(map(int, input().split()))
t.sort()
if t[0] + t[1] > t[2] or t[1] + t[2] > t[3]:
print("TRIANGLE")
elif t[0] + t[1] == t[2] or t[1] + t[2] == t[3]:
print("SEGMENT")
else:
print("IMPOSSIBLE") | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
t = list(map(int, input().split()))
t.sort()
if t[0] + t[1] > t[2] or t[1] + t[2] > t[3]:
print("TRIANGLE")
elif t[0] + t[1] == t[2] or t[1] + t[2] == t[3]:
print("SEGMENT")
else:
print("IMPOSSIBLE")
``` | 3.969 |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,599,721,298 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 186 | 307,200 |
n = int(input(''))
p = []
q = {}
for i in range(n):
name,score = input().split()
q[name] = q.get(name,0)+int(score)
p.append([name,q[name]])
max_value = max(q.values())
for i,j in p:
if q[i]==max_value and j>=max_value:
print(i)
break
| Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n = int(input(''))
p = []
q = {}
for i in range(n):
name,score = input().split()
q[name] = q.get(name,0)+int(score)
p.append([name,q[name]])
max_value = max(q.values())
for i,j in p:
if q[i]==max_value and j>=max_value:
print(i)
break
``` | 3.904711 |
128 | D | Numbers | PROGRAMMING | 2,000 | [
"constructive algorithms",
"implementation"
] | null | null | One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if she had arranged the numbers correctly, but at this point her youn... | The first line contains an integer *n* — how many numbers Anna had (3<=≤<=*n*<=≤<=105). The next line contains those numbers, separated by a space. All numbers are integers and belong to the range from 1 to 109. | Print the single line "YES" (without the quotes), if Anna could have completed the task correctly using all those numbers (using all of them is necessary). If Anna couldn't have fulfilled the task, no matter how hard she would try, print "NO" (without the quotes). | [
"4\n1 2 3 2\n",
"6\n1 1 2 2 2 3\n",
"6\n2 4 1 1 2 2\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 2,000 | [
{
"input": "4\n1 2 3 2",
"output": "YES"
},
{
"input": "6\n1 1 2 2 2 3",
"output": "YES"
},
{
"input": "6\n2 4 1 1 2 2",
"output": "NO"
},
{
"input": "4\n999999998 1000000000 999999999 999999999",
"output": "YES"
},
{
"input": "5\n6 7 6 7 6",
"output": "NO"
... | 1,689,604,597 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | print("_RANDOM_GUESS_1689604596.1554387")# 1689604596.1554592 | Title: Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. T... | ```python
print("_RANDOM_GUESS_1689604596.1554387")# 1689604596.1554592
``` | 0 | |
964 | B | Messages | PROGRAMMING | 1,300 | [
"math"
] | null | null | There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any mome... | The first line contains five integers *n*, *A*, *B*, *C* and *T* (1<=≤<=*n*,<=*A*,<=*B*,<=*C*,<=*T*<=≤<=1000).
The second string contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=*T*). | Output one integer — the answer to the problem. | [
"4 5 5 3 5\n1 5 5 4\n",
"5 3 1 1 3\n2 2 2 1 1\n",
"5 5 3 4 5\n1 2 3 4 5\n"
] | [
"20\n",
"15\n",
"35\n"
] | In the first sample the messages must be read immediately after receiving, Vasya receives *A* points for each message, *n*·*A* = 20 in total.
In the second sample the messages can be read at any integer moment.
In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messa... | 1,000 | [
{
"input": "4 5 5 3 5\n1 5 5 4",
"output": "20"
},
{
"input": "5 3 1 1 3\n2 2 2 1 1",
"output": "15"
},
{
"input": "5 5 3 4 5\n1 2 3 4 5",
"output": "35"
},
{
"input": "1 6 4 3 9\n2",
"output": "6"
},
{
"input": "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3",
"output": "90... | 1,587,816,133 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 2,150,400 | n,a,b,c,t=int(input().split())
ans=n*a
s=list(map(int,input().split()))
for i in s:
if b<c:
ans+=(c-b)*(t-i)
print(ans)
| Title: Messages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* e... | ```python
n,a,b,c,t=int(input().split())
ans=n*a
s=list(map(int,input().split()))
for i in s:
if b<c:
ans+=(c-b)*(t-i)
print(ans)
``` | -1 | |
624 | B | Making a String | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the ... | The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. | Print a single integer — the maximum length of the string that meets all the requirements. | [
"3\n2 5 5\n",
"3\n1 1 2\n"
] | [
"11\n",
"3\n"
] | For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | 1,000 | [
{
"input": "3\n2 5 5",
"output": "11"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "3\n1 1000000000 2",
"output": "1000000003"
},
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000... | 1,620,385,596 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 62 | 6,758,400 |
n = int(input())
l_n = list(map(int, input().split()))
d = {}
t = 0
for n in l_n:
while n in d and n > 0:
n -= 1
d[n] = ""
t += n
print(t) | Title: Making a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than ... | ```python
n = int(input())
l_n = list(map(int, input().split()))
d = {}
t = 0
for n in l_n:
while n in d and n > 0:
n -= 1
d[n] = ""
t += n
print(t)
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,695,558,794 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | x,y=map(int,input().split())
if x%2==0 or y%2==0:
m=(x*y)//2
else:
m=((x*y)-1)//2
print(m) | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
x,y=map(int,input().split())
if x%2==0 or y%2==0:
m=(x*y)//2
else:
m=((x*y)-1)//2
print(m)
``` | -1 |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,623,862,338 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 62 | 0 | ReadMultipleValues = lambda: map(int, input().split())
ReadMultipleValuesStr = lambda: map(str, input().split())
a,b,c,n=ReadMultipleValues()
if n-a-b+c <=0 or a<c or b<c:
print(-1)
else:
print(n-a-b+c) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
ReadMultipleValues = lambda: map(int, input().split())
ReadMultipleValuesStr = lambda: map(str, input().split())
a,b,c,n=ReadMultipleValues()
if n-a-b+c <=0 or a<c or b<c:
print(-1)
else:
print(n-a-b+c)
``` | 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,624,449,004 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | def lowerCount(word):
count = 0
for char in word:
if char.islower():
count += 1
return count
def upperCount(word):
count = 0
for char in word:
if char.isupper():
count += 1
return count
word = input()
if lowerCount(word) >= upperCount(... | 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 lowerCount(word):
count = 0
for char in word:
if char.islower():
count += 1
return count
def upperCount(word):
count = 0
for char in word:
if char.isupper():
count += 1
return count
word = input()
if lowerCount(word) >= u... | 3.969 |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,699,776,629 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | s = input()
res = '.'
for i in s.lower():
if i not in 'aeuioy':
res+=i
res+='.'
print(res[:-1]) | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
s = input()
res = '.'
for i in s.lower():
if i not in 'aeuioy':
res+=i
res+='.'
print(res[:-1])
``` | 3 | |
482 | A | Diverse Permutation | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your task is to find such permutation *p* of length *n*, that the group of number... | The single line of the input contains two space-separated positive integers *n*, *k* (1<=≤<=*k*<=<<=*n*<=≤<=105). | Print *n* integers forming the permutation. If there are multiple answers, print any of them. | [
"3 2\n",
"3 1\n",
"5 2\n"
] | [
"1 3 2\n",
"1 2 3\n",
"1 3 2 4 5\n"
] | By |*x*| we denote the absolute value of number *x*. | 500 | [
{
"input": "3 2",
"output": "1 3 2"
},
{
"input": "3 1",
"output": "1 2 3"
},
{
"input": "5 2",
"output": "1 3 2 4 5"
},
{
"input": "5 4",
"output": "1 5 2 4 3"
},
{
"input": "10 4",
"output": "1 10 2 9 8 7 6 5 4 3"
},
{
"input": "10 3",
"output": ... | 1,503,224,708 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | n,k = map(int,input().split())
ll = [str(i) for i in range(1,n+1)]
print(' '.join([ll[0]] + [ll[k]] + ll[1:k] + ll[k+1:]))
| Title: Diverse Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<... | ```python
n,k = map(int,input().split())
ll = [str(i) for i in range(1,n+1)]
print(' '.join([ll[0]] + [ll[k]] + ll[1:k] + ll[k+1:]))
``` | 0 | |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
... | 1,625,143,456 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 278 | 8,192,000 | n = int(input())
arr = sorted(map(int, input().split()))
mn = arr[0]
divs = sum(1 for i in arr if i%mn == 0)
if divs == n:
print(mn)
else:
print(-1) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that ... | ```python
n = int(input())
arr = sorted(map(int, input().split()))
mn = arr[0]
divs = sum(1 for i in arr if i%mn == 0)
if divs == n:
print(mn)
else:
print(-1)
``` | 3 | |
804 | B | Minimum number of steps | PROGRAMMING | 1,400 | [
"combinatorics",
"greedy",
"implementation",
"math"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | 1,000 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,513,772,826 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 5,734,400 | # -*- coding: utf-8 -*-
"""
Created on Wed Dec 20 20:22:23 2017
@author: admin
"""
s = input()
step = 0
while 'ab' in s:
s =s.replace('ab','bba',1)
step += 1
print(step) | Title: Minimum number of steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 20 20:22:23 2017
@author: admin
"""
s = input()
step = 0
while 'ab' in s:
s =s.replace('ab','bba',1)
step += 1
print(step)
``` | 0 |
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.